From: Erik van der Kouwe Date: Thu, 10 Jun 2010 11:14:04 +0000 (+0000) Subject: Remove dependency of release.sh on bc, du option to give overhead totals X-Git-Tag: v3.1.8~460 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.named-checkzone.html?a=commitdiff_plain;h=65764218f75795d200a2e6984cb40586ae1c76dd;p=minix.git Remove dependency of release.sh on bc, du option to give overhead totals --- diff --git a/commands/du/Makefile b/commands/du/Makefile index a37f2ea57..4f0acfabb 100644 --- a/commands/du/Makefile +++ b/commands/du/Makefile @@ -1,4 +1,5 @@ PROG= du +CPPFLAGS+= -I${MINIXSRCDIR}/servers MAN= .include diff --git a/commands/du/du.c b/commands/du/du.c index ee3e136b6..64c9a8410 100644 --- a/commands/du/du.c +++ b/commands/du/du.c @@ -46,6 +46,8 @@ #include #include +#include "mfs/const.h" + extern char *optarg; extern int optind; @@ -71,10 +73,11 @@ _PROTOTYPE(int done, (dev_t dev, ino_t inum, nlink_t nlink)); _PROTOTYPE(long dodir, (char *d, int thislev, dev_t dev)); char *prog; /* program name */ -char *optstr = "asxdl:"; /* options */ +char *optstr = "aFsxdl:"; /* options */ int silent = 0; /* silent mode */ int all = 0; /* all directory entries mode */ int crosschk = 0; /* do not cross device boundaries mode */ +int fsoverhead = 0; /* include FS overhead */ char *startdir = "."; /* starting from here */ int levels = 20000; /* # of directory levels to print */ ALREADY *already[NR_ALREADY]; @@ -107,6 +110,8 @@ int done(dev_t dev, ino_t inum, nlink_t nlink) { register ALREADY **pap, *ap; + if (fsoverhead) return 0; + pap = &already[(unsigned) inum % NR_ALREADY]; while ((ap = *pap) != NULL) { if (ap->al_inum == inum && ap->al_dev == dev) { @@ -164,7 +169,8 @@ long dodir(char *d, int thislev, dev_t dev) { int maybe_print; struct stat s; - long total_kb; + long indir_blocks, indir2_blocks, indir_per_block; + long total_blocks, total_kb; char dent[LINELEN]; DIR *dp; struct dirent *entry; @@ -183,7 +189,16 @@ long dodir(char *d, int thislev, dev_t dev) prog, d, block_size); return 0L; } - total_kb = ((s.st_size + (block_size - 1)) / block_size) * block_size / 1024; + total_blocks = (s.st_size + (block_size - 1)) / block_size; + if (fsoverhead) { + /* file system overhead: indirect blocks */ + indir_per_block = block_size / sizeof(zone_t); + indir_blocks = (total_blocks - V2_NR_DZONES) / indir_per_block; + total_blocks += indir_blocks; + indir2_blocks = (indir_blocks - 1) / (indir_per_block * indir_per_block); + total_blocks += indir2_blocks; + } + total_kb = total_blocks * block_size / 1024; switch (s.st_mode & S_IFMT) { case S_IFDIR: /* Directories should not be linked except to "." and "..", so this @@ -228,10 +243,11 @@ char **argv; case 's': silent = 1; break; case 'x': case 'd': crosschk = 1; break; + case 'F': fsoverhead = 1; break; case 'l': levels = atoi(optarg); break; default: fprintf(stderr, - "Usage: %s [-asx] [-l levels] [startdir]\n", prog); + "Usage: %s [-asxF] [-l levels] [startdir]\n", prog); exit(1); } do { diff --git a/man/man1/du.1 b/man/man1/du.1 index 217d4a6d7..9bd10399c 100644 --- a/man/man1/du.1 +++ b/man/man1/du.1 @@ -16,6 +16,7 @@ du \- print disk usage .. .SH OPTIONS .FL "\-a" "Give usage for all files" +.FL "\-F" "Include filesystem overhead for indirect blocks" .FL "\-l" "List up to \fIn\fR levels of subdirectories" .FL "\-d" "Do not cross file system boundaries" .FL "\-s" "Summary only" diff --git a/tools/release.sh b/tools/release.sh index ca3441f95..01843949a 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -122,18 +122,11 @@ fitfs() inodes=`find $path | egrep -v ^$path/usr | wc -l` inodes="`expr $inodes + $extra_inodes`" - # Determine number of data zones using bc formula to transform file size in zone count - # s - file size - # d - number of direct blocks - # i - number of indirect blocks - # j - number of double indirect blocks - dir=7 - indir="`expr $BS / 4`" - indir2="`expr $indir \* $indir`" - formula="s=\\0;d=(s+$BS-1)/$BS;i=(d-$dir+$indir-1)/$indir;j=(i-1+$indir2-1)/$indir2;d+i+j" - zones=`( find $path | egrep -v ^$path/usr | xargs lstat -size | egrep '^[0-9]+$' | sed -r "s|.+|$formula|" | bc | tr ' -' +; echo 0 ) | bc` - zones="`expr $zones + $extra_zones`" + # Determine number of data zones + zonekbs=`du -Fs $path | cut -d' ' -f1` + zonekbsignore=0 + [ ! -d $path/usr ] || zonekbsignore=`du -Fs $path/usr | cut -d" " -f1` + zones="`expr \( $zonekbs - $zonekbsignore \) / \( $BS / 1024 \) + $extra_zones`" # Determine file system size BSBITS="`expr $BS \* 8`"