aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-25 15:27:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-25 15:27:58 +0100
commit83bc4332e7d6d74293c1c41e047d2681a8350e1a (patch)
tree45102af4f78dc84d4c49885a3505c8ee019f537f
parent12916b922065f452a5b6c043200ac0863853c7a3 (diff)
downloadbusybox-w32-83bc4332e7d6d74293c1c41e047d2681a8350e1a.tar.gz
busybox-w32-83bc4332e7d6d74293c1c41e047d2681a8350e1a.tar.bz2
busybox-w32-83bc4332e7d6d74293c1c41e047d2681a8350e1a.zip
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>
-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 2f02d0746..f11c2afb2 100644
--- a/libbb/inode_hash.c
+++ b/libbb/inode_hash.c
@@ -11,14 +11,23 @@
11#include "libbb.h" 11#include "libbb.h"
12 12
13typedef struct ino_dev_hash_bucket_struct { 13typedef struct ino_dev_hash_bucket_struct {
14 struct ino_dev_hash_bucket_struct *next;
15 ino_t ino; 14 ino_t ino;
16 dev_t dev; 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 char name[1]; 26 char name[1];
18} ino_dev_hashtable_bucket_t; 27} ino_dev_hashtable_bucket_t;
19 28
20#define HASH_SIZE 311 /* Should be prime */ 29#define HASH_SIZE 311u /* Should be prime */
21#define hash_inode(i) ((i) % HASH_SIZE) 30#define hash_inode(i) ((unsigned)(i) % HASH_SIZE)
22 31
23/* array of [HASH_SIZE] elements */ 32/* array of [HASH_SIZE] elements */
24static ino_dev_hashtable_bucket_t **ino_dev_hashtable; 33static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
@@ -38,6 +47,7 @@ char* FAST_FUNC is_in_ino_dev_hashtable(const struct stat *statbuf)
38 while (bucket != NULL) { 47 while (bucket != NULL) {
39 if ((bucket->ino == statbuf->st_ino) 48 if ((bucket->ino == statbuf->st_ino)
40 && (bucket->dev == statbuf->st_dev) 49 && (bucket->dev == statbuf->st_dev)
50 && (bucket->isdir == !!S_ISDIR(statbuf->st_mode))
41 ) { 51 ) {
42 return bucket->name; 52 return bucket->name;
43 } 53 }
@@ -52,17 +62,18 @@ void FAST_FUNC add_to_ino_dev_hashtable(const struct stat *statbuf, const char *
52 int i; 62 int i;
53 ino_dev_hashtable_bucket_t *bucket; 63 ino_dev_hashtable_bucket_t *bucket;
54 64
55 i = hash_inode(statbuf->st_ino);
56 if (!name) 65 if (!name)
57 name = ""; 66 name = "";
58 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name)); 67 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
59 bucket->ino = statbuf->st_ino; 68 bucket->ino = statbuf->st_ino;
60 bucket->dev = statbuf->st_dev; 69 bucket->dev = statbuf->st_dev;
70 bucket->isdir = !!S_ISDIR(statbuf->st_mode);
61 strcpy(bucket->name, name); 71 strcpy(bucket->name, name);
62 72
63 if (!ino_dev_hashtable) 73 if (!ino_dev_hashtable)
64 ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable)); 74 ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
65 75
76 i = hash_inode(statbuf->st_ino);
66 bucket->next = ino_dev_hashtable[i]; 77 bucket->next = ino_dev_hashtable[i];
67 ino_dev_hashtable[i] = bucket; 78 ino_dev_hashtable[i] = bucket;
68} 79}