Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (7 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/util-linux/volume_id/get_devname.c

    r2725 r3232  
    2020    char *label;
    2121    char *uc_uuid; /* prefix makes it easier to grep for */
     22    IF_FEATURE_BLKID_TYPE(const char *type;)
    2223} *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
    2331
    2432/* Returns !0 on error.
     
    2735 * NB: closes fd. */
    2836static int
    29 get_label_uuid(int fd, char **label, char **uuid)
     37get_label_uuid(int fd, char **label, char **uuid, const char **type)
    3038{
    3139    int rv = 1;
     
    4250        goto ret;
    4351
    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    ) {
    4557        *label = xstrndup(vid->label, sizeof(vid->label));
    4658        *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
    4763        dbg("found label '%s', uuid '%s'", *label, *uuid);
     64#endif
    4865        rv = 0;
    4966    }
     
    5572/* NB: we take ownership of (malloc'ed) label and uuid */
    5673static void
    57 uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid)
     74uuidcache_addentry(char *device, /*int major, int minor,*/ char *label, char *uuid, const char *type)
    5875{
    5976    struct uuidCache_s *last;
     
    7390    last->label = label;
    7491    last->uc_uuid = uuid;
     92    IF_FEATURE_BLKID_TYPE(last->type = type;)
    7593}
    7694
     
    84102        int depth UNUSED_PARAM)
    85103{
    86     char *uuid = uuid; /* for compiler */
    87     char *label = label;
    88     int fd;
    89 
    90104    /* note: this check rejects links to devices, among other nodes */
    91105    if (!S_ISBLK(statbuf->st_mode))
     
    100114        return TRUE;
    101115
    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
    111118    return TRUE;
    112119}
    113120
    114 static void
    115 uuidcache_init(void)
    116 {
     121static struct uuidCache_s*
     122uuidcache_init(int scan_devices)
     123{
     124    dbg("DBG: uuidCache=%x, uuidCache");
    117125    if (uuidCache)
    118         return;
     126        return uuidCache;
    119127
    120128    /* We were scanning /proc/partitions
     
    128136     * (Maybe add scanning of /sys/block/XXX/dev for devices
    129137     * 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;
    136146}
    137147
     
    145155    struct uuidCache_s *uc;
    146156
    147     uuidcache_init();
    148     uc = uuidCache;
    149 
     157    uc = uuidcache_init(/*scan_devices:*/ 1);
    150158    while (uc) {
    151159        switch (n) {
     
    212220
    213221/* 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);
     222void 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
    226237        bb_putchar('\n');
    227         u = u->next;
    228     }
    229 }
     238        uc = uc->next;
     239    }
     240}
     241
     242int 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
    230264
    231265/* Used by mount and findfs */
     
    235269    struct uuidCache_s *uc;
    236270
    237     uuidcache_init();
    238     uc = uuidCache;
     271    uc = uuidcache_init(/*scan_devices:*/ 1);
    239272    while (uc) {
    240273        if (uc->label[0] && strcmp(spec, uc->label) == 0) {
     
    250283    struct uuidCache_s *uc;
    251284
    252     uuidcache_init();
    253     uc = uuidCache;
     285    uc = uuidcache_init(/*scan_devices:*/ 1);
    254286    while (uc) {
    255287        /* case of hex numbers doesn't matter */
Note: See TracChangeset for help on using the changeset viewer.