aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/du.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-10-01 18:19:45 -0500
committerRob Landley <rob@landley.net>2016-10-01 18:19:45 -0500
commit8d0f0b6ba864155914f88e39076213b4486efee4 (patch)
tree12b3107346a7bb0b89a09a0f705df3ba69aa8316 /toys/posix/du.c
parent29e75d51d447c5c0aae9834f5988b79a945c7acc (diff)
downloadtoybox-8d0f0b6ba864155914f88e39076213b4486efee4.tar.gz
du: 32 bit systems were maxing out at 2GB when they should max out at 2TB
(1<<32 blocks * 512 bytes, done with unsigned 64 bit math).
Diffstat (limited to 'toys/posix/du.c')
-rw-r--r--toys/posix/du.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/toys/posix/du.c b/toys/posix/du.c
index 2797b3f4..fad46a32 100644
--- a/toys/posix/du.c
+++ b/toys/posix/du.c
@@ -39,7 +39,7 @@ config DU
GLOBALS(
long maxdepth;
- long depth, total;
+ unsigned long depth, total;
dev_t st_dev;
void *inodes;
)
@@ -103,9 +103,11 @@ static int seen_inode(void **list, struct stat *st)
return 0;
}
-// dirtree callback, comput/display size of node
+// dirtree callback, compute/display size of node
static int do_du(struct dirtree *node)
{
+ unsigned long blocks;
+
if (!node->parent) TT.st_dev = node->st.st_dev;
else if (!dirtree_notdotdot(node)) return 0;
@@ -134,14 +136,19 @@ static int do_du(struct dirtree *node)
} else TT.depth--;
}
- node->extra += node->st.st_blocks;
- if (node->parent) node->parent->extra += node->extra;
+ // Modern compilers' optimizers are insane and think signed overflow
+ // behaves differently than unsigned overflow. Sigh. Big hammer.
+ blocks = node->st.st_blocks + (unsigned long)node->extra;
+ node->extra = blocks;
+ if (node->parent)
+ node->parent->extra = (unsigned long)node->parent->extra+blocks;
else TT.total += node->extra;
if ((toys.optflags & FLAG_a) || !node->parent
|| (S_ISDIR(node->st.st_mode) && !(toys.optflags & FLAG_s)))
{
- print(node->extra*512, node);
+ blocks = node->extra;
+ print(blocks*512LL, node);
}
return 0;