From: bde@runx.oz.au (Bruce Evans)
Subject: Fixes for 1.6.24b commands [a-d]
Organization: RUNX Un*x Timeshare.  Sydney, Australia.
Date: Sat, 9 Jan 93 16:21:01 GMT

Here are some fixes and improvements for the 1.6.24b commands/*.c files.
The most important fixes are marked with a '!'.

arglist.c:
	Kludge to get _PROTOTYPE defined.  The <stdio.h> in estdio does not
	define it.  Most programs include more headers and chance to have it
	defined somewhere else.

badblocks.c:
	Don't use %d or %u to print "block_t num".  block_t is now long.

	Harmless printf format mismatches are fixed too.

cdiff.c:
	! Don't follow null pointers.

chmem.c:
	Don't abort early when the size is too large for one file.  The
	maximum now depends on the file.

	Reset errno after handling an error to try to avoid using a stale
	errno in a report about a non-system error for the next file.

	This program needs to be reformatted.

chgrp.c:
	This need not exist.  chmod.c and chgrp.c are completely independent
	but both support both chmod and chgrp using linked binaries.  chmod.c
	is now far more up to date.  The only reason for keeping both files
	is that they have different copyrights.

	No changes here for this file.

cp.c, cpdir.c:
	cpdir.c should not exist.  The cpdir binary is supposed to be a link
	to the cp binary.

	cpdir.c was the most up to date.  It still had a flag test back to
	front so that "cp /dev/null foo" tried to create the device.  cp.c
	was missing support for symlinks and some fixes for comments.

	After patching cpdir.c, mv it to cp.c to delete the old cp.c, and
	arrange for fixbin.sh to link /bin/cp to /bin/cpdir.

	The prototypes are from cp.c; pretty had munged them.

	Avoid warnings about if (foo = bar).

	! The correct treatment of rflag and rrflag is from cp.c.

	! Fix cp -p to change the modes properly when run as root.

cron.c:
	Don't include <stdlib.h> twice.  The second one would undo
	the kludge of including <stdio.h> last to get NULL redefined.

diskcheck.c:
	Don't depend on ERROR being defined in <errno.h>.

	Use short for pat1, pat2 and testb arrays in all cases to avoid
	ifdefs.

	Use off_t for file positions.  off_t is now unsigned long, so
	using plain long tends to cause compiler warnings.

	Flush output after printf without a newline.

	Make purging work (incredibly slowly) on my system.  When there
	are 2000 buffers it is painful to read that many for every block
	tested.

diskcheck.c:
	Avoid the usual long vs off_t type mismatches.

	! Check the value returned by opendir().  opendir() often fails
	due to lack of memory.

	! Don't scanf into a uid_t using %d format.  uid_t is unsigned
	short so it might be shorter than an int.

	! Don't continue after malloc fails.

du.c:
	Cleaned up.

	Improved counting and reporting.  See comments in the file for
	details.  Still doesn't know about indirect blocks or zero blocks.

I will post changes to these files over the next few days:

    find.c fsck.c fsck2.c getlf.c getty.c hyphenate.c kill.c leave.c
    login.c ls.c man.c mkfs.c mv.c ps.c roff.c sort.c stty.c su.c
    swapfs.c term.c test.c time.c uname.c users.c
---
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  arglist.c.cd badblocks.c.cd cdiff.c.cd chmem.c.cd
#   cpdir.c.cd cron.c.cd diskcheck.c.cd diskusage.c.cd du.c.cd
# Wrapped by src@besplex on Sun Jan 10 02:41:30 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'arglist.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'arglist.c.cd'\"
else
echo shar: Extracting \"'arglist.c.cd'\" \(495 characters\)
sed "s/^X//" >'arglist.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/arglist.c  crc=02747    233	Sun Jan  3 12:44:57 1993
X--- arglist.c  crc=02807    311	Sun Jan  3 15:14:28 1993
X***************
X*** 1,7 ****
X  #include <stdio.h>
X  
X  _PROTOTYPE(int main, (int argc, char **argv));
X  
X! main(argc, argv)
X  int argc;
X  char *argv[];
X--- 1,10 ----
X+ /* XXX - using _PROTOTYPE destroys STDC conformance */
X+ #include <ansi.h>
X+ 
X  #include <stdio.h>
X  
X  _PROTOTYPE(int main, (int argc, char **argv));
X  
X! int main(argc, argv)
X  int argc;
X  char *argv[];
END_OF_FILE
if test 495 -ne `wc -c <'arglist.c.cd'`; then
    echo shar: \"'arglist.c.cd'\" unpacked with wrong size!
