[comp.os.minix] Patch to 1.5.10 du - one out with the block count

cagney@cs.adelaide.edu.au (04/16/91)

Below is a patch to minix du. It seems to be getting the size of files
out by one (unless that's what it should do :-). The problem is best seen if
you use du on a file with exactly n*BLOCK_SIZE bytes in it.
eg for a file with 0 bytes

	old equation gave
		(0 + BLOCK_SIZE) / BLOCK_SIZE = 1 block
	new equation gives
		(0 + BLOCK_SIZE - 1) / BLOCK_SIZE = 0 blocks

					Noid


cagney@berlioz% diff -c du.c du.c.orig
*** du.c        Tue Apr 16 14:32:27 1991
--- du.c.orig   Tue Apr 16 14:32:04 1991
***************
*** 193,199 ****
        switch (s.st_mode & S_IFMT) {
            case S_IFREG:
            case S_IFDIR:
!               total += (s.st_size + BLOCK_SIZE - 1) / BLOCK_SIZE;
                break;
        }
        if (all && (s.st_mode & S_IFMT) != S_IFDIR)
--- 193,199 ----
        switch (s.st_mode & S_IFMT) {
            case S_IFREG:
            case S_IFDIR:
!               total += (s.st_size + BLOCK_SIZE) / BLOCK_SIZE;
                break;
        }
        if (all && (s.st_mode & S_IFMT) != S_IFDIR)

PATZEL@rzmain.rz.uni-ulm.de (Patzel Martin) (04/17/91)

In <2867@sirius.ucs.adelaide.edu.au> cagney@cs.adelaide.edu.au writes:

> Below is a patch to minix du. It seems to be getting the size of files
> out by one (unless that's what it should do :-). The problem is best seen if

du has more problems with counting blocks. It seems that du
doesn't count single and double indirect blocks, too.

Martin