Always round up to the next blocksize unit in du(1)
This commit is contained in:
parent
6a680269bf
commit
0690c1a003
10
du.c
10
du.c
|
@ -96,6 +96,12 @@ pop(char *path)
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
nblks(struct stat *st)
|
||||||
|
{
|
||||||
|
return (512 * st->st_blocks + blksize - 1) / blksize;
|
||||||
|
}
|
||||||
|
|
||||||
static long
|
static long
|
||||||
du(const char *path)
|
du(const char *path)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +113,7 @@ du(const char *path)
|
||||||
|
|
||||||
if (lstat(path, &st) < 0)
|
if (lstat(path, &st) < 0)
|
||||||
eprintf("stat: %s:", path);
|
eprintf("stat: %s:", path);
|
||||||
n = 512 * st.st_blocks / blksize;
|
n = nblks(&st);
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode))
|
if (!S_ISDIR(st.st_mode))
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -130,7 +136,7 @@ du(const char *path)
|
||||||
n += du(dent->d_name);
|
n += du(dent->d_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m = 512 * st.st_blocks / blksize;
|
m = nblks(&st);
|
||||||
n += m;
|
n += m;
|
||||||
if (aflag && !sflag) {
|
if (aflag && !sflag) {
|
||||||
if (S_ISLNK(st.st_mode))
|
if (S_ISLNK(st.st_mode))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user