Mirror of git://git.busybox.net/busybox with our patches on top
Source
/* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
/* vi: set sw=4 ts=4: */
/*
* Mini du implementation for busybox
*
* Copyright (C) 1999,2000,2001 by Lineo, inc. and John Beppu
* Copyright (C) 1999,2000,2001 by John Beppu <beppu@codepoet.org>
* Copyright (C) 2002 Edward Betts <edward@debian.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT SUSv3 compliant (unless default blocksize set to 1k) */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/du.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Mostly rewritten for SUSv3 compliance and to fix bugs/defects.
* 1) Added support for SUSv3 -a, -H, -L, gnu -c, and (busybox) -d options.
* The -d option allows setting of max depth (similar to gnu --max-depth).
* 2) Fixed incorrect size calculations for links and directories, especially
* when errors occurred. Calculates sizes should now match gnu du output.
* 3) Added error checking of output.
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
*/
enum {
OPT_a_files_too = (1 << 0),
OPT_H_follow_links = (1 << 1),
OPT_k_kbytes = (1 << 2),
OPT_L_follow_links = (1 << 3),
OPT_s_total_norecurse = (1 << 4),
OPT_x_one_FS = (1 << 5),
OPT_d_maxdepth = (1 << 6),
OPT_l_hardlinks = (1 << 7),
OPT_c_total = (1 << 8),
OPT_h_for_humans = (1 << 9),
OPT_m_mbytes = (1 << 10),
};
struct globals {
unsigned long disp_hr;
unsigned disp_k;
int max_print_depth;
bool status;
int slink_depth;
int du_depth;
dev_t dir_dev;
} FIX_ALIASING;
static void print(unsigned long size, const char *filename)
{
/* TODO - May not want to defer error checking here. */
printf("%s\t%s\n",
/* size x 512 / G.disp_hr, show one fractional,
* use suffixes if G.disp_hr == 0 */