summaryrefslogtreecommitdiff
path: root/libbb/inode_hash.c
diff options
context:
space:
mode:
authorDenys Vlasenko2014-02-25 15:27:58 +0100
committerDenys Vlasenko2014-02-25 15:27:58 +0100
commit83bc4332e7d6d74293c1c41e047d2681a8350e1a (patch)
tree45102af4f78dc84d4c49885a3505c8ee019f537f /libbb/inode_hash.c
parent12916b922065f452a5b6c043200ac0863853c7a3 (diff)
downloadbusybox-83bc4332e7d6d74293c1c41e047d2681a8350e1a.zip
busybox-83bc4332e7d6d74293c1c41e047d2681a8350e1a.tar.gz
du, copy_file: fix file matching on cramfs. Closes 5456
function old new delta is_in_ino_dev_hashtable 88 108 +20 add_to_ino_dev_hashtable 150 142 -8 reset_ino_dev_hashtable 84 75 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 20/-17) Total: 3 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/inode_hash.c')
-rw-r--r--libbb/inode_hash.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/libbb/inode_hash.c b/libbb/inode_hash.c
index 2f02d07..f11c2af 100644
--- a/libbb/inode_hash.c
+++ b/libbb/inode_hash.c
@@ -11,14 +11,23 @@
#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;
@@ -38,6 +47,7 @@ char* FAST_FUNC is_in_ino_dev_hashtable(const struct stat *statbuf)
while (bucket != NULL) {
if ((bucket->ino == statbuf->st_ino)
&& (bucket->dev == statbuf->st_dev)
+ && (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
) {
return bucket->name;
}
@@ -52,17 +62,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
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;
}