commit 0690c1a0038c5e89780643c42c28e708a65f3764
parent 6a680269bfdc3e06b5090e3f510b6ee99e12c6da
Author: sin <sin@2f30.org>
Date: Fri, 18 Oct 2013 16:40:31 +0100
Always round up to the next blocksize unit in du(1)
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/du.c b/du.c
@@ -97,6 +97,12 @@ pop(char *path)
}
static long
+nblks(struct stat *st)
+{
+ return (512 * st->st_blocks + blksize - 1) / blksize;
+}
+
+static long
du(const char *path)
{
DIR *dp;
@@ -107,7 +113,7 @@ du(const char *path)
if (lstat(path, &st) < 0)
eprintf("stat: %s:", path);
- n = 512 * st.st_blocks / blksize;
+ n = nblks(&st);
if (!S_ISDIR(st.st_mode))
goto done;
@@ -130,7 +136,7 @@ du(const char *path)
n += du(dent->d_name);
continue;
}
- m = 512 * st.st_blocks / blksize;
+ m = nblks(&st);
n += m;
if (aflag && !sflag) {
if (S_ISLNK(st.st_mode))