Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/inode_hash.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/inode_hash.c
r821 r1770 9 9 */ 10 10 11 #include <stdio.h>12 #include <stdlib.h>13 #include <string.h>14 11 #include "libbb.h" 12 13 typedef struct ino_dev_hash_bucket_struct { 14 struct ino_dev_hash_bucket_struct *next; 15 ino_t ino; 16 dev_t dev; 17 char name[1]; 18 } ino_dev_hashtable_bucket_t; 15 19 16 20 #define HASH_SIZE 311 /* Should be prime */ 17 21 #define hash_inode(i) ((i) % HASH_SIZE) 18 22 19 typedef struct ino_dev_hash_bucket_struct { 20 struct ino_dev_hash_bucket_struct *next; 21 ino_t ino; 22 dev_t dev; 23 char name[1]; 24 } ino_dev_hashtable_bucket_t; 25 26 static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE]; 23 /* array of [HASH_SIZE] elements */ 24 static ino_dev_hashtable_bucket_t **ino_dev_hashtable; 27 25 28 26 /* 29 * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in 30 * `ino_dev_hashtable', else return 0 31 * 32 * If NAME is a non-NULL pointer to a character pointer, and there is 33 * a match, then set *NAME to the value of the name slot in that 34 * bucket. 27 * Return name if statbuf->st_ino && statbuf->st_dev are recorded in 28 * ino_dev_hashtable, else return NULL 35 29 */ 36 int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)30 char *is_in_ino_dev_hashtable(const struct stat *statbuf) 37 31 { 38 32 ino_dev_hashtable_bucket_t *bucket; 39 33 34 if (!ino_dev_hashtable) 35 return NULL; 36 40 37 bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)]; 41 38 while (bucket != NULL) { 42 if ((bucket->ino == statbuf->st_ino) && 43 (bucket->dev == statbuf->st_dev)) 44 { 45 if (name) *name = bucket->name; 46 return 1; 47 } 48 bucket = bucket->next; 39 if ((bucket->ino == statbuf->st_ino) 40 && (bucket->dev == statbuf->st_dev) 41 ) { 42 return bucket->name; 43 } 44 bucket = bucket->next; 49 45 } 50 return 0;46 return NULL; 51 47 } 52 48 … … 55 51 { 56 52 int i; 57 size_t s;58 53 ino_dev_hashtable_bucket_t *bucket; 59 54 60 55 i = hash_inode(statbuf->st_ino); 61 s = name ? strlen(name) : 0; 62 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s); 56 if (!name) 57 name = ""; 58 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name)); 63 59 bucket->ino = statbuf->st_ino; 64 60 bucket->dev = statbuf->st_dev; 65 if (name) 66 strcpy(bucket->name, name); 67 else 68 bucket->name[0] = '\0'; 61 strcpy(bucket->name, name); 62 63 if (!ino_dev_hashtable) 64 ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable)); 65 69 66 bucket->next = ino_dev_hashtable[i]; 70 67 ino_dev_hashtable[i] = bucket; 71 68 } 72 69 73 #if def CONFIG_FEATURE_CLEAN_UP70 #if ENABLE_FEATURE_CLEAN_UP 74 71 /* Clear statbuf hash table */ 75 72 void reset_ino_dev_hashtable(void) … … 78 75 ino_dev_hashtable_bucket_t *bucket; 79 76 80 for (i = 0; i < HASH_SIZE; i++) {77 for (i = 0; ino_dev_hashtable && i < HASH_SIZE; i++) { 81 78 while (ino_dev_hashtable[i] != NULL) { 82 79 bucket = ino_dev_hashtable[i]->next; … … 85 82 } 86 83 } 84 free(ino_dev_hashtable); 85 ino_dev_hashtable = NULL; 87 86 } 87 #else 88 void reset_ino_dev_hashtable(void); 88 89 #endif
Note:
See TracChangeset
for help on using the changeset viewer.