Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/inode_hash.c

    r2725 r3621  
    1212
    1313typedef struct ino_dev_hash_bucket_struct {
    14     struct ino_dev_hash_bucket_struct *next;
    1514    ino_t ino;
    1615    dev_t dev;
     16    /*
     17     * Above fields can be 64-bit, while pointer may be 32-bit.
     18     * Putting "next" field here may reduce size of this struct:
     19     */
     20    struct ino_dev_hash_bucket_struct *next;
     21    /*
     22     * Reportedly, on cramfs a file and a dir can have same ino.
     23     * Need to also remember "file/dir" bit:
     24     */
     25    char isdir; /* bool */
    1726    char name[1];
    1827} ino_dev_hashtable_bucket_t;
    1928
    20 #define HASH_SIZE      311   /* Should be prime */
    21 #define hash_inode(i)  ((i) % HASH_SIZE)
     29#define HASH_SIZE      311u   /* Should be prime */
     30#define hash_inode(i)  ((unsigned)(i) % HASH_SIZE)
    2231
    2332/* array of [HASH_SIZE] elements */
     
    3948        if ((bucket->ino == statbuf->st_ino)
    4049         && (bucket->dev == statbuf->st_dev)
     50         && (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
    4151        ) {
    4252            return bucket->name;
     
    5363    ino_dev_hashtable_bucket_t *bucket;
    5464
    55     i = hash_inode(statbuf->st_ino);
    5665    if (!name)
    5766        name = "";
     
    5968    bucket->ino = statbuf->st_ino;
    6069    bucket->dev = statbuf->st_dev;
     70    bucket->isdir = !!S_ISDIR(statbuf->st_mode);
    6171    strcpy(bucket->name, name);
    6272
     
    6474        ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
    6575
     76    i = hash_inode(statbuf->st_ino);
    6677    bucket->next = ino_dev_hashtable[i];
    6778    ino_dev_hashtable[i] = bucket;
     
    7384{
    7485    int i;
    75     ino_dev_hashtable_bucket_t *bucket;
     86    ino_dev_hashtable_bucket_t *bucket, *next;
    7687
    77     for (i = 0; ino_dev_hashtable && i < HASH_SIZE; i++) {
    78         while (ino_dev_hashtable[i] != NULL) {
    79             bucket = ino_dev_hashtable[i]->next;
    80             free(ino_dev_hashtable[i]);
    81             ino_dev_hashtable[i] = bucket;
     88    if (!ino_dev_hashtable)
     89        return;
     90
     91    for (i = 0; i < HASH_SIZE; i++) {
     92        bucket = ino_dev_hashtable[i];
     93
     94        while (bucket != NULL) {
     95            next = bucket->next;
     96            free(bucket);
     97            bucket = next;
    8298        }
    8399    }
Note: See TracChangeset for help on using the changeset viewer.