static char * get_spec_by_x(int n, const char *t, int *majorPtr, int *minorPtr) { struct uuidCache_s *uc; uuidcache_init(); uc = uuidCache; while (uc) { switch (n) { case UUID: if (strcmp(t, uc->uc_uuid) == 0) { *majorPtr = uc->major; *minorPtr = uc->minor; return uc->device; } break; case VOL: if (strcmp(t, uc->label) == 0) { *majorPtr = uc->major; *minorPtr = uc->minor; return uc->device; } break; } uc = uc->next; } return NULL; }
static char * get_spec_by_x(int n, const char *t) { struct uuidCache_s *uc; uuidcache_init(); uc = uuidCache; if (t == NULL) return NULL; while(uc) { switch (n) { case UUID: if (!memcmp(t, uc->uuid, sizeof(uc->uuid))) return string_copy(uc->device); break; case VOL: if (!strcmp(t, uc->label)) return string_copy(uc->device); break; } uc = uc->next; } return NULL; }
const char * get_volume_label_by_spec(const char *spec) { struct uuidCache_s *uc; uuidcache_init(); uc = uuidCache; while(uc) { if (!strcmp(spec, uc->device)) return uc->label; uc = uc->next; } return NULL; }
char *get_devname_from_uuid(const char *spec) { struct uuidCache_s *uc; uuidcache_init(); uc = uuidCache; while (uc) { /* case of hex numbers doesn't matter */ if (strcasecmp(spec, uc->uc_uuid) == 0) { return xstrdup(uc->device); } uc = uc->next; } return NULL; }
static int display_uuid_cache(void) { struct uuidCache_s *u; size_t i; uuidcache_init(); u = uuidCache; while (u) { printf("%s %s %s\n", u->device, u->label, u->uc_uuid); u = u->next; } return 0; }
char *get_devname_from_label(const char *spec) { struct uuidCache_s *uc; int spec_len = strlen(spec); uuidcache_init(); uc = uuidCache; while (uc) { // FIXME: empty label ("LABEL=") matches anything??! if (uc->label[0] && strncmp(spec, uc->label, spec_len) == 0) { return xstrdup(uc->device); } uc = uc->next; } return NULL; }
/* * second_occurrence_of_vol_label() * As labels are user defined they are not necessarily * system-wide unique. Make sure that they are. */ const char * second_occurrence_of_vol_label (const char *label) { struct uuidCache_s *last; int occurrences = 0; uuidcache_init(); for (last = uuidCache; last; last = last->next) { if (last->label && !strcmp(last->label, label)) { occurrences++; if (occurrences == 2) return last->device; } } return NULL; }
main(int argc, char **argv) { uuidcache_init(); }