[PATCH] Use 'long long' for size field in du
Ian Wienand
ianw at vmware.com
Mon Feb 27 22:40:26 UTC 2012
Hi,
Busybox du has issues with files reporting large block counts on
32-bit systems with 4 byte longs. From looking at the stat.c code, it
seem the preference is to use 'long long', rather than blkcnt_t.
I confirmed it worked with some testing using a stat wrapper that
faked AUTHORS as a 2TB file.
---
$ LD_PRELOAD=/tmp/fake-stat.so ./busybox_old du ./AUTHORS
10 ./AUTHORS
$ LD_PRELOAD=/tmp/fake-stat.so ./busybox du ./AUTHORS
2147483658 ./AUTHORS
$ LD_PRELOAD=/tmp/fake-stat.so ./busybox du -h ./AUTHORS
2.0T ./AUTHORS
---
Thanks,
-i
function old new delta
du 420 444 +24
du_main 317 321 +4
print 43 41 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/1 up/down: 28/-2) Total: 26 bytes
text data bss dec hex filename
732467 2074 9036 743577 b5899 busybox_old
732493 2074 9036 743603 b58b3 busybox_unstripped
Signed-off-by: Ian Wienand <ianw at vmware.com>
---
coreutils/du.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/coreutils/du.c b/coreutils/du.c
index 34a549f..09a908c 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -91,7 +91,7 @@ struct globals {
#define INIT_G() do { } while (0)
-static void print(unsigned long size, const char *filename)
+static void print(unsigned long long size, const char *filename)
{
/* TODO - May not want to defer error checking here. */
#if ENABLE_FEATURE_HUMAN_READABLE
@@ -105,15 +105,15 @@ static void print(unsigned long size, const char *filename)
size++;
size >>= 1;
}
- printf("%lu\t%s\n", size, filename);
+ printf("%llu\t%s\n", size, filename);
#endif
}
/* tiny recursive du */
-static unsigned long du(const char *filename)
+static unsigned long long du(const char *filename)
{
struct stat statbuf;
- unsigned long sum;
+ unsigned long long sum;
if (lstat(filename, &statbuf) != 0) {
bb_simple_perror_msg(filename);
@@ -190,7 +190,7 @@ static unsigned long du(const char *filename)
int du_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int du_main(int argc UNUSED_PARAM, char **argv)
{
- unsigned long total;
+ unsigned long long total;
int slink_depth_save;
unsigned opt;
--
1.7.4.1
More information about the busybox
mailing list