diff options
Diffstat (limited to 'util-linux/volume_id/get_devname.c')
-rw-r--r-- | util-linux/volume_id/get_devname.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 7c9930543..230102d89 100644 --- a/util-linux/volume_id/get_devname.c +++ b/util-linux/volume_id/get_devname.c | |||
@@ -114,12 +114,12 @@ uuidcache_check_device(const char *device, | |||
114 | return TRUE; | 114 | return TRUE; |
115 | } | 115 | } |
116 | 116 | ||
117 | static void | 117 | static struct uuidCache_s* |
118 | uuidcache_init(void) | 118 | uuidcache_init(int scan_devices) |
119 | { | 119 | { |
120 | dbg("DBG: uuidCache=%x, uuidCache"); | 120 | dbg("DBG: uuidCache=%x, uuidCache"); |
121 | if (uuidCache) | 121 | if (uuidCache) |
122 | return; | 122 | return uuidCache; |
123 | 123 | ||
124 | /* We were scanning /proc/partitions | 124 | /* We were scanning /proc/partitions |
125 | * and /proc/sys/dev/cdrom/info here. | 125 | * and /proc/sys/dev/cdrom/info here. |
@@ -131,12 +131,14 @@ uuidcache_init(void) | |||
131 | * This is unacceptably complex. Let's just scan /dev. | 131 | * This is unacceptably complex. Let's just scan /dev. |
132 | * (Maybe add scanning of /sys/block/XXX/dev for devices | 132 | * (Maybe add scanning of /sys/block/XXX/dev for devices |
133 | * somehow not having their /dev/XXX entries created?) */ | 133 | * somehow not having their /dev/XXX entries created?) */ |
134 | 134 | if (scan_devices) | |
135 | recursive_action("/dev", ACTION_RECURSE, | 135 | recursive_action("/dev", ACTION_RECURSE, |
136 | uuidcache_check_device, /* file_action */ | 136 | uuidcache_check_device, /* file_action */ |
137 | NULL, /* dir_action */ | 137 | NULL, /* dir_action */ |
138 | NULL, /* userData */ | 138 | NULL, /* userData */ |
139 | 0 /* depth */); | 139 | 0 /* depth */); |
140 | |||
141 | return uuidCache; | ||
140 | } | 142 | } |
141 | 143 | ||
142 | #define UUID 1 | 144 | #define UUID 1 |
@@ -148,9 +150,7 @@ get_spec_by_x(int n, const char *t, int *majorPtr, int *minorPtr) | |||
148 | { | 150 | { |
149 | struct uuidCache_s *uc; | 151 | struct uuidCache_s *uc; |
150 | 152 | ||
151 | uuidcache_init(); | 153 | uc = uuidcache_init(/*scan_devices:*/ 1); |
152 | uc = uuidCache; | ||
153 | |||
154 | while (uc) { | 154 | while (uc) { |
155 | switch (n) { | 155 | switch (n) { |
156 | case UUID: | 156 | case UUID: |
@@ -215,24 +215,23 @@ get_spec_by_volume_label(const char *s, int *major, int *minor) | |||
215 | #endif // UNUSED | 215 | #endif // UNUSED |
216 | 216 | ||
217 | /* Used by blkid */ | 217 | /* Used by blkid */ |
218 | void display_uuid_cache(void) | 218 | void display_uuid_cache(int scan_devices) |
219 | { | 219 | { |
220 | struct uuidCache_s *u; | 220 | struct uuidCache_s *uc; |
221 | 221 | ||
222 | uuidcache_init(); | 222 | uc = uuidcache_init(scan_devices); |
223 | u = uuidCache; | 223 | while (uc) { |
224 | while (u) { | 224 | printf("%s:", uc->device); |
225 | printf("%s:", u->device); | 225 | if (uc->label[0]) |
226 | if (u->label[0]) | 226 | printf(" LABEL=\"%s\"", uc->label); |
227 | printf(" LABEL=\"%s\"", u->label); | 227 | if (uc->uc_uuid[0]) |
228 | if (u->uc_uuid[0]) | 228 | printf(" UUID=\"%s\"", uc->uc_uuid); |
229 | printf(" UUID=\"%s\"", u->uc_uuid); | ||
230 | #if ENABLE_FEATURE_BLKID_TYPE | 229 | #if ENABLE_FEATURE_BLKID_TYPE |
231 | if (u->type) | 230 | if (uc->type) |
232 | printf(" TYPE=\"%s\"", u->type); | 231 | printf(" TYPE=\"%s\"", uc->type); |
233 | #endif | 232 | #endif |
234 | bb_putchar('\n'); | 233 | bb_putchar('\n'); |
235 | u = u->next; | 234 | uc = uc->next; |
236 | } | 235 | } |
237 | } | 236 | } |
238 | 237 | ||
@@ -265,8 +264,7 @@ char *get_devname_from_label(const char *spec) | |||
265 | { | 264 | { |
266 | struct uuidCache_s *uc; | 265 | struct uuidCache_s *uc; |
267 | 266 | ||
268 | uuidcache_init(); | 267 | uc = uuidcache_init(/*scan_devices:*/ 1); |
269 | uc = uuidCache; | ||
270 | while (uc) { | 268 | while (uc) { |
271 | if (uc->label[0] && strcmp(spec, uc->label) == 0) { | 269 | if (uc->label[0] && strcmp(spec, uc->label) == 0) { |
272 | return xstrdup(uc->device); | 270 | return xstrdup(uc->device); |
@@ -280,8 +278,7 @@ char *get_devname_from_uuid(const char *spec) | |||
280 | { | 278 | { |
281 | struct uuidCache_s *uc; | 279 | struct uuidCache_s *uc; |
282 | 280 | ||
283 | uuidcache_init(); | 281 | uc = uuidcache_init(/*scan_devices:*/ 1); |
284 | uc = uuidCache; | ||
285 | while (uc) { | 282 | while (uc) { |
286 | /* case of hex numbers doesn't matter */ | 283 | /* case of hex numbers doesn't matter */ |
287 | if (strcasecmp(spec, uc->uc_uuid) == 0) { | 284 | if (strcasecmp(spec, uc->uc_uuid) == 0) { |