Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/inode_hash.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/inode_hash.c
r2725 r3621 12 12 13 13 typedef struct ino_dev_hash_bucket_struct { 14 struct ino_dev_hash_bucket_struct *next;15 14 ino_t ino; 16 15 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 */ 17 26 char name[1]; 18 27 } ino_dev_hashtable_bucket_t; 19 28 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) 22 31 23 32 /* array of [HASH_SIZE] elements */ … … 39 48 if ((bucket->ino == statbuf->st_ino) 40 49 && (bucket->dev == statbuf->st_dev) 50 && (bucket->isdir == !!S_ISDIR(statbuf->st_mode)) 41 51 ) { 42 52 return bucket->name; … … 53 63 ino_dev_hashtable_bucket_t *bucket; 54 64 55 i = hash_inode(statbuf->st_ino);56 65 if (!name) 57 66 name = ""; … … 59 68 bucket->ino = statbuf->st_ino; 60 69 bucket->dev = statbuf->st_dev; 70 bucket->isdir = !!S_ISDIR(statbuf->st_mode); 61 71 strcpy(bucket->name, name); 62 72 … … 64 74 ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable)); 65 75 76 i = hash_inode(statbuf->st_ino); 66 77 bucket->next = ino_dev_hashtable[i]; 67 78 ino_dev_hashtable[i] = bucket; … … 73 84 { 74 85 int i; 75 ino_dev_hashtable_bucket_t *bucket ;86 ino_dev_hashtable_bucket_t *bucket, *next; 76 87 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; 82 98 } 83 99 }
Note:
See TracChangeset
for help on using the changeset viewer.