fi
# end of 'arglist.c.cd'
fi
if test -f 'badblocks.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'badblocks.c.cd'\"
else
echo shar: Extracting \"'badblocks.c.cd'\" \(2575 characters\)
sed "s/^X//" >'badblocks.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/badblocks.c  crc=08766  15365	Sun Jan  3 12:48:28 1993
X--- badblocks.c  crc=62664  15472	Sun Jan  3 16:51:17 1993
X***************
X*** 124,128 ****
X  struct stat stat_buf;
X  struct super_block *sp;
X! int inodes_per_block, inode_size;
X  int v1fs;			/* TRUE for V1 file system, FALSE for V2 */
X  
X--- 124,129 ----
X  struct stat stat_buf;
X  struct super_block *sp;
X! int inodes_per_block;
X! size_t inode_size;
X  int v1fs;			/* TRUE for V1 file system, FALSE for V2 */
X  
X***************
X*** 148,154 ****
X  	rwd = write(fd, (char *) sp, SUPER_SIZE);
X    if (rwd != SUPER_SIZE) {	/* ok ? */
X! 	printf("Bad %s in get_super() (should be %d is %d)\n",
X  	       flag == READ ? "read" : "write",
X! 	       SUPER_SIZE, rwd);
X  	done(DIR_CREATED);
X    }
X--- 149,155 ----
X  	rwd = write(fd, (char *) sp, SUPER_SIZE);
X    if (rwd != SUPER_SIZE) {	/* ok ? */
X! 	printf("Bad %s in get_super() (should be %u is %d)\n",
X  	       flag == READ ? "read" : "write",
X! 	       (unsigned) SUPER_SIZE, rwd);
X  	done(DIR_CREATED);
X    }
X***************
X*** 168,172 ****
X    } else {
X  	/* Neither V1 nor V2. */
X! 	printf("Bad magic number in super_block (0x%x)\n", sp->s_magic);
X  	done(DIR_CREATED);
X    }
X--- 169,174 ----
X    } else {
X  	/* Neither V1 nor V2. */
X! 	printf("Bad magic number in super_block (0x%x)\n",
X! 	       (unsigned) sp->s_magic);
X  	done(DIR_CREATED);
X    }
X***************
X*** 461,465 ****
X    int i;
X  
X!   for (i = 0; i < blk_cnt; i++) printf("Block[%d] = %ld\n", i, block[i]);
X  }
X  
X--- 463,468 ----
X    int i;
X  
X!   for (i = 0; i < blk_cnt; i++)
X! 	printf("Block[%d] = %lu\n", i, (unsigned long) block[i]);
X  }
X  
X***************
X*** 488,492 ****
X  
X    if (blk_is_used(num)) {
X! 	printf("Duplicate block (%d) given\n", num);
X  	return NOT_OK;
X    }
X--- 491,495 ----
X  
X    if (blk_is_used(num)) {
X! 	printf("Duplicate block (%lu) given\n", (unsigned long) num);
X  	return NOT_OK;
X    }
X***************
X*** 521,525 ****
X  	return OK;
X    else {
X! 	printf("Bad number %d. ", num);
X  	printf("This zone (block) is marked in bitmap\n");
X  	return NOT_OK;
X--- 524,528 ----
X  	return OK;
X    else {
X! 	printf("Bad number %lu. ", (unsigned long) num);
X  	printf("This zone (block) is marked in bitmap\n");
X  	return NOT_OK;
X***************
X*** 567,571 ****
X  	return;
X    }
X!   printf("Bit map indicates that block %u is in use. Not marked.\n", num);
X  /*  done(DIR_CREATED); */
X    return;
X--- 570,575 ----
X  	return;
X    }
X!   printf("Bit map indicates that block %lu is in use. Not marked.\n",
X! 	 (unsigned long) num);
X  /*  done(DIR_CREATED); */
X    return;
END_OF_FILE
if test 2575 -ne `wc -c <'badblocks.c.cd'`; then
    echo shar: \"'badblocks.c.cd'\" unpacked with wrong size!
