Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/util-linux/volume_id/get_devname.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/util-linux/volume_id/get_devname.c
r2725 r3232 20 20 char *label; 21 21 char *uc_uuid; /* prefix makes it easier to grep for */ 22 IF_FEATURE_BLKID_TYPE(const char *type;) 22 23 } *uuidCache; 24 25 #if !ENABLE_FEATURE_BLKID_TYPE 26 #define get_label_uuid(fd, label, uuid, type) \ 27 get_label_uuid(fd, label, uuid) 28 #define uuidcache_addentry(device, label, uuid, type) \ 29 uuidcache_addentry(device, label, uuid) 30 #endif 23 31 24 32 /* Returns !0 on error. … … 27 35 * NB: closes fd. */ 28 36 static int 29 get_label_uuid(int fd, char **label, char **uuid )37 get_label_uuid(int fd, char **label, char **uuid, const char **type) 30 38 { 31 39 int rv = 1; … … 42 50 goto ret; 43 51 44 if (vid->label[0] != '\0' || vid->uuid[0] != '\0') { 52 if (vid->label[0] != '\0' || vid->uuid[0] != '\0' 53 #if ENABLE_FEATURE_BLKID_TYPE 54 || vid->type != NULL 55 #endif 56 ) { 45 57 *label = xstrndup(vid->label, sizeof(vid->label)); 46 58 *uuid = xstrndup(vid->uuid, sizeof(vid->uuid)); 59 #if ENABLE_FEATURE_BLKID_TYPE 60 *type = vid->type; 61 dbg("found label '%s', uuid '%s', type '%s'", *label, *uuid, *type); 62 #else 47 63 dbg("found label '%s', uuid '%s'", *label, *uuid); 64 #endif 48 65 rv = 0; 49 66 } … … 55 72 /* NB: we take ownership of (malloc'ed) label and uuid */ 56 73 static void 57 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid )74 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type) 58 75 { 59 76 struct uuidCache_s *last; … … 73 90 last->label = label; 74 91 last->uc_uuid = uuid; 92 IF_FEATURE_BLKID_TYPE(last->type = type;) 75 93 } 76 94 … … 84 102 int depth UNUSED_PARAM) 85 103 { 86 char *uuid = uuid; /* for compiler */87 char *label = label;88 int fd;89 90 104 /* note: this check rejects links to devices, among other nodes */ 91 105 if (!S_ISBLK(statbuf->st_mode)) … … 100 114 return TRUE; 101 115 102 fd = open(device, O_RDONLY); 103 if (fd < 0) 104 return TRUE; 105 106 /* get_label_uuid() closes fd in all cases (success & failure) */ 107 if (get_label_uuid(fd, &label, &uuid) == 0) { 108 /* uuidcache_addentry() takes ownership of all three params */ 109 uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid); 110 } 116 add_to_uuid_cache(device); 117 111 118 return TRUE; 112 119 } 113 120 114 static void 115 uuidcache_init(void) 116 { 121 static struct uuidCache_s* 122 uuidcache_init(int scan_devices) 123 { 124 dbg("DBG: uuidCache=%x, uuidCache"); 117 125 if (uuidCache) 118 return ;126 return uuidCache; 119 127 120 128 /* We were scanning /proc/partitions … … 128 136 * (Maybe add scanning of /sys/block/XXX/dev for devices 129 137 * somehow not having their /dev/XXX entries created?) */ 130 131 recursive_action("/dev", ACTION_RECURSE, 132 uuidcache_check_device, /* file_action */ 133 NULL, /* dir_action */ 134 NULL, /* userData */ 135 0 /* depth */); 138 if (scan_devices) 139 recursive_action("/dev", ACTION_RECURSE, 140 uuidcache_check_device, /* file_action */ 141 NULL, /* dir_action */ 142 NULL, /* userData */ 143 0 /* depth */); 144 145 return uuidCache; 136 146 } 137 147 … … 145 155 struct uuidCache_s *uc; 146 156 147 uuidcache_init(); 148 uc = uuidCache; 149 157 uc = uuidcache_init(/*scan_devices:*/ 1); 150 158 while (uc) { 151 159 switch (n) { … … 212 220 213 221 /* Used by blkid */ 214 void display_uuid_cache(void) 215 { 216 struct uuidCache_s *u; 217 218 uuidcache_init(); 219 u = uuidCache; 220 while (u) { 221 printf("%s:", u->device); 222 if (u->label[0]) 223 printf(" LABEL=\"%s\"", u->label); 224 if (u->uc_uuid[0]) 225 printf(" UUID=\"%s\"", u->uc_uuid); 222 void display_uuid_cache(int scan_devices) 223 { 224 struct uuidCache_s *uc; 225 226 uc = uuidcache_init(scan_devices); 227 while (uc) { 228 printf("%s:", uc->device); 229 if (uc->label[0]) 230 printf(" LABEL=\"%s\"", uc->label); 231 if (uc->uc_uuid[0]) 232 printf(" UUID=\"%s\"", uc->uc_uuid); 233 #if ENABLE_FEATURE_BLKID_TYPE 234 if (uc->type) 235 printf(" TYPE=\"%s\"", uc->type); 236 #endif 226 237 bb_putchar('\n'); 227 u = u->next; 228 } 229 } 238 uc = uc->next; 239 } 240 } 241 242 int add_to_uuid_cache(const char *device) 243 { 244 char *uuid = uuid; /* for compiler */ 245 char *label = label; 246 #if ENABLE_FEATURE_BLKID_TYPE 247 const char *type = type; 248 #endif 249 int fd; 250 251 fd = open(device, O_RDONLY); 252 if (fd < 0) 253 return 0; 254 255 /* get_label_uuid() closes fd in all cases (success & failure) */ 256 if (get_label_uuid(fd, &label, &uuid, &type) == 0) { 257 /* uuidcache_addentry() takes ownership of all four params */ 258 uuidcache_addentry(xstrdup(device), /*ma, mi,*/ label, uuid, type); 259 return 1; 260 } 261 return 0; 262 } 263 230 264 231 265 /* Used by mount and findfs */ … … 235 269 struct uuidCache_s *uc; 236 270 237 uuidcache_init(); 238 uc = uuidCache; 271 uc = uuidcache_init(/*scan_devices:*/ 1); 239 272 while (uc) { 240 273 if (uc->label[0] && strcmp(spec, uc->label) == 0) { … … 250 283 struct uuidCache_s *uc; 251 284 252 uuidcache_init(); 253 uc = uuidCache; 285 uc = uuidcache_init(/*scan_devices:*/ 1); 254 286 while (uc) { 255 287 /* case of hex numbers doesn't matter */
Note:
See TracChangeset
for help on using the changeset viewer.