Hi Denys I see the disk check has never been in busybox. With the digit check devices like mmcblk0 were skipped, but now with 0 allowed we're seeing a ton of loop devices listed (loop0, loop10, loop20...) as well as ramzswap0, all which should not be shown in fdisk -l.
Attaching a patch to use a proper disk check (from upstream fdisk). function old new delta fdisk_main 453 519 +66 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 66/0) Total: 66 bytes text data bss dec hex filename 22052 802 96 22950 59a6 busybox_old 22118 802 96 23016 59e8 busybox_unstripped - Lauri -- http://www.fastmail.fm - Same, same, but different...
From 5ce162114ebd53f377c273d105a4c05d009a7788 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <[email protected]> Date: Fri, 29 Apr 2011 17:42:37 +0300 Subject: [PATCH] fdisk: Backport disk check from util-linux Current busybox code listed devices like loop0, loop10 and so on. Signed-off-by: Lauri Kasanen <[email protected]> --- util-linux/fdisk.c | 37 ++++++++++++++++++++++++++++++------- 1 files changed, 30 insertions(+), 7 deletions(-) diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index da03e68..f829c36 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -2846,13 +2846,39 @@ open_list_and_close(const char *device, int user_specified) close_dev_fd(); } +/* Is it a whole disk? The digit check is still useful + for Xen devices for example. */ +static int is_whole_disk(const char *disk) +{ + int fd = open(disk, O_RDONLY); + const char *s; + + if (fd != -1) { + struct hd_geometry geometry; + int i = ioctl(fd, HDIO_GETGEO, &geometry); +#if ENABLE_FEATURE_CLEAN_UP + close(fd); +#endif + if (i == 0) + return (geometry.start == 0); + } + + for (s = disk; *s; s++) + continue; + /* note: mmcblk0 should work from the geometry check above */ + if (isdigit(s[-1])) + return 0; + + return 1; +} + /* for fdisk -l: try all things in /proc/partitions that look like a partition name (do not end in a digit) */ static void list_devs_in_proc_partititons(void) { FILE *procpt; - char line[100], ptname[100], devname[120], *s; + char line[100], ptname[100], devname[120]; int ma, mi, sz; procpt = fopen_or_warn("/proc/partitions", "r"); @@ -2861,13 +2887,10 @@ list_devs_in_proc_partititons(void) if (sscanf(line, " %u %u %u %[^\n ]", &ma, &mi, &sz, ptname) != 4) continue; - for (s = ptname; *s; s++) - continue; - /* note: excluding '0': e.g. mmcblk0 is not a partition name! */ - if (s[-1] >= '1' && s[-1] <= '9') - continue; + sprintf(devname, "/dev/%s", ptname); - open_list_and_close(devname, 0); + if (is_whole_disk(devname)) + open_list_and_close(devname, 0); } #if ENABLE_FEATURE_CLEAN_UP fclose(procpt); -- 1.7.2.1
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
