Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini du implementation for busybox |
| 4 | * |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999,2000,2001 by Lineo, inc. and John Beppu |
| 6 | * Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org> |
Eric Andersen | 265d229 | 2002-04-06 23:16:44 +0000 | [diff] [blame] | 7 | * Copyright (C) 2002 Edward Betts <edward@debian.org> |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 8 | * |
Bernhard Reutner-Fischer | cb44816 | 2006-04-12 07:35:12 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 12 | /* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */ |
| 13 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/du.html */ |
| 14 | |
| 15 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) |
| 16 | * |
| 17 | * Mostly rewritten for SUSv3 compliance and to fix bugs/defects. |
| 18 | * 1) Added support for SUSv3 -a, -H, -L, gnu -c, and (busybox) -d options. |
| 19 | * The -d option allows setting of max depth (similar to gnu --max-depth). |
| 20 | * 2) Fixed incorrect size calculations for links and directories, especially |
| 21 | * when errors occurred. Calculates sizes should now match gnu du output. |
| 22 | * 3) Added error checking of output. |
| 23 | * 4) Fixed busybox bug #1284 involving long overflow with human_readable. |
| 24 | */ |
| 25 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 26 | #include "libbb.h" |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 27 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 28 | struct globals { |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 29 | #if ENABLE_FEATURE_HUMAN_READABLE |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 30 | unsigned long disp_hr; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 31 | #else |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 32 | unsigned disp_k; |
Richard June | 6d0921c | 2001-01-22 22:35:38 +0000 | [diff] [blame] | 33 | #endif |
| 34 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 35 | int max_print_depth; |
| 36 | nlink_t count_hardlinks; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 37 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 38 | bool status; |
| 39 | bool one_file_system; |
| 40 | int print_files; |
| 41 | int slink_depth; |
| 42 | int du_depth; |
| 43 | dev_t dir_dev; |
| 44 | }; |
| 45 | #define G (*(struct globals*)&bb_common_bufsiz1) |
John Beppu | e1618e4 | 1999-12-15 18:52:17 +0000 | [diff] [blame] | 46 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 47 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 48 | static void print(unsigned long size, const char *filename) |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 49 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 50 | /* TODO - May not want to defer error checking here. */ |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 51 | #if ENABLE_FEATURE_HUMAN_READABLE |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 52 | printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr), |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 53 | filename); |
Richard June | 6d0921c | 2001-01-22 22:35:38 +0000 | [diff] [blame] | 54 | #else |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 55 | if (G.disp_k) { |
Glenn L McGrath | c66ebe4 | 2004-03-10 09:58:51 +0000 | [diff] [blame] | 56 | size++; |
| 57 | size >>= 1; |
| 58 | } |
Denis Vlasenko | f0ed376 | 2006-10-26 23:21:47 +0000 | [diff] [blame] | 59 | printf("%ld\t%s\n", size, filename); |
Richard June | 6d0921c | 2001-01-22 22:35:38 +0000 | [diff] [blame] | 60 | #endif |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* tiny recursive du */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 64 | static unsigned long du(const char *filename) |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 65 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 66 | struct stat statbuf; |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 67 | unsigned long sum; |
John Beppu | 14c82b6 | 1999-12-10 06:15:27 +0000 | [diff] [blame] | 68 | |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 69 | if (lstat(filename, &statbuf) != 0) { |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 70 | bb_simple_perror_msg(filename); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 71 | G.status = EXIT_FAILURE; |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 72 | return 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 75 | if (G.one_file_system) { |
| 76 | if (G.du_depth == 0) { |
| 77 | G.dir_dev = statbuf.st_dev; |
| 78 | } else if (G.dir_dev != statbuf.st_dev) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 79 | return 0; |
Eric Andersen | 8fa1bf7 | 2001-06-30 17:54:20 +0000 | [diff] [blame] | 80 | } |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 81 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 82 | |
| 83 | sum = statbuf.st_blocks; |
| 84 | |
| 85 | if (S_ISLNK(statbuf.st_mode)) { |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 86 | if (G.slink_depth > G.du_depth) { /* -H or -L */ |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 87 | if (stat(filename, &statbuf) != 0) { |
Denis Vlasenko | 0c97c9d | 2007-10-01 11:58:38 +0000 | [diff] [blame] | 88 | bb_simple_perror_msg(filename); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 89 | G.status = EXIT_FAILURE; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | sum = statbuf.st_blocks; |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 93 | if (G.slink_depth == 1) { |
| 94 | G.slink_depth = INT_MAX; /* Convert -H to -L. */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 99 | if (statbuf.st_nlink > G.count_hardlinks) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 100 | /* Add files/directories with links only once */ |
Denis Vlasenko | e1e93c1 | 2007-03-14 22:06:57 +0000 | [diff] [blame] | 101 | if (is_in_ino_dev_hashtable(&statbuf)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | add_to_ino_dev_hashtable(&statbuf, NULL); |
| 105 | } |
| 106 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 107 | if (S_ISDIR(statbuf.st_mode)) { |
| 108 | DIR *dir; |
| 109 | struct dirent *entry; |
Eric Andersen | 04b0354 | 2001-05-07 22:49:43 +0000 | [diff] [blame] | 110 | char *newfile; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 111 | |
Rob Landley | 86b4d64 | 2006-08-03 17:58:17 +0000 | [diff] [blame] | 112 | dir = warn_opendir(filename); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 113 | if (!dir) { |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 114 | G.status = EXIT_FAILURE; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 115 | return sum; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 116 | } |
Erik Andersen | 42387e4 | 2000-02-21 17:27:17 +0000 | [diff] [blame] | 117 | |
Eric Andersen | 04b0354 | 2001-05-07 22:49:43 +0000 | [diff] [blame] | 118 | newfile = last_char_is(filename, '/'); |
| 119 | if (newfile) |
| 120 | *newfile = '\0'; |
Erik Andersen | 42387e4 | 2000-02-21 17:27:17 +0000 | [diff] [blame] | 121 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 122 | while ((entry = readdir(dir))) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 123 | char *name = entry->d_name; |
| 124 | |
Glenn L McGrath | 393183d | 2003-05-26 14:07:50 +0000 | [diff] [blame] | 125 | newfile = concat_subpath_file(filename, name); |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 126 | if (newfile == NULL) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 127 | continue; |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 128 | ++G.du_depth; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 129 | sum += du(newfile); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 130 | --G.du_depth; |
Eric Andersen | e5dfced | 2001-04-09 22:48:12 +0000 | [diff] [blame] | 131 | free(newfile); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 132 | } |
| 133 | closedir(dir); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 134 | } else if (G.du_depth > G.print_files) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 135 | return sum; |
Erik Andersen | 27fdd08 | 2000-02-19 18:16:49 +0000 | [diff] [blame] | 136 | } |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 137 | if (G.du_depth <= G.max_print_depth) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 138 | print(sum, filename); |
| 139 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 140 | return sum; |
John Beppu | 0f5e1ab | 1999-12-09 18:23:54 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 143 | int du_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 144 | int du_main(int argc UNUSED_PARAM, char **argv) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 145 | { |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 146 | unsigned long total; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 147 | int slink_depth_save; |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 148 | bool print_final_total; |
Denis Vlasenko | 67b23e6 | 2006-10-03 21:00:06 +0000 | [diff] [blame] | 149 | unsigned opt; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 150 | |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 151 | #if ENABLE_FEATURE_HUMAN_READABLE |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 152 | USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;) |
| 153 | SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;) |
| 154 | if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */ |
| 155 | G.disp_hr = 512; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 156 | #else |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 157 | USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;) |
| 158 | /* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 159 | #endif |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 160 | G.max_print_depth = INT_MAX; |
| 161 | G.count_hardlinks = 1; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 162 | |
Denis Vlasenko | e1a0d48 | 2006-10-20 13:28:22 +0000 | [diff] [blame] | 163 | /* Note: SUSv3 specifies that -a and -s options cannot be used together |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 164 | * in strictly conforming applications. However, it also says that some |
| 165 | * du implementations may produce output when -a and -s are used together. |
| 166 | * gnu du exits with an error code in this case. We choose to simply |
| 167 | * ignore -a. This is consistent with -s being equivalent to -d 0. |
| 168 | */ |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 169 | #if ENABLE_FEATURE_HUMAN_READABLE |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 170 | opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+"; |
| 171 | opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 172 | argv += optind; |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 173 | if (opt & (1 << 9)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 174 | /* -h opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 175 | G.disp_hr = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 176 | } |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 177 | if (opt & (1 << 10)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 178 | /* -m opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 179 | G.disp_hr = 1024*1024; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 180 | } |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 181 | if (opt & (1 << 2)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 182 | /* -k opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 183 | G.disp_hr = 1024; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 184 | } |
| 185 | #else |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 186 | opt_complementary = "H-L:L-H:s-d:d-s:d+"; |
| 187 | opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 188 | argv += optind; |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 189 | #if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K |
| 190 | if (opt & (1 << 2)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 191 | /* -k opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 192 | G.disp_k = 1; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | #endif |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 196 | if (opt & (1 << 0)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 197 | /* -a opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 198 | G.print_files = INT_MAX; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 199 | } |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 200 | if (opt & (1 << 1)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 201 | /* -H opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 202 | G.slink_depth = 1; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 203 | } |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 204 | if (opt & (1 << 3)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 205 | /* -L opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 206 | G.slink_depth = INT_MAX; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 207 | } |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 208 | if (opt & (1 << 4)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 209 | /* -s opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 210 | G.max_print_depth = 0; |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 211 | } |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 212 | G.one_file_system = opt & (1 << 5); /* -x opt */ |
Denis Vlasenko | f42ff90 | 2006-12-18 21:22:16 +0000 | [diff] [blame] | 213 | if (opt & (1 << 7)) { |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 214 | /* -l opt */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 215 | G.count_hardlinks = MAXINT(nlink_t); |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 216 | } |
| 217 | print_final_total = opt & (1 << 8); /* -c opt */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 218 | |
| 219 | /* go through remaining args (if any) */ |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 220 | if (!*argv) { |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 221 | *--argv = (char*)"."; |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 222 | if (G.slink_depth == 1) { |
| 223 | G.slink_depth = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 227 | slink_depth_save = G.slink_depth; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 228 | total = 0; |
| 229 | do { |
| 230 | total += du(*argv); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 231 | G.slink_depth = slink_depth_save; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 232 | } while (*++argv); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 233 | |
Bernhard Reutner-Fischer | bdd253e | 2007-04-05 09:21:24 +0000 | [diff] [blame] | 234 | if (ENABLE_FEATURE_CLEAN_UP) |
| 235 | reset_ino_dev_hashtable(); |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 236 | if (print_final_total) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 237 | print(total, "total"); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 238 | |
Denis Vlasenko | 21b83cf | 2007-09-03 20:05:58 +0000 | [diff] [blame] | 239 | fflush_stdout_and_exit(G.status); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 240 | } |