|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= < [email protected]> |
| 3 | +Date: Wed, 6 Mar 2024 10:39:06 +0100 |
| 4 | +Subject: [PATCH] udev: correctly handle partition #16 and later |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +If a zvol has more than 15 partitions, the minor device number exhausts |
| 10 | +the slot count reserved for partitions next to the zvol itself. As a |
| 11 | +result, the minor number cannot be used to determine the partition |
| 12 | +number for the higher partition, and doing so results in wrong named |
| 13 | +symlinks being generated by udev. |
| 14 | + |
| 15 | +Since the partition number is encoded in the block device name anyway, |
| 16 | +let's just extract it from there instead. |
| 17 | + |
| 18 | +Fixes: #15904 |
| 19 | + |
| 20 | +Signed-off-by: Fabian Grünbichler < [email protected]> |
| 21 | +Signed-off-by: Stoiko Ivanov < [email protected]> |
| 22 | +--- |
| 23 | + udev/zvol_id.c | 9 +++++---- |
| 24 | + 1 file changed, 5 insertions(+), 4 deletions(-) |
| 25 | + |
| 26 | +diff --git a/udev/zvol_id.c b/udev/zvol_id.c |
| 27 | +index 5960b9787..609349594 100644 |
| 28 | +--- a/udev/zvol_id.c |
| 29 | ++++ b/udev/zvol_id.c |
| 30 | +@@ -51,7 +51,7 @@ const char *__asan_default_options(void) { |
| 31 | + int |
| 32 | + main(int argc, const char *const *argv) |
| 33 | + { |
| 34 | +- if (argc != 2) { |
| 35 | ++ if (argc != 2 || strncmp(argv[1], "/dev/zd", 7) != 0) { |
| 36 | + fprintf(stderr, "usage: %s /dev/zdX\n", argv[0]); |
| 37 | + return (1); |
| 38 | + } |
| 39 | +@@ -72,9 +72,10 @@ main(int argc, const char *const *argv) |
| 40 | + return (1); |
| 41 | + } |
| 42 | + |
| 43 | +- unsigned int dev_part = minor(sb.st_rdev) % ZVOL_MINORS; |
| 44 | +- if (dev_part != 0) |
| 45 | +- sprintf(zvol_name + strlen(zvol_name), "-part%u", dev_part); |
| 46 | ++ const char *dev_part = strrchr(dev_name, 'p'); |
| 47 | ++ if (dev_part != NULL) { |
| 48 | ++ sprintf(zvol_name + strlen(zvol_name), "-part%s", dev_part + 1); |
| 49 | ++ } |
| 50 | + |
| 51 | + for (size_t i = 0; i < strlen(zvol_name); ++i) |
| 52 | + if (isblank(zvol_name[i])) |
0 commit comments