Add support for searching /proc/evms/volumes when interpreting

LABEL=xxx or UUID=xxx.  

Add new utility program /sbin/findfs, which interprets LABEL=xxx or
UUID=xxx, and returns the device name.  (Part of tune2fs).
bitmap-optimize
Theodore Ts'o 2002-08-17 23:01:22 -04:00
parent e5b164373c
commit 118d7dacc5
4 changed files with 112 additions and 11 deletions

View File

@ -1,5 +1,17 @@
2002-08-17 Theodore Ts'o <tytso@mit.edu>
* findfs.8.in: New man page.
* tune2fs.c (do_findfs): If tune2fs is executed with argv[0] set
to findfs, then it will interpret argv[1] as one of
LABEL=xxx or UUID=xxx and translate it to a device name.
* get_device_by_label.c (uuidcache_init): Moved code which
interpreted /proc/partitions into read_partitions(), and
then added support for interpreting /proc/evms/volumes in
read_evms(). uuidcache_init() calls both read_evms() and
read_partitions().
* mke2fs.8.in: Add a common usage of the -n option. (Addresses
Debian Bug #146437)

View File

@ -17,7 +17,7 @@ INSTALL = @INSTALL@
SPROGS= mke2fs badblocks tune2fs dumpe2fs $(E2IMAGE_PROG) @FSCK_PROG@
USPROGS= mklost+found
SMANPAGES= tune2fs.8 mklost+found.8 mke2fs.8 dumpe2fs.8 badblocks.8 \
e2label.8 $(E2IMAGE_MAN) @FSCK_MAN@
e2label.8 findfs.8 $(E2IMAGE_MAN) @FSCK_MAN@
UPROGS= chattr lsattr uuidgen
UMANPAGES= chattr.1 lsattr.1 uuidgen.1
@ -116,6 +116,9 @@ mke2fs.8: $(DEP_SUBSTITUTE) $(srcdir)/mke2fs.8.in
e2label.8: $(DEP_SUBSTITUTE) $(srcdir)/e2label.8.in
$(SUBSTITUTE) $(srcdir)/e2label.8.in e2label.8
findfs.8: $(DEP_SUBSTITUTE) $(srcdir)/findfs.8.in
$(SUBSTITUTE) $(srcdir)/findfs.8.in findfs.8
e2image.8: $(DEP_SUBSTITUTE) $(srcdir)/e2image.8.in
$(SUBSTITUTE) $(srcdir)/e2image.8.in e2image.8
@ -157,6 +160,8 @@ install: all $(SMANPAGES) $(UMANPAGES) installdirs
$(DESTDIR)$(root_sbindir)/mkfs.ext3
$(LN) -f $(DESTDIR)$(root_sbindir)/tune2fs \
$(DESTDIR)$(root_sbindir)/e2label
$(LN) -f $(DESTDIR)$(root_sbindir)/tune2fs \
$(DESTDIR)$(root_sbindir)/findfs
for i in $(UPROGS); do \
$(INSTALL_PROGRAM) $$i $(DESTDIR)$(bindir)/$$i; \
$(STRIP) $(DESTDIR)$(bindir)/$$i; \

View File

@ -37,6 +37,7 @@
extern char *ext2fs_find_block_device(dev_t device);
#define PROC_PARTITIONS "/proc/partitions"
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
#define DEVLABELDIR "/dev"
#define VG_DIR "/proc/lvm/VGs"
@ -197,7 +198,8 @@ static void init_lvm(void)
#endif
static void
uuidcache_init(void) {
read_partitions(void)
{
char line[100];
char *s;
int ma, mi, sz;
@ -210,13 +212,6 @@ uuidcache_init(void) {
int firstPass;
int handleOnFirst;
if (uuidCache)
return;
#ifdef VG_DIR
init_lvm();
#endif
procpt = fopen(PROC_PARTITIONS, "r");
if (!procpt)
return;
@ -259,6 +254,10 @@ uuidcache_init(void) {
devname = string_copy(device);
if (!devname)
continue;
#ifdef DEBUG
printf("Checking partition %s (%d, %d)\n",
devname, ma, mi);
#endif
if (!get_label_uuid(devname, &label, uuid))
uuidcache_addentry(devname, label, uuid);
else
@ -270,6 +269,64 @@ uuidcache_init(void) {
fclose(procpt);
}
static void
read_evms(void)
{
char line[100];
char *s;
int ma, mi, sz;
FILE *procpt;
char uuid[16], *label, *devname;
char device[110];
dev_t dev;
struct stat statbuf;
procpt = fopen(PROC_EVMS_VOLUMES, "r");
if (!procpt)
return;
while (fgets(line, sizeof(line), procpt)) {
if (sscanf (line, " %d %d %d %*s %*s %[^\n ]",
&ma, &mi, &sz, device) != 4)
continue;
/*
* We first look for the device in the named location,
* 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.
*/
dev = makedev(ma, mi);
if ((stat(device, &statbuf) < 0) || (statbuf.st_rdev != dev)) {
devname = ext2fs_find_block_device(dev);
} else
devname = string_copy(device);
if (!devname)
continue;
#ifdef DEBUG
printf("Checking partition %s (%d, %d)\n",
devname, ma, mi);
#endif
if (!get_label_uuid(devname, &label, uuid))
uuidcache_addentry(devname, label, uuid);
else
free(devname);
}
fclose(procpt);
}
static void
uuidcache_init(void)
{
if (uuidCache)
return;
#ifdef VG_DIR
init_lvm();
#endif
read_evms();
read_partitions();
}
#define UUID 1
#define VOL 2
@ -328,7 +385,7 @@ get_spec_by_uuid(const char *s)
return get_spec_by_x(UUID, uuid);
bad_uuid:
fprintf(stderr, _("WARNING: %s: bad UUID"), s);
fprintf(stderr, _("WARNING: %s: bad UUID\n"), s);
return NULL;
}
@ -371,3 +428,10 @@ char *interpret_spec(char *spec)
dev = string_copy(spec);
return dev;
}
#ifdef DEBUG
main(int argc, char **argv)
{
uuidcache_init();
}
#endif

View File

@ -627,8 +627,26 @@ static void parse_tune2fs_options(int argc, char **argv)
if (!open_flag && !l_flag)
usage();
device_name = argv[optind];
}
}
do_findfs(int argc, char **argv)
{
char *dev;
if ((argc != 2) ||
(strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
exit(2);
}
dev = interpret_spec(argv[1]);
if (!dev) {
fprintf(stderr, "Filesystem matching %s not found\n",
argv[1]);
exit(1);
}
puts(dev);
exit(0);
}
int main (int argc, char ** argv)
@ -647,6 +665,8 @@ int main (int argc, char ** argv)
program_name = *argv;
initialize_ext2_error_table();
if (strcmp(get_progname(argv[0]), "findfs") == 0)
do_findfs(argc, argv);
if (strcmp(get_progname(argv[0]), "e2label") == 0)
parse_e2label_options(argc, argv);
else