diff options
author | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-03-04 21:19:32 +0000 |
---|---|---|
committer | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-03-04 21:19:32 +0000 |
commit | f042f3c095e99887a076427cc04de54f90fe2c29 (patch) | |
tree | 7c49f1fc1547a2f9cee812472f422a5c1a5c448b /du.c | |
parent | 6b65252692f961f249492e7768d7b2826600d956 (diff) | |
download | busybox-w32-f042f3c095e99887a076427cc04de54f90fe2c29.tar.gz busybox-w32-f042f3c095e99887a076427cc04de54f90fe2c29.tar.bz2 busybox-w32-f042f3c095e99887a076427cc04de54f90fe2c29.zip |
A few updates (including the cp fix the Craig has been looking for)
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@386 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'du.c')
-rw-r--r-- | du.c | 71 |
1 files changed, 11 insertions, 60 deletions
@@ -36,16 +36,6 @@ | |||
36 | 36 | ||
37 | typedef void (Display) (long, char *); | 37 | typedef void (Display) (long, char *); |
38 | 38 | ||
39 | typedef struct inode_type { | ||
40 | struct inode_type *next; | ||
41 | ino_t ino; | ||
42 | } INODETYPE; | ||
43 | |||
44 | #define HASH_SIZE 311 /* Should be prime */ | ||
45 | #define hash_inode(i) ((i) % HASH_SIZE) | ||
46 | |||
47 | static INODETYPE *inode_hash_list[HASH_SIZE]; | ||
48 | |||
49 | static const char du_usage[] = | 39 | static const char du_usage[] = |
50 | "du [OPTION]... [FILE]...\n\n" | 40 | "du [OPTION]... [FILE]...\n\n" |
51 | "Summarize disk space used for each FILE and/or directory.\n" | 41 | "Summarize disk space used for each FILE and/or directory.\n" |
@@ -71,52 +61,6 @@ static void print_summary(long size, char *filename) | |||
71 | } | 61 | } |
72 | } | 62 | } |
73 | 63 | ||
74 | /* Return 1 if inode is in inode hash list, else return 0 */ | ||
75 | static int is_in_list(const ino_t ino) | ||
76 | { | ||
77 | INODETYPE *inode; | ||
78 | |||
79 | inode = inode_hash_list[hash_inode(ino)]; | ||
80 | while (inode != NULL) { | ||
81 | if (inode->ino == ino) | ||
82 | return 1; | ||
83 | inode = inode->next; | ||
84 | } | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | /* Add inode to inode hash list */ | ||
90 | static void add_inode(const ino_t ino) | ||
91 | { | ||
92 | int i; | ||
93 | INODETYPE *inode; | ||
94 | |||
95 | i = hash_inode(ino); | ||
96 | inode = malloc(sizeof(INODETYPE)); | ||
97 | if (inode == NULL) | ||
98 | fatalError("du: Not enough memory."); | ||
99 | |||
100 | inode->ino = ino; | ||
101 | inode->next = inode_hash_list[i]; | ||
102 | inode_hash_list[i] = inode; | ||
103 | } | ||
104 | |||
105 | /* Clear inode hash list */ | ||
106 | static void reset_inode_list(void) | ||
107 | { | ||
108 | int i; | ||
109 | INODETYPE *inode; | ||
110 | |||
111 | for (i = 0; i < HASH_SIZE; i++) { | ||
112 | while (inode_hash_list[i] != NULL) { | ||
113 | inode = inode_hash_list[i]->next; | ||
114 | free(inode_hash_list[i]); | ||
115 | inode_hash_list[i] = inode; | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | /* tiny recursive du */ | 64 | /* tiny recursive du */ |
121 | static long du(char *filename) | 65 | static long du(char *filename) |
122 | { | 66 | { |
@@ -175,13 +119,13 @@ static long du(char *filename) | |||
175 | } | 119 | } |
176 | else if (statbuf.st_nlink > 1 && !count_hardlinks) { | 120 | else if (statbuf.st_nlink > 1 && !count_hardlinks) { |
177 | /* Add files with hard links only once */ | 121 | /* Add files with hard links only once */ |
178 | if (is_in_list(statbuf.st_ino)) { | 122 | if (is_in_ino_dev_hashtable(&statbuf, NULL)) { |
179 | sum = 0L; | 123 | sum = 0L; |
180 | if (du_depth == 1) | 124 | if (du_depth == 1) |
181 | print(sum, filename); | 125 | print(sum, filename); |
182 | } | 126 | } |
183 | else { | 127 | else { |
184 | add_inode(statbuf.st_ino); | 128 | add_to_ino_dev_hashtable(&statbuf, NULL); |
185 | } | 129 | } |
186 | } | 130 | } |
187 | du_depth--; | 131 | du_depth--; |
@@ -231,11 +175,18 @@ int du_main(int argc, char **argv) | |||
231 | if (sum && isDirectory(argv[i], FALSE, NULL)) { | 175 | if (sum && isDirectory(argv[i], FALSE, NULL)) { |
232 | print_normal(sum, argv[i]); | 176 | print_normal(sum, argv[i]); |
233 | } | 177 | } |
234 | reset_inode_list(); | 178 | reset_ino_dev_hashtable(); |
235 | } | 179 | } |
236 | } | 180 | } |
237 | 181 | ||
238 | exit(0); | 182 | exit(0); |
239 | } | 183 | } |
240 | 184 | ||
241 | /* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */ | 185 | /* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */ |
186 | /* | ||
187 | Local Variables: | ||
188 | c-file-style: "linux" | ||
189 | c-basic-offset: 4 | ||
190 | tab-width: 4 | ||
191 | End: | ||
192 | */ | ||