diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-12-06 15:06:59 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-12-06 15:06:59 +0100 |
commit | c3375f0389469f596b93cdb34a6005382bc19a36 (patch) | |
tree | 0d8f0eacc77ea786b38ed282ba72b63d1b2a2995 | |
parent | b8ff9357d579913a5c699d89b4126d859590eea3 (diff) | |
download | busybox-w32-c3375f0389469f596b93cdb34a6005382bc19a36.tar.gz busybox-w32-c3375f0389469f596b93cdb34a6005382bc19a36.tar.bz2 busybox-w32-c3375f0389469f596b93cdb34a6005382bc19a36.zip |
volume_id/get_devname: trivial code shrink
function old new delta
uuidcache_init 36 41 +5
get_devname_from_uuid 55 51 -4
get_devname_from_label 61 57 -4
display_uuid_cache 109 105 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-12) Total: -7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/volume_id/get_devname.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 7c9930543..d81e24438 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(void) |
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. |
@@ -137,6 +137,8 @@ uuidcache_init(void) | |||
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(); |
152 | uc = uuidCache; | ||
153 | |||
154 | while (uc) { | 154 | while (uc) { |
155 | switch (n) { | 155 | switch (n) { |
156 | case UUID: | 156 | case UUID: |
@@ -217,22 +217,21 @@ get_spec_by_volume_label(const char *s, int *major, int *minor) | |||
217 | /* Used by blkid */ | 217 | /* Used by blkid */ |
218 | void display_uuid_cache(void) | 218 | void display_uuid_cache(void) |
219 | { | 219 | { |
220 | struct uuidCache_s *u; | 220 | struct uuidCache_s *uc; |
221 | 221 | ||
222 | uuidcache_init(); | 222 | uc = uuidcache_init(); |
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(); |
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(); |
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) { |