#include "libbb.h"
typedef struct ino_dev_hash_bucket_struct {
- struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
+ /*
+ * Above fields can be 64-bit, while pointer may be 32-bit.
+ * Putting "next" field here may reduce size of this struct:
+ */
+ struct ino_dev_hash_bucket_struct *next;
+ /*
+ * Reportedly, on cramfs a file and a dir can have same ino.
+ * Need to also remember "file/dir" bit:
+ */
+ char isdir; /* bool */
char name[1];
} ino_dev_hashtable_bucket_t;
-#define HASH_SIZE 311 /* Should be prime */
-#define hash_inode(i) ((i) % HASH_SIZE)
+#define HASH_SIZE 311u /* Should be prime */
+#define hash_inode(i) ((unsigned)(i) % HASH_SIZE)
/* array of [HASH_SIZE] elements */
static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
while (bucket != NULL) {
if ((bucket->ino == statbuf->st_ino)
&& (bucket->dev == statbuf->st_dev)
+ && (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
) {
return bucket->name;
}
int i;
ino_dev_hashtable_bucket_t *bucket;
- i = hash_inode(statbuf->st_ino);
if (!name)
name = "";
bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
bucket->ino = statbuf->st_ino;
bucket->dev = statbuf->st_dev;
+ bucket->isdir = !!S_ISDIR(statbuf->st_mode);
strcpy(bucket->name, name);
if (!ino_dev_hashtable)
ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
+ i = hash_inode(statbuf->st_ino);
bucket->next = ino_dev_hashtable[i];
ino_dev_hashtable[i] = bucket;
}