From 556ccbd6f9722ccf4a278a7bbdaf82f3c6153ede Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 20 Aug 2000 19:11:05 +0000 Subject: [PATCH] ChangeLog, Makefile.in, get_device_by_label.c: get_device_by_label.c: Add call to ext2fs_find_block_device if we can't find the device using the name given by /proc/partitions. (This can happen if devfs is compiled into the kernel, but not mounted.) --- misc/ChangeLog | 7 +++++++ misc/Makefile.in | 2 +- misc/get_device_by_label.c | 48 +++++++++++++++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index fd55752..9b3f68c 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,10 @@ +2000-08-20 + + * get_device_by_label.c: Add call to ext2fs_find_block_device if + we can't find the device using the name given by + /proc/partitions. (This can happen if devfs is compiled + into the kernel, but not mounted.) + 2000-06-27 Andreas Dilger * dumpe2fs.c (usage): add fhx options to usage message, add -x option diff --git a/misc/Makefile.in b/misc/Makefile.in index 7e9e1d5..f196f46 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -83,7 +83,7 @@ dumpe2fs: $(DUMPE2FS_OBJS) $(DEPLIBS_E2P) $(CC) $(ALL_LDFLAGS) -o dumpe2fs $(DUMPE2FS_OBJS) $(LIBS_E2P) fsck: $(FSCK_OBJS) - $(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) + $(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBS) badblocks: $(BADBLOCKS_OBJS) $(DEPLIBS) $(CC) $(ALL_LDFLAGS) -o badblocks $(BADBLOCKS_OBJS) $(LIBS) diff --git a/misc/get_device_by_label.c b/misc/get_device_by_label.c index 7a1a4bd..72378e7 100644 --- a/misc/get_device_by_label.c +++ b/misc/get_device_by_label.c @@ -1,23 +1,36 @@ /* * get_device_by_label.h * - * Copyright 1999 by Andries Brouwer and Theodore Ts'o + * Copyright 1999 by Andries Brouwer + * Copyright 1999, 2000 by Theodore Ts'o * * This file may be redistributed under the terms of the GNU Public * License. * * Taken from aeb's mount, 990619 * Updated from aeb's mount, 20000725 + * Added call to ext2fs_find_block_device, so that we can find devices + * even if devfs (ugh) is compiled in, but not mounted, since + * this messes up /proc/partitions, by TYT. */ #include #include +#include #include #include #include +#include +#include +#ifdef HAVE_SYS_MKDEV_H +#include +#endif #include "nls-enable.h" #include "get_device_by_label.h" +/* function prototype from libext2 */ +extern char *ext2fs_find_block_device(dev_t device); + #define PROC_PARTITIONS "/proc/partitions" #define DEVLABELDIR "/dev" @@ -91,8 +104,10 @@ uuidcache_init(void) { int ma, mi, sz; static char ptname[100]; FILE *procpt; - char uuid[16], *label; + char uuid[16], *label, *devname; char device[110]; + dev_t dev; + struct stat statbuf; int firstPass; int handleOnFirst; @@ -126,18 +141,25 @@ uuidcache_init(void) { for(s = ptname; *s; s++); if (isdigit(s[-1])) { - /* - * Note: this is a heuristic only - there is no reason - * why these devices should live in /dev. - * Perhaps this directory should be specifiable by option. - * One might for example have /devlabel with links to /dev - * for the devices that may be accessed in this way. - * (This is useful, if the cdrom on /dev/hdc must not - * be accessed.) - */ + /* + * We first look in /dev for the device, but + * if we don't find it, or if the stat + * information doesn't check out, we use + * ext2fs_find_block_device to find it. + */ sprintf(device, "%s/%s", DEVLABELDIR, ptname); - if (!get_label_uuid(device, &label, uuid)) - uuidcache_addentry(strdup(device), label, uuid); + dev = makedev(ma, mi); + if ((stat(device, &statbuf) < 0) || + (statbuf.st_rdev != dev)) { + devname = ext2fs_find_block_device(dev); + } else + devname = strdup(device); + if (!devname) + continue; + if (!get_label_uuid(devname, &label, uuid)) + uuidcache_addentry(devname, label, uuid); + else + free(devname); } } } -- 1.8.3.1