Skip to content

Commit f1b3683

Browse files
udev: correctly handle partition #16 and later
If a zvol has more than 15 partitions, the minor device number exhausts the slot count reserved for partitions next to the zvol itself. As a result, the minor number cannot be used to determine the partition number for the higher partition, and doing so results in wrong named symlinks being generated by udev. Since the partition number is encoded in the block device name anyway, let's just extract it from there instead. Reviewed-by: Tony Hutter <[email protected]> Reviewed by: Brian Behlendorf <[email protected]> Reviewed-by: Tino Reichardt <[email protected]> Signed-off-by: Fabian Grünbichler <[email protected]> Closes #15904 Closes #15970
1 parent 2c01cae commit f1b3683

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

udev/zvol_id.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const char *__asan_default_options(void) {
5151
int
5252
main(int argc, const char *const *argv)
5353
{
54-
if (argc != 2) {
54+
if (argc != 2 || strncmp(argv[1], "/dev/zd", 7) != 0) {
5555
fprintf(stderr, "usage: %s /dev/zdX\n", argv[0]);
5656
return (1);
5757
}
@@ -72,9 +72,10 @@ main(int argc, const char *const *argv)
7272
return (1);
7373
}
7474

75-
unsigned int dev_part = minor(sb.st_rdev) % ZVOL_MINORS;
76-
if (dev_part != 0)
77-
sprintf(zvol_name + strlen(zvol_name), "-part%u", dev_part);
75+
const char *dev_part = strrchr(dev_name, 'p');
76+
if (dev_part != NULL) {
77+
sprintf(zvol_name + strlen(zvol_name), "-part%s", dev_part + 1);
78+
}
7879

7980
for (size_t i = 0; i < strlen(zvol_name); ++i)
8081
if (isblank(zvol_name[i]))

0 commit comments

Comments
 (0)