aboutsummaryrefslogtreecommitdiff
path: root/coreutils/du.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-01 21:47:15 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-01 21:47:15 +0000
commit8b113f93b9b9157ea1e013667eaaf00aed97a251 (patch)
treec833c8f3a72637660af61b061b90d69d987fed25 /coreutils/du.c
parent4f6753e586dba5e6c240e670d41fc8fd011034e1 (diff)
downloadbusybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.tar.gz
busybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.tar.bz2
busybox-w32-8b113f93b9b9157ea1e013667eaaf00aed97a251.zip
Vladimir's last_patch13, containing several bugfixes.
Diffstat (limited to 'coreutils/du.c')
-rw-r--r--coreutils/du.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/coreutils/du.c b/coreutils/du.c
index 3e4821a39..fd19855e1 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -71,6 +71,78 @@ static void print_summary(long size, char *filename)
71 } 71 }
72} 72}
73 73
74#define HASH_SIZE 311 /* Should be prime */
75#define hash_inode(i) ((i) % HASH_SIZE)
76
77typedef struct ino_dev_hash_bucket_struct {
78 struct ino_dev_hash_bucket_struct *next;
79 ino_t ino;
80 dev_t dev;
81 char name[1];
82} ino_dev_hashtable_bucket_t;
83
84static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
85
86/*
87 * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
88 * `ino_dev_hashtable', else return 0
89 *
90 * If NAME is a non-NULL pointer to a character pointer, and there is
91 * a match, then set *NAME to the value of the name slot in that
92 * bucket.
93 */
94static int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
95{
96 ino_dev_hashtable_bucket_t *bucket;
97
98 bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
99 while (bucket != NULL) {
100 if ((bucket->ino == statbuf->st_ino) &&
101 (bucket->dev == statbuf->st_dev))
102 {
103 if (name) *name = bucket->name;
104 return 1;
105 }
106 bucket = bucket->next;
107 }
108 return 0;
109}
110
111/* Add statbuf to statbuf hash table */
112static void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
113{
114 int i;
115 size_t s;
116 ino_dev_hashtable_bucket_t *bucket;
117
118 i = hash_inode(statbuf->st_ino);
119 s = name ? strlen(name) : 0;
120 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
121 bucket->ino = statbuf->st_ino;
122 bucket->dev = statbuf->st_dev;
123 if (name)
124 strcpy(bucket->name, name);
125 else
126 bucket->name[0] = '\0';
127 bucket->next = ino_dev_hashtable[i];
128 ino_dev_hashtable[i] = bucket;
129}
130
131/* Clear statbuf hash table */
132static void reset_ino_dev_hashtable(void)
133{
134 int i;
135 ino_dev_hashtable_bucket_t *bucket;
136
137 for (i = 0; i < HASH_SIZE; i++) {
138 while (ino_dev_hashtable[i] != NULL) {
139 bucket = ino_dev_hashtable[i]->next;
140 free(ino_dev_hashtable[i]);
141 ino_dev_hashtable[i] = bucket;
142 }
143 }
144}
145
74/* tiny recursive du */ 146/* tiny recursive du */
75static long du(char *filename) 147static long du(char *filename)
76{ 148{
@@ -187,7 +259,7 @@ int du_main(int argc, char **argv)
187 return status; 259 return status;
188} 260}
189 261
190/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */ 262/* $Id: du.c,v 1.48 2001/06/01 21:47:15 andersen Exp $ */
191/* 263/*
192Local Variables: 264Local Variables:
193c-file-style: "linux" 265c-file-style: "linux"