blkid: if parameters are given, do not scan /dev

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2012-03-03 15:09:07 +01:00
parent 97e5281641
commit e8cfc3f693
3 changed files with 17 additions and 14 deletions

View File

@ -20,7 +20,7 @@
char *get_devname_from_label(const char *spec); char *get_devname_from_label(const char *spec);
char *get_devname_from_uuid(const char *spec); char *get_devname_from_uuid(const char *spec);
void display_uuid_cache(void); void display_uuid_cache(int scan_devices);
/* Returns: /* Returns:
* 0: no UUID= or LABEL= prefix found * 0: no UUID= or LABEL= prefix found

View File

@ -18,11 +18,14 @@
int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int blkid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int blkid_main(int argc UNUSED_PARAM, char **argv) int blkid_main(int argc UNUSED_PARAM, char **argv)
{ {
int scan_devices = 1;
while (*++argv) { while (*++argv) {
/* Note: bogus device names don't cause any error messages */ /* Note: bogus device names don't cause any error messages */
add_to_uuid_cache(*argv); add_to_uuid_cache(*argv);
scan_devices = 0;
} }
display_uuid_cache(); display_uuid_cache(scan_devices);
return 0; return 0;
} }

View File

@ -115,7 +115,7 @@ uuidcache_check_device(const char *device,
} }
static struct uuidCache_s* static struct uuidCache_s*
uuidcache_init(void) uuidcache_init(int scan_devices)
{ {
dbg("DBG: uuidCache=%x, uuidCache"); dbg("DBG: uuidCache=%x, uuidCache");
if (uuidCache) if (uuidCache)
@ -131,12 +131,12 @@ uuidcache_init(void)
* This is unacceptably complex. Let's just scan /dev. * This is unacceptably complex. Let's just scan /dev.
* (Maybe add scanning of /sys/block/XXX/dev for devices * (Maybe add scanning of /sys/block/XXX/dev for devices
* somehow not having their /dev/XXX entries created?) */ * somehow not having their /dev/XXX entries created?) */
if (scan_devices)
recursive_action("/dev", ACTION_RECURSE, recursive_action("/dev", ACTION_RECURSE,
uuidcache_check_device, /* file_action */ uuidcache_check_device, /* file_action */
NULL, /* dir_action */ NULL, /* dir_action */
NULL, /* userData */ NULL, /* userData */
0 /* depth */); 0 /* depth */);
return uuidCache; return uuidCache;
} }
@ -150,7 +150,7 @@ get_spec_by_x(int n, const char *t, int *majorPtr, int *minorPtr)
{ {
struct uuidCache_s *uc; struct uuidCache_s *uc;
uc = uuidcache_init(); uc = uuidcache_init(/*scan_devices:*/ 1);
while (uc) { while (uc) {
switch (n) { switch (n) {
case UUID: case UUID:
@ -215,11 +215,11 @@ get_spec_by_volume_label(const char *s, int *major, int *minor)
#endif // UNUSED #endif // UNUSED
/* Used by blkid */ /* Used by blkid */
void display_uuid_cache(void) void display_uuid_cache(int scan_devices)
{ {
struct uuidCache_s *uc; struct uuidCache_s *uc;
uc = uuidcache_init(); uc = uuidcache_init(scan_devices);
while (uc) { while (uc) {
printf("%s:", uc->device); printf("%s:", uc->device);
if (uc->label[0]) if (uc->label[0])
@ -264,7 +264,7 @@ char *get_devname_from_label(const char *spec)
{ {
struct uuidCache_s *uc; struct uuidCache_s *uc;
uc = uuidcache_init(); uc = uuidcache_init(/*scan_devices:*/ 1);
while (uc) { while (uc) {
if (uc->label[0] && strcmp(spec, uc->label) == 0) { if (uc->label[0] && strcmp(spec, uc->label) == 0) {
return xstrdup(uc->device); return xstrdup(uc->device);
@ -278,7 +278,7 @@ char *get_devname_from_uuid(const char *spec)
{ {
struct uuidCache_s *uc; struct uuidCache_s *uc;
uc = uuidcache_init(); uc = uuidcache_init(/*scan_devices:*/ 1);
while (uc) { while (uc) {
/* case of hex numbers doesn't matter */ /* case of hex numbers doesn't matter */
if (strcasecmp(spec, uc->uc_uuid) == 0) { if (strcasecmp(spec, uc->uc_uuid) == 0) {