bin/122043: du does not support byte-count-based reporting (-b
argument)
Drkshadow
freebsd-bugs.20.drkshadow at spamgourmet.com
Mon Mar 24 09:10:02 UTC 2008
>Number: 122043
>Category: bin
>Synopsis: du does not support byte-count-based reporting (-b argument)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Mar 24 09:10:02 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Drkshadow
>Release: FreeBSD 6.2-RELEASE-p10
>Organization:
>Environment:
FreeBSD DrkShadow.com 6.2-RELEASE-p10 FreeBSD 6.2-RELEASE-p10 #1: Mon Jan 28 06:51:11 MST 2008 root at DrkShadow.com:/usr/obj/usr/src/sys/via-c7 i386
>Description:
du(1) that comes with FreeBSD does not understand the -b argument, and these is no way to achieve such functionality using the BLOCKSIZE environment variable. As far as I know, this option is not required by POSIX, but it's trivially implemented using a different member of the stat(2) structure and an if to separate block counts from byte counts.
The only issue that I can see is for filesystems containing files that sum up to more than 8 exabytes in size -- in this case, the 64-bit integer used to store the byte count will overflow. Multiply this by 512 for the maximum size for block-based counting. If it becomes an issue, a check can be put in to compare the addition and, if the result is less than the additive value, throw an error.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
Only in a/usr.bin/du: Makefile
diff -u -r a/usr.bin/du/du.1 b/usr.bin/du/du.1
--- a/usr.bin/du/du.1 Mon Mar 24 02:56:25 2008
+++ b/usr.bin/du/du.1 Mon Mar 24 02:59:40 2008
@@ -43,7 +43,7 @@
.Op Fl H | L | P
.Op Fl a | s | d Ar depth
.Op Fl c
-.Op Fl h | k | m
+.Op Fl h | b | k | m
.Op Fl n
.Op Fl x
.Op Fl I Ar mask
@@ -92,6 +92,8 @@
directories deep.
.It Fl c
Display a grand total.
+.It Fl b
+Display block counts in bytes.
.It Fl k
Display block counts in 1024-byte (1-Kbyte) blocks.
.It Fl m
diff -u -r a/usr.bin/du/du.c b/usr.bin/du/du.c
--- a/usr.bin/du/du.c Mon Mar 24 02:56:25 2008
+++ b/usr.bin/du/du.c Mon Mar 24 03:05:13 2008
@@ -90,20 +90,20 @@
int ftsoptions;
int listall;
int depth;
- int Hflag, Lflag, Pflag, aflag, sflag, dflag, cflag, hflag, ch, notused, rval;
+ int Hflag, Lflag, Pflag, aflag, bflag, sflag, dflag, cflag, hflag, ch, notused, rval;
char **save;
static char dot[] = ".";
setlocale(LC_ALL, "");
- Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag = 0;
+ Hflag = Lflag = Pflag = aflag = bflag = sflag = dflag = cflag = hflag = 0;
save = argv;
ftsoptions = 0;
depth = INT_MAX;
SLIST_INIT(&ignores);
- while ((ch = getopt(argc, argv, "HI:LPasd:chkmnrx")) != -1)
+ while ((ch = getopt(argc, argv, "HI:LPabsd:chkmnrx")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -143,11 +143,17 @@
putenv("BLOCKSIZE=512");
hflag = 1;
break;
+ case 'b':
+ putenv("BLOCKSIZE=512");
+ bflag = 1;
+ break;
case 'k':
+ bflag = 0;
hflag = 0;
putenv("BLOCKSIZE=1024");
break;
case 'm':
+ bflag = 0;
hflag = 0;
putenv("BLOCKSIZE=1048576");
break;
@@ -213,8 +219,12 @@
argv[1] = NULL;
}
- (void) getbsize(¬used, &blocksize);
- blocksize /= 512;
+ if (!bflag) {
+ (void) getbsize(¬used, &blocksize);
+ blocksize /= 512;
+ } else {
+ blocksize=1;
+ }
rval = 0;
@@ -231,8 +241,13 @@
if (ignorep(p))
break;
- p->fts_parent->fts_bignum +=
- p->fts_bignum += p->fts_statp->st_blocks;
+ if (!bflag) {
+ p->fts_parent->fts_bignum +=
+ p->fts_bignum += p->fts_statp->st_blocks;
+ } else {
+ p->fts_parent->fts_bignum +=
+ p->fts_bignum += p->fts_statp->st_size;
+ }
if (p->fts_level <= depth) {
if (hflag) {
@@ -261,18 +276,34 @@
break;
if (listall || p->fts_level == 0) {
- if (hflag) {
- (void) prthumanval(howmany(p->fts_statp->st_blocks,
- blocksize));
- (void) printf("\t%s\n", p->fts_path);
+ if (!bflag) {
+ if (hflag) {
+ (void) prthumanval(howmany(p->fts_statp->st_blocks,
+ blocksize));
+ (void) printf("\t%s\n", p->fts_path);
+ } else {
+ (void) printf("%jd\t%s\n",
+ (intmax_t)howmany(p->fts_statp->st_blocks, blocksize),
+ p->fts_path);
+ }
} else {
- (void) printf("%jd\t%s\n",
- (intmax_t)howmany(p->fts_statp->st_blocks, blocksize),
- p->fts_path);
+ if (hflag) {
+ (void) prthumanval(howmany(p->fts_statp->st_size,
+ blocksize));
+ (void) printf("\t%s\n", p->fts_path);
+ } else {
+ (void) printf("%jd\t%s\n",
+ (intmax_t)howmany(p->fts_statp->st_size, blocksize),
+ p->fts_path);
+ }
}
}
- p->fts_parent->fts_bignum += p->fts_statp->st_blocks;
+ if (!bflag) {
+ p->fts_parent->fts_bignum += p->fts_statp->st_blocks;
+ } else {
+ p->fts_parent->fts_bignum += p->fts_statp->st_size;
+ }
}
savednumber = p->fts_parent->fts_bignum;
}
@@ -443,7 +474,7 @@
usage(void)
{
(void)fprintf(stderr,
- "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
+ "usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -b | -m] [-n] [-x] [-I mask] [file ...]\n");
exit(EX_USAGE);
}
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list