fi
# end of 'badblocks.c.cd'
fi
if test -f 'cdiff.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cdiff.c.cd'\"
else
echo shar: Extracting \"'cdiff.c.cd'\" \(724 characters\)
sed "s/^X//" >'cdiff.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/cdiff.c  crc=27806   7109	Sun Jan  3 12:48:30 1993
X--- cdiff.c  crc=32541   7107	Mon Jan  4 15:39:37 1993
X***************
X*** 187,191 ****
X  		for (i = oldbeg; i <= oldmax; i++) {
X  			line = getold(i);
X! 			if (!*line) {
X  				oldend = oldmax = i - 1;
X  				break;
X--- 187,191 ----
X  		for (i = oldbeg; i <= oldmax; i++) {
X  			line = getold(i);
X! 			if (!line) {
X  				oldend = oldmax = i - 1;
X  				break;
X***************
X*** 210,214 ****
X  		for (i = newbeg; i <= newmax; i++) {
X  			line = getnew(i);
X! 			if (!*line) {
X  				newend = newmax = i - 1;
X  				break;
X--- 210,214 ----
X  		for (i = newbeg; i <= newmax; i++) {
X  			line = getnew(i);
X! 			if (!line) {
X  				newend = newmax = i - 1;
X  				break;
END_OF_FILE
if test 724 -ne `wc -c <'cdiff.c.cd'`; then
    echo shar: \"'cdiff.c.cd'\" unpacked with wrong size!
fi
# end of 'cdiff.c.cd'
fi
if test -f 'chmem.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chmem.c.cd'\"
else
echo shar: Extracting \"'chmem.c.cd'\" \(455 characters\)
sed "s/^X//" >'chmem.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/chmem.c  crc=23511   3335	Sun Jan  3 12:48:31 1993
X--- chmem.c  crc=56602   3358	Tue Jan  5 02:35:32 1993
X***************
X*** 97,102 ****
X  	if (lsize > max)
X  	{
X!   		error(p + 1, "is too large");
X! 		exit(1);
X  	}
X  	
X--- 97,102 ----
X  	if (lsize > max)
X  	{
X!   		error("size is too large for", *argv);
X! 		continue;
X  	}
X  	
X***************
X*** 138,141 ****
X--- 138,142 ----
X    else
X  	fprintf(stderr, "%s\n", s2);
X+   errno = 0;
X  }
X  
END_OF_FILE
if test 455 -ne `wc -c <'chmem.c.cd'`; then
    echo shar: \"'chmem.c.cd'\" unpacked with wrong size!
fi
# end of 'chmem.c.cd'
fi
if test -f 'cpdir.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cpdir.c.cd'\"
else
echo shar: Extracting \"'cpdir.c.cd'\" \(4076 characters\)
sed "s/^X//" >'cpdir.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/cpdir.c  crc=01274  12817	Sun Jan  3 12:48:33 1993
X--- cpdir.c  crc=09981  12849	Sat Jan  9 01:21:19 1993
X***************
X*** 70,76 ****
X  _PROTOTYPE(void doing, (char *what, char *with, char *on));
X  _PROTOTYPE(void do_close, (void));
X! _PROTOTYPE(void similar, (struct stat * sp));
X! _PROTOTYPE(void do_cpfile, (int new, struct stat * st));
X! _PROTOTYPE(void do_cpdir, (int new, struct stat * oldmode, TREE * dotdot));
X  _PROTOTYPE(int do_cp, (char *source));
X  _PROTOTYPE(void usage, (void));
X--- 70,76 ----
X  _PROTOTYPE(void doing, (char *what, char *with, char *on));
X  _PROTOTYPE(void do_close, (void));
X! _PROTOTYPE(void similar, (struct stat *sp));
X! _PROTOTYPE(void do_cpfile, (int new, struct stat *st));
X! _PROTOTYPE(void do_cpdir, (int new, struct stat *oldmode, TREE *dotdot));
X  _PROTOTYPE(int do_cp, (char *source));
X  _PROTOTYPE(void usage, (void));
X***************
X*** 92,96 ****
X    struct stat st;
X  
X!   if (s = strrchr(*argv, '/'))
X  	s++;
X    else
X--- 92,96 ----
X    struct stat st;
X  
X!   if ((s = strrchr(*argv, '/')) != NULL)
X  	s++;
X    else
X***************
X*** 99,102 ****
X--- 99,103 ----
X  	cflag = 1;
X  	rflag = 1;
X+ 	rrflag = 1;
X    }
X    opterr = 0;
X***************
X*** 115,121 ****
X  	    case 'p':	pflag = 1;	break;
X  	    case 'v':	vflag = 1;	break;
X! 	    case 'r':
X! 		if (!cflag) rrflag = 1;
X! 	    case 'R':	rflag = 1;	break;
X  	    default:	usage();
X  	}
X--- 116,121 ----
X  	    case 'p':	pflag = 1;	break;
X  	    case 'v':	vflag = 1;	break;
X! 	    case 'R':	rrflag = 1;
X! 	    case 'r':	rflag = 1;	break;
X  	    default:	usage();
X  	}
X***************
X*** 225,229 ****
X  	errors = 1;
X    }
X!   if (userid || chown(dst_path, sp->st_uid, sp->st_gid))
X  	sp->st_mode &= ALL_MODES;
X    if (chmod(dst_path, sp->st_mode)) {
X--- 225,229 ----
X  	errors = 1;
X    }
X!   if (chown(dst_path, sp->st_uid, sp->st_gid) || userid != 0)
X  	sp->st_mode &= ALL_MODES;
X    if (chmod(dst_path, sp->st_mode)) {
X***************
X*** 288,292 ****
X  	if ((linkp = (LINK *) malloc(sizeof(LINK))) == (LINK *) 0)
X  		perror(dst_path);
X! 	else if ((linkp->path = (char *) malloc(strlen(dst_path) + 1)) == NONE) {
X  		perror(dst_path);
X  		free(linkp);
X--- 288,292 ----
X  	if ((linkp = (LINK *) malloc(sizeof(LINK))) == (LINK *) 0)
X  		perror(dst_path);
X! 	else if ((linkp->path = (char *)malloc(strlen(dst_path) + 1)) == NONE){
X  		perror(dst_path);
X  		free(linkp);
X***************
X*** 303,307 ****
X        S_ISLNK(st->st_mode) ||
X  #endif
X!       !rrflag && (S_ISBLK(st->st_mode) ||
X  		S_ISCHR(st->st_mode) || S_ISFIFO(st->st_mode))) {
X  	if (!new) {
X--- 303,307 ----
X        S_ISLNK(st->st_mode) ||
X  #endif
X!       rrflag && (S_ISBLK(st->st_mode) ||
X  		S_ISCHR(st->st_mode) || S_ISFIFO(st->st_mode))) {
X  	if (!new) {
X***************
X*** 380,384 ****
X  	return;
X    }
X!   while (n = read(fd, buffer, sizeof(buffer))) {
X  	if (n < 0) {
X  		perror(src_path);
X--- 380,384 ----
X  	return;
X    }
X!   while ((n = read(fd, buffer, sizeof(buffer))) != 0) {
X  	if (n < 0) {
X  		perror(src_path);
X***************
X*** 495,499 ****
X  		    stat(src_path, &d.st)
X  #endif
X! 			) {
X  			perror(src);
X  			errors = 1;
X--- 495,499 ----
X  		    stat(src_path, &d.st)
X  #endif
X! 		   ) {
X  			perror(src);
X  			errors = 1;
X***************
X*** 502,506 ****
X  		d.pos = entp->d_off;
X  
X! 		if (new2 = stat(dst_path, &st2)) {
X  			if (S_ISDIR(d.st.st_mode)) {
X  				do_cpdir(new2, &d.st, &d);
X--- 502,506 ----
X  		d.pos = entp->d_off;
X  
X! 		if ((new2 = stat(dst_path, &st2)) != 0) {
X  			if (S_ISDIR(d.st.st_mode)) {
X  				do_cpdir(new2, &d.st, &d);
X***************
X*** 555,559 ****
X    strcpy(dst_path, dest);
X    if (dflag) {
X! 	if (s = strrchr(source, '/'))
X  		strcat(dst_path, s);
X  	else {
X--- 555,559 ----
X    strcpy(dst_path, dest);
X    if (dflag) {
X! 	if ((s = strrchr(source, '/')) != NULL)
X  		strcat(dst_path, s);
X  	else {
X***************
X*** 567,571 ****
X  		std_err(",");
X  		std_err(dst_path);
X! 		std_err(": Same files\n");
X  		return(1);
X  	}
X--- 567,571 ----
X  		std_err(",");
X  		std_err(dst_path);
X! 		std_err(": Same file\n");
X  		return(1);
X  	}
END_OF_FILE
if test 4076 -ne `wc -c <'cpdir.c.cd'`; then
    echo shar: \"'cpdir.c.cd'\" unpacked with wrong size!
fi
# end of 'cpdir.c.cd'
fi
if test -f 'cron.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cron.c.cd'\"
else
echo shar: Extracting \"'cron.c.cd'\" \(270 characters\)
sed "s/^X//" >'cron.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/cron.c  crc=57855   8539	Sun Jan  3 12:48:34 1993
X--- cron.c  crc=65530   8519	Fri Jul 12 14:59:45 1991
X***************
X*** 44,48 ****
X  #include <sys/wait.h>
X  #include <stdio.h>
X- #include <stdlib.h>
X  
X  #define CRONTAB		"/usr/lib/crontab"
X--- 44,47 ----
END_OF_FILE
if test 270 -ne `wc -c <'cron.c.cd'`; then
    echo shar: \"'cron.c.cd'\" unpacked with wrong size!
fi
# end of 'cron.c.cd'
fi
if test -f 'diskcheck.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'diskcheck.c.cd'\"
else
echo shar: Extracting \"'diskcheck.c.cd'\" \(5503 characters\)
sed "s/^X//" >'diskcheck.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/diskcheck.c  crc=55647   5309	Sun Jan  3 12:48:35 1993
X--- diskcheck.c  crc=25422   5487	Tue Jan  5 02:12:41 1993
X***************
X*** 13,30 ****
X  #include <stdio.h>
X  
X  #define OK 0
X  #define PRINTFREQ  10
X  #define N 30
X  
X  char purgebuf[BLOCK_SIZE * N];
X  char buf[BLOCK_SIZE], zero[BLOCK_SIZE];
X! 
X! /* There are some tricks used here, that only work if ints are 16 bits. */
X! #ifndef INTEL_32BITS
X! int pat1[BLOCK_SIZE / 2], pat2[BLOCK_SIZE / 2];
X! #else
X! short pat1[BLOCK_SIZE / 2], pat2[BLOCK_SIZE / 2];
X! #endif
X! 
X  int blk = -1;			/* number of the block in buf, or -1 */
X  int pfd;			/* file descriptor for purging */
X--- 13,26 ----
X  #include <stdio.h>
X  
X+ #undef ERROR			/* ERROR might be defined in <errno.h> :-( */
X+ #define ERROR (-99)
X  #define OK 0
X  #define PRINTFREQ  10
X  #define N 30
X+ #define SHORTS_PER_BLOCK (BLOCK_SIZE / sizeof(short))
X  
X  char purgebuf[BLOCK_SIZE * N];
X  char buf[BLOCK_SIZE], zero[BLOCK_SIZE];
X! short pat1[SHORTS_PER_BLOCK], pat2[SHORTS_PER_BLOCK];
X  int blk = -1;			/* number of the block in buf, or -1 */
X  int pfd;			/* file descriptor for purging */
X***************
X*** 34,42 ****
X  unsigned limit;			/* first block beyond test zone */
X  unsigned errors;		/* # errors so far */
X! unsigned ct = 0;		/* # blocks read so far */
X  int intflag;			/* set when signal seen */
X  int rawdev;			/* set when I/O done on raw device */
X- extern errno;
X- long pos;
X  char *purgefile = "/dev/ram";
X  
X--- 30,36 ----
X  unsigned limit;			/* first block beyond test zone */
X  unsigned errors;		/* # errors so far */
X! unsigned ct;			/* # blocks read so far */
X  int intflag;			/* set when signal seen */
X  int rawdev;			/* set when I/O done on raw device */
X  char *purgefile = "/dev/ram";
X  
X***************
X*** 48,52 ****
X  _PROTOTYPE(void catch, (int sig ));
X  _PROTOTYPE(void usage, (void ));
X! _PROTOTYPE(int wtest, (long pos , int pat []));
X  _PROTOTYPE(void purge_cache, (void ));
X  
X--- 42,46 ----
X  _PROTOTYPE(void catch, (int sig ));
X  _PROTOTYPE(void usage, (void ));
X! _PROTOTYPE(int wtest, (off_t pos , short *pat ));
X  _PROTOTYPE(void purge_cache, (void ));
X  
X***************
X*** 79,83 ****
X    if (limit <= initblock) usage();
X  
X!   for (i = 0; i < BLOCK_SIZE / 2; i++) {
X  	pat1[i] = i;
X  	pat2[i] = 1000 - i;
X--- 73,77 ----
X    if (limit <= initblock) usage();
X  
X!   for (i = 0; i < SHORTS_PER_BLOCK; i++) {
X  	pat1[i] = i;
X  	pat2[i] = 1000 - i;
X***************
X*** 90,94 ****
X  		if (blk == b) {
X  			/* Read ok, write failed; try to restore block. */
X! 			lseek(fd, pos, SEEK_SET);
X  			write(fd, buf, BLOCK_SIZE);
X  		}
X--- 84,88 ----
X  		if (blk == b) {
X  			/* Read ok, write failed; try to restore block. */
X! 			lseek(fd, (off_t) BLOCK_SIZE * (off_t) b, SEEK_SET);
X  			write(fd, buf, BLOCK_SIZE);
X  		}
X***************
X*** 113,120 ****
X   */
X  
X    int s;
X  
X    blk = -1;
X!   pos = (long) BLOCK_SIZE *(long) b;
X    purge_cache();
X    if (lseek(fd, pos, SEEK_SET) != pos) fatal("Cannot seek to block ", b);
X--- 107,115 ----
X   */
X  
X+   off_t pos;
X    int s;
X  
X    blk = -1;
X!   pos = (off_t) BLOCK_SIZE * (off_t) b;
X    purge_cache();
X    if (lseek(fd, pos, SEEK_SET) != pos) fatal("Cannot seek to block ", b);
X***************
X*** 156,159 ****
X--- 151,155 ----
X    printf("%8u blocks tested, %u errors detected (last block tested = %5u)\r",
X           ct, errors, curblock);
X+   fflush(stdout);
X  }
X  
X***************
X*** 191,206 ****
X  
X  int wtest(pos, pat)
X! long pos;
X! #ifndef INTEL_32BITS
X! int pat[];
X! #else
X! short pat[];
X! #endif
X  {
X! #ifndef INTEL_32BITS
X!   int testb[BLOCK_SIZE / 2];
X! #else
X!   short testb[BLOCK_SIZE / 2];
X! #endif
X    int i;
X  
X--- 187,194 ----
X  
X  int wtest(pos, pat)
X! off_t pos;
X! short *pat;
X  {
X!   short testb[SHORTS_PER_BLOCK];
X    int i;
X  
X***************
X*** 211,215 ****
X    lseek(fd, pos, SEEK_SET);
X    if (read(fd, (char *) testb, BLOCK_SIZE) != BLOCK_SIZE) return(ERROR);
X!   for (i = 0; i < BLOCK_SIZE / 2; i++)
X  	if (testb[i] != pat[i]) {
X  		printf("%d %d\n", testb[i], pat[i]);
X--- 199,203 ----
X    lseek(fd, pos, SEEK_SET);
X    if (read(fd, (char *) testb, BLOCK_SIZE) != BLOCK_SIZE) return(ERROR);
X!   for (i = 0; i < SHORTS_PER_BLOCK; i++)
X  	if (testb[i] != pat[i]) {
X  		printf("%d %d\n", testb[i], pat[i]);
X***************
X*** 227,234 ****
X    if (rawdev) return;
X    pfd = open(purgefile, O_RDONLY);
X    left = NR_BUFS;
X    while (left > 0) {
X  	count = (left < N ? left : N);
X! 	if ((r = read(pfd, purgebuf, count * BLOCK_SIZE)) != count * BLOCK_SIZE) {
X  		if (r == 0) {
X  			if (!warned) printf("WARNING: Cannot purge cache.\n");
X--- 215,231 ----
X    if (rawdev) return;
X    pfd = open(purgefile, O_RDONLY);
X+ #ifdef NR_BUFS
X    left = NR_BUFS;
X+ #else
X+   /* XXX - buffers are dynamically allocated and there are likely to be
X+    * several MB worth.  This purge is unlikely to work.  There should be
X+    * raw devices to avoid such complications.
X+    */
X+   left = 8000;
X+ #endif
X    while (left > 0) {
X  	count = (left < N ? left : N);
X! 	r = read(pfd, purgebuf, (size_t) (count * BLOCK_SIZE));
X! 	if (r != count * BLOCK_SIZE) {
X  		if (r == 0) {
X  			if (!warned) printf("WARNING: Cannot purge cache.\n");
X***************
X*** 237,241 ****
X  		}
X  		printf("ERROR: count=%d  left=%d r=%d.  ", count, left, r);
X! 		fatal("Cannot purge cache.  errno= ", errno);
X  	}
X  	left -= count;
X--- 234,238 ----
X  		}
X  		printf("ERROR: count=%d  left=%d r=%d.  ", count, left, r);
X! 		fatal("Cannot purge cache.  errno= ", (unsigned) errno);
X  	}
X  	left -= count;
END_OF_FILE
if test 5503 -ne `wc -c <'diskcheck.c.cd'`; then
    echo shar: \"'diskcheck.c.cd'\" unpacked with wrong size!
fi
# end of 'diskcheck.c.cd'
fi
if test -f 'diskusage.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'diskusage.c.cd'\"
else
echo shar: Extracting \"'diskusage.c.cd'\" \(3095 characters\)
sed "s/^X//" >'diskusage.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/diskusage.c  crc=18858  12822	Sun Jan  3 12:44:58 1993
X--- diskusage.c  crc=56940  13058	Sat Jan  9 01:57:10 1993
X***************
X*** 53,56 ****
X--- 53,57 ----
X  #include <string.h>
X  #include <dirent.h>
X+ #include <errno.h>
X  #include <limits.h>
X  #include <blocksize.h>
X***************
X*** 105,109 ****
X  _PROTOTYPE(void make_userlist, (void));
X  _PROTOTYPE(void showlist, (void));
X! _PROTOTYPE(int update_list, (Uid_t uid, long bytes));
X  _PROTOTYPE(void search_all, (char *cur_dir));
X  _PROTOTYPE(int ilist_search, (char *path));
X--- 106,110 ----
X  _PROTOTYPE(void make_userlist, (void));
X  _PROTOTYPE(void showlist, (void));
X! _PROTOTYPE(int update_list, (Uid_t uid, off_t bytes));
X  _PROTOTYPE(void search_all, (char *cur_dir));
X  _PROTOTYPE(int ilist_search, (char *path));
X***************
X*** 183,187 ****
X  int update_list(uid, bytes)	/* Increment uid's total.   */
X  Uid_t uid;			/* If uid has duplicates    */
X! long bytes;			/* will be charged to first. */
X  {
X    USEREC *curs;
X--- 184,188 ----
X  int update_list(uid, bytes)	/* Increment uid's total.   */
X  Uid_t uid;			/* If uid has duplicates    */
X! off_t bytes;			/* will be charged to first. */
X  {
X    USEREC *curs;
X***************
X*** 216,220 ****
X    }
X    dp1 = opendir(cur_dir);
X!   while (this_file = readdir(dp1)) {	/* Iterate through this directory */
X  	if (strcmp(this_file->d_name, ".") &&
X  	    strcmp(this_file->d_name, "..")) {
X--- 217,226 ----
X    }
X    dp1 = opendir(cur_dir);
X!   if (dp1 == NULL) {
X! 	fprintf(stderr, "Opendir returned NULL.  (%s).\n", strerror(errno));
X! 	exit(EXIT_FAILURE);
X!   }
X!   while ((this_file = readdir(dp1)) != NULL) {
X! 	/* Iterate through this directory */
X  	if (strcmp(this_file->d_name, ".") &&
X  	    strcmp(this_file->d_name, "..")) {
X***************
X*** 295,298 ****
X--- 301,305 ----
X    uid_t m_uid;
X    long m_blocks;
X+   unsigned scan_uid;
X    progname = argv[0];
X    argc--;
X***************
X*** 378,382 ****
X  		}
X  		while (fgets(line, PLENGTH, dskusg)) {
X! 			sscanf(line, "%d%s%ld", &m_uid, mf1, &m_blocks);
X  			if (!exists(list_head, m_uid)) {
X  				m_rec = (USEREC *) malloc(sizeof(USEREC));
X--- 385,390 ----
X  		}
X  		while (fgets(line, PLENGTH, dskusg)) {
X! 			sscanf(line, "%u%s%ld", &scan_uid, mf1, &m_blocks);
X! 			m_uid = scan_uid;
X  			if (!exists(list_head, m_uid)) {
X  				m_rec = (USEREC *) malloc(sizeof(USEREC));
X***************
X*** 389,393 ****
X  				insert(&list_head, m_rec);
X  			}	/* if !exist */
X! 			update_list((Uid_t) m_uid, BLOCK_SIZE * m_blocks);
X  		}		/* while fgets */
X  		fclose(dskusg);
X--- 397,402 ----
X  				insert(&list_head, m_rec);
X  			}	/* if !exist */
X! 			update_list((Uid_t) m_uid,
X! 				    (off_t) BLOCK_SIZE * m_blocks);
X  		}		/* while fgets */
X  		fclose(dskusg);
X***************
X*** 464,469 ****
X  void *ptr;
X  {
X!   if (ptr == NULL)
X  	fprintf(stderr, 
X  		  "Malloc returned NULL.  Use chmem to allocate more stack\n");
X  }
X--- 473,480 ----
X  void *ptr;
X  {
X!   if (ptr == NULL) {
X  	fprintf(stderr, 
X  		  "Malloc returned NULL.  Use chmem to allocate more stack\n");
X+ 	exit(EXIT_FAILURE);
X+   }
X  }
END_OF_FILE
if test 3095 -ne `wc -c <'diskusage.c.cd'`; then
    echo shar: \"'diskusage.c.cd'\" unpacked with wrong size!
fi
# end of 'diskusage.c.cd'
fi
if test -f 'du.c.cd' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'du.c.cd'\"
else
echo shar: Extracting \"'du.c.cd'\" \(6647 characters\)
sed "s/^X//" >'du.c.cd' <<'END_OF_FILE'
X*** 1.6.24b/du.c  crc=10307   4442	Sun Jan  3 12:48:36 1993
X--- du.c  crc=17350   4765	Mon Jan  4 02:23:13 1993
X***************
X*** 6,10 ****
X   *			1.3	31 Mar 89	nick@nswitgould.oz
X   *			1.4	22 Feb 90	meulenbr@cst.prl.philips.nl
X!  *			1.5	01 Oct 92	kjb@cs.vu.nl
X   *
X   *	Copyright 1987, Joypace Ltd., London UK. All rights reserved.
X--- 6,12 ----
X   *			1.3	31 Mar 89	nick@nswitgould.oz
X   *			1.4	22 Feb 90	meulenbr@cst.prl.philips.nl
X!  *			1.5	09 Jul 91	hp@vmars.tuwien.ac.at
X!  *			1.6	01 Oct 92	kjb@cs.vu.nl
X!  *			1.7	04 Jan 93	bde
X   *
X   *	Copyright 1987, Joypace Ltd., London UK. All rights reserved.
X***************
X*** 17,22 ****
X   *  1.3:	Add [-l levels] option to restrict printing.
X   *  1.4:	Added processing of multiple arguments
X!  *  1.5:	Use readdir
X!  *
X   */
X  
X--- 19,31 ----
X   *  1.3:	Add [-l levels] option to restrict printing.
X   *  1.4:	Added processing of multiple arguments
X!  *  1.5:	Fixed processing of multiple arguments. General cleanup.
X!  *  1.6:	Use readdir
X!  *  1.7:	Merged 1.5 and 1.6.
X!  *		Print totals even for non-dirs at top level.
X!  *		Count blocks for each dir before printing total for the dir.
X!  *		Count blocks for all non-special files.
X!  *		Don't clutter link buffer with directories.
X!  *  TODO	Report all errors.  Count indirect blocks.  Don't forget
X!  *		links.
X   */
X  
X***************
X*** 24,29 ****
X--- 33,41 ----
X  #include <sys/types.h>
X  #include <sys/stat.h>
X+ #include <blocksize.h>
X  #include <fcntl.h>
X  #include <blocksize.h>
X+ #include <errno.h>
X+ #include <limits.h>
X  #include <stdlib.h>
X  #include <string.h>
X***************
X*** 35,46 ****
X  extern int optind;
X  
X! char *prog;			/* program name */
X! char *optstr = "asl:";		/* -a and -s arguments */
X! int silent = 0;			/* silent mode */
X! int all = 0;			/* all directory entries mode */
X! char *startdir = ".";		/* starting from here */
X! int levels = 255;		/* # of directory levels to print */
X! 
X! #define	LINELEN 256
X  
X  #ifdef S_IFLNK
X--- 47,52 ----
X  extern int optind;
X  
X! #define	LINELEN		256
X! #define	MAXALREADY	512
X  
X  #ifdef S_IFLNK
X***************
X*** 50,80 ****
X  #endif
X  
X! typedef struct _alstr {
X    int al_dev;
X    ino_t al_inum;
X  } ALREADY;
X  
X- #define	MAXALREADY	50
X- ALREADY already[MAXALREADY];
X- int alc = 0;
X- 
X  _PROTOTYPE(int main, (int argc, char **argv));
X- _PROTOTYPE(char *myindex, (char *s, int c));
X  _PROTOTYPE(int makedname, (char *d, char *f, char *out, int outlen));
X  _PROTOTYPE(int done, (int dev, Ino_t inum));
X  _PROTOTYPE(long dodir, (char *d, int thislev));
X  
X! /*
X!  *	myindex - stop the scanf bug
X!  */
X! char *myindex(s, c)
X! register char *s;
X! register char c;
X! {
X!   for (; *s; s++)
X! 	if (*s == c) return(s);
X!   return(NULL);
X! }
X  
X  /*
X   *	makedname - make the pathname from the directory name, and the
X--- 56,79 ----
X  #endif
X  
X! typedef struct {
X    int al_dev;
X    ino_t al_inum;
X  } ALREADY;
X  
X  _PROTOTYPE(int main, (int argc, char **argv));
X  _PROTOTYPE(int makedname, (char *d, char *f, char *out, int outlen));
X  _PROTOTYPE(int done, (int dev, Ino_t inum));
X  _PROTOTYPE(long dodir, (char *d, int thislev));
X  
X! char *prog;			/* program name */
X! char *optstr = "asl:";		/* -a and -s arguments */
X! int silent = 0;			/* silent mode */
X! int all = 0;			/* all directory entries mode */
X! char *startdir = ".";		/* starting from here */
X! int levels = INT_MAX;		/* # of directory levels to print */
X! ALREADY already[MAXALREADY];
X! int alc;
X  
X+ 
X  /*
X   *	makedname - make the pathname from the directory name, and the
X***************
X*** 91,97 ****
X    int length;
X  
X-   /* Find length of directory entry */
X    length = strlen(f);
X- 
X    if (strlen(d) + length + 2 > outlen) return(0);
X    for (cp = out; *d; *cp++ = *d++);
X--- 90,94 ----
X***************
X*** 134,179 ****
X  int thislev;
X  {
X    struct stat s;
X!   long total = 0L;
X    char dent[LINELEN];
X    DIR *dp;
X    struct dirent *entry;
X  
X!   if ((dp = opendir(d)) == NULL) return(0L);
X!   while ((entry = readdir(dp)) != NULL) {
X! 	if (strcmp(entry->d_name, ".") == 0 ||
X! 	    strcmp(entry->d_name, "..") == 0)
X! 		continue;
X! 	if (!makedname(d, entry->d_name, dent, sizeof(dent))) continue;
X! 	if (LSTAT(dent, &s) < 0) continue;
X! 	if (s.st_nlink > 1 && done(s.st_dev, s.st_ino)) continue;
X! 	if ((s.st_mode & S_IFMT) == S_IFDIR)
X  		total += dodir(dent, thislev - 1);
X- 	switch (s.st_mode & S_IFMT) {
X- 	    case S_IFREG:
X- 	    case S_IFDIR:
X- 		total += (s.st_size + BLOCK_SIZE - 1) / BLOCK_SIZE;
X- 		break;
X  	}
X! 	if (all && (s.st_mode & S_IFMT) != S_IFDIR)
X! 		if (thislev > 0)/* this is correct - file in subdir */
X! 			printf("%ld\t%s\n",
X! 			       (s.st_size + BLOCK_SIZE - 1) / BLOCK_SIZE, dent);
X    }
X!   closedir(dp);
X!   if (!silent)
X! 	if (thislev >= 0)	/* this is correct - subdir itself */
X! 		printf("%ld\t%s\n", total, d);
X    return(total);
X  }
X  
X- /*
X-  *	OK, here goes...
X-  */
X  int main(argc, argv)
X  int argc;
X  char **argv;
X  {
X-   long tot;
X    int c;
X  
X--- 131,182 ----
X  int thislev;
X  {
X+   int maybe_print;
X    struct stat s;
X!   long total;
X    char dent[LINELEN];
X    DIR *dp;
X    struct dirent *entry;
X  
X!   if (LSTAT(d, &s) < 0) {
X! 	fprintf(stderr,
X! 		"%s: %s: %s\n", prog, d, strerror(errno));
X!     	return 0L;
X!   }
X!   total = (s.st_size + (BLOCK_SIZE - 1)) / BLOCK_SIZE;
X!   switch (s.st_mode & S_IFMT) {
X!     case S_IFDIR:
X! 	/* Directories should not be linked except to "." and "..", so this
X! 	 * directory should not already have been done.
X! 	 */
X! 	maybe_print = !silent;
X! 	if ((dp = opendir(d)) == NULL) break;
X! 	while ((entry = readdir(dp)) != NULL) {
X! 		if (strcmp(entry->d_name, ".") == 0 ||
X! 		    strcmp(entry->d_name, "..") == 0)
X! 			continue;
X! 		if (!makedname(d, entry->d_name, dent, sizeof(dent))) continue;
X  		total += dodir(dent, thislev - 1);
X  	}
X! 	closedir(dp);
X! 	break;
X!     case S_IFBLK:
X!     case S_IFCHR:
X! 	/* st_size for special files is not related to blocks used. */
X! 	total = 0;
X! 	/* Fall through. */
X!     default:
X! 	if (s.st_nlink > 1 && done(s.st_dev, s.st_ino)) return 0L;
X! 	maybe_print = all;
X! 	break;
X    }
X!   if (thislev >= levels || (maybe_print && thislev >= 0))
X! 	printf("%ld\t%s\n", total, d);
X    return(total);
X  }
X  
X  int main(argc, argv)
X  int argc;
X  char **argv;
X  {
X    int c;
X  
X***************
X*** 190,195 ****
X    do {
X  	if (optind < argc) startdir = argv[optind++];
X! 	tot = dodir(startdir, levels);
X! 	if (silent) printf("%ld\t%s\n", tot, startdir);
X    } while (optind < argc);
X    return(0);
X--- 193,198 ----
X    do {
X  	if (optind < argc) startdir = argv[optind++];
X! 	alc = 0;
X! 	(void) dodir(startdir, levels);
X    } while (optind < argc);
X    return(0);
END_OF_FILE
if test 6647 -ne `wc -c <'du.c.cd'`; then
    echo shar: \"'du.c.cd'\" unpacked with wrong size!
fi
# end of 'du.c.cd'
fi
echo shar: End of shell archive.
exit 0
-- 
Bruce Evans  (bde@runx.oz.au)
Newsgroups: comp.os.minix