~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to coreutils/du.c

  • Committer: Denys Vlasenko
  • Author(s): Christian Franke
  • Date: 2023-11-13 10:32:35 UTC
  • Revision ID: git-v1:a63b60bdd6fa26b867c80d44074118babbae7ffd
Cygwin: regenerate defconfig

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * 4) Fixed busybox bug #1284 involving long overflow with human_readable.
20
20
 */
21
21
//config:config DU
22
 
//config:       bool "du (6.3 kb)"
 
22
//config:       bool "du (6.5 kb)"
23
23
//config:       default y
24
24
//config:       help
25
25
//config:       du is used to report the amount of disk space used
40
40
//usage:#define du_trivial_usage
41
41
//usage:       "[-aHLdclsx" IF_FEATURE_HUMAN_READABLE("hm") "k] [FILE]..."
42
42
//usage:#define du_full_usage "\n\n"
43
 
//usage:       "Summarize disk space used for each FILE and/or directory\n"
 
43
//usage:       "Summarize disk space used for FILEs (or directories)\n"
44
44
//usage:     "\n        -a      Show file sizes too"
 
45
//usage:     "\n        -b      Apparent size (including holes)"
45
46
//usage:     "\n        -L      Follow all symlinks"
46
47
//usage:     "\n        -H      Follow symlinks on command line"
47
48
//usage:     "\n        -d N    Limit output to directories (and files with -a) of depth < N"
84
85
        OPT_d_maxdepth     = (1 << 6),
85
86
        OPT_l_hardlinks    = (1 << 7),
86
87
        OPT_c_total        = (1 << 8),
87
 
        OPT_h_for_humans   = (1 << 9),
88
 
        OPT_m_mbytes       = (1 << 10),
 
88
        OPT_b              = (1 << 9),
 
89
        OPT_h_for_humans   = (1 << 10),
 
90
        OPT_m_mbytes       = (1 << 11),
89
91
};
90
92
 
91
93
struct globals {
109
111
        /* TODO - May not want to defer error checking here. */
110
112
#if ENABLE_FEATURE_HUMAN_READABLE
111
113
# if ENABLE_DESKTOP
112
 
        /* ~30 bytes of code for extra comtat:
 
114
        /* ~30 bytes of code for extra compat:
113
115
         * coreutils' du rounds sizes up:
114
116
         * for example,  1025k file is shown as "2" by du -m.
115
117
         * We round to nearest if human-readable [too hard to fix],
124
126
                         * If G.disp_unit == 0, show one fractional
125
127
                         * and use suffixes
126
128
                         */
127
 
                        make_human_readable_str(size, 512, G.disp_unit),
 
129
                        make_human_readable_str(size, (option_mask32 & OPT_b) ? 1 : 512, G.disp_unit),
128
130
                        filename);
129
131
#else
130
132
        if (G.disp_k) {
131
 
                size++;
132
 
                size >>= 1;
 
133
                if (!(option_mask32 & OPT_b)) {
 
134
                        size++;
 
135
                        size >>= 1;
 
136
                } else {
 
137
                        size >>= 10;
 
138
                }
133
139
        }
134
140
        printf("%llu\t%s\n", size, filename);
135
141
#endif
155
161
                }
156
162
        }
157
163
 
158
 
        sum = statbuf.st_blocks;
 
164
        sum = ((option_mask32 & OPT_b) ? statbuf.st_size : statbuf.st_blocks);
159
165
 
160
166
        if (S_ISLNK(statbuf.st_mode)) {
161
167
                if (G.slink_depth > G.du_depth) { /* -H or -L */
164
170
                                G.status = EXIT_FAILURE;
165
171
                                return 0;
166
172
                        }
167
 
                        sum = statbuf.st_blocks;
 
173
                        sum = ((option_mask32 & OPT_b) ? statbuf.st_size : statbuf.st_blocks);
168
174
                        if (G.slink_depth == 1) {
169
175
                                /* Convert -H to -L */
170
176
                                G.slink_depth = INT_MAX;
241
247
         */
242
248
#if ENABLE_FEATURE_HUMAN_READABLE
243
249
        opt = getopt32(argv, "^"
244
 
                        "aHkLsxd:+lchm"
 
250
                        "aHkLsxd:+lcbhm"
245
251
                        "\0" "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s",
246
252
                        &G.max_print_depth
247
253
        );
248
254
        argv += optind;
 
255
        if (opt & OPT_b) {
 
256
                G.disp_unit = 1;
 
257
        }
249
258
        if (opt & OPT_h_for_humans) {
250
259
                G.disp_unit = 0;
251
260
        }
257
266
        }
258
267
#else
259
268
        opt = getopt32(argv, "^"
260
 
                        "aHkLsxd:+lc"
 
269
                        "aHkLsxd:+lcb"
261
270
                        "\0" "H-L:L-H:s-d:d-s",
262
271
                        &G.max_print_depth
263
272
        );
264
273
        argv += optind;
265
 
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
 
274
# if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
266
275
        if (opt & OPT_k_kbytes) {
267
276
                G.disp_k = 1;
268
277
        }
269
 
#endif
 
278
# endif
270
279
#endif
271
280
        if (opt & OPT_H_follow_links) {
272
281
                G.slink_depth = 1;