blarson@skat.usc.edu (Bob Larson) (05/22/89)
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
# "End of shell archive."
# Contents: freeb.doc Makefile freeb.c lcldrv.h
# Wrapped by Somebody@blars on Sun May 21 19:53:44 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'freeb.doc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'freeb.doc'\"
else
echo shar: Extracting \"'freeb.doc'\" \(306 characters\)
sed "s/^X//" >'freeb.doc' <<'END_OF_FILE'
XFreeb is a superset of the os9 command Free.
X
XUse:
X
X freeb [options] [disk] [options]
X
X
XOptions:
X
X -a List sector and size of each free block.
X
X -t List number of free block of each size are on the disk.
X
X -h Suppress normal disk name and size header.
X
X -s Suppress total of free blocks.
X
X -? List options
END_OF_FILE
if test 306 -ne `wc -c <'freeb.doc'`; then
echo shar: \"'freeb.doc'\" unpacked with wrong size!
fi
# end of 'freeb.doc'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(108 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS = -t=/r0
XLFLAGS = -i -bg
X
Xfreeb: freeb.r
X cc $(LFLAGS) -f=freeb freeb.r
X
Xfreeb.r: freeb.c lcldrv.h
X
END_OF_FILE
if test 108 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'freeb.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'freeb.c'\"
else
echo shar: Extracting \"'freeb.c'\" \(3988 characters\)
sed "s/^X//" >'freeb.c' <<'END_OF_FILE'
X/* Freeb: list free blocks on os9 disk */
X/* by Robert A. Larson */
X/* Public domain version: 5/21/89 */
X/* expect the usual problems of missing header files and _gs routines
X * if you try porting this to os9/6809.
X */
X
X#include <stdio.h>
X#include <modes.h>
X#include <rbf.h>
X
Xstatic struct sect0std sect0;
Xstatic struct sect0boot sect0b;
Xstatic unsigned long freecount[256];
Xstatic struct biglist {
X struct biglist *next;
X unsigned long size;
X unsigned long count;
X} *blp;
X
X/* options, -1 for default on, 0 for default off */
Xstatic char all = 0;
Xstatic char header = -1;
Xstatic char table = 0;
Xstatic char sum = -1;
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X register unsigned char *bp;
X register unsigned t;
X register int c;
X register unsigned s, b;
X register int fp;
X char devat[38];
X unsigned char buf[256];
X char *dp = (char *)NULL;
X
X for(s=1; s < argc; s++) {
X if(argv[s][0]=='-') {
X while(*++argv[s]) {
X switch(*argv[s]) {
X case 'a':
X all++;
X break;
X case 'h':
X header++;
X break;
X case 's':
X sum++;
X break;
X case 't':
X table++;
X break;
X case '?':
X default:
X printf("Usage:\n freeb [-a] [-h] [-s] [-t] [device]\n");
X exit(*argv[s] != '?');
X }
X }
X } else {
X if(dp != NULL) {
X fprintf(stderr, "To many devices specified\n");
X exit(1);
X }
X dp = argv[s];
X }
X }
X if(dp==NULL) {
X if((s = open(".", S_IFDIR)) == -1) {
X fprintf(stderr, "Cannot open \".\"");
X exit(1);
X }
X _gs_devn(s, dp = (char *)buf);
X close(s);
X }
X if(dp[0]=='/') dp++;
X devat[0] = '/';
X strcpy(&devat[1], dp);
X strcat(devat, "@");
X if((fp = open(devat, S_IREAD)) < 0) {
X fprintf(stderr, "Could not open '%s'\n", devat);
X exit(1);
X }
X if(read(fp, (char *)§0, sizeof sect0) != sizeof sect0) {
X fprintf(stderr, "Could not read sect0\n");
X exit(1);
X }
X if(header) {
X if((lseek(fp, (long)0x14, 0) < 0) ||
X read(fp, (char *)§0b, sizeof sect0b) != sizeof sect0b) {
X fprintf(stderr, "Could not read sect0b\n");
X exit(1);
X }
X printf("Disk \"%s\" Created %2d/%02d/%02d %2d:%02d\n",
X sect0b.dd_name, sect0b.dd_date[1], sect0b.dd_date[2],
X sect0b.dd_date[0], sect0b.dd_date[3], sect0b.dd_date[4]);
X printf("%d total sectors (%d sector clusters)\n",
X (sect0.dd_map << 3) * sect0.dd_bit, sect0.dd_bit);
X }
X if(lseek(fp, (long)256, 0) < 0) {
X fprintf(stderr, "Could not lseek to sector 1\n");
X exit(1);
X }
X s = 0, b = 0;
X for(;;) {
X if(read(fp, buf, sizeof buf) <= 0) break;
X bp = buf;
X while(bp < &buf[sizeof buf]) {
X t = *bp;
X for(c = 0; c++ < 8; t <<= 1) {
X if(t & 0x80) {
X if(s) {
X freesect((b << 3) + c - s - 1, s);
X s = 0;
X }
X } else s++;
X }
X if(++b == sect0.dd_map) goto done;
X bp++;
X }
X }
Xdone:
X if(s) freesect((b<<3) - s - 1, s);
X close(fp);
X if(table || sum) {
X s = 0;
X for(b = 0; b < sizeof freecount/sizeof freecount[0]; b++) {
X if(freecount[b]) {
X if(table) printf("%4d\t%4d\n", b * sect0.dd_bit, freecount[b]);
X s += b * freecount[b];
X }
X }
X while(blp != NULL) {
X if(table) printf("%4d\t%4d\n", blp->size * sect0.dd_bit, blp->count);
X s += blp->size * blp->count;
X blp = blp->next;
X }
X if(sum) {
X printf("Total free: %6d\n", s * sect0.dd_bit);
X }
X }
X}
X
Xfreesect(where, size)
Xunsigned where, size;
X{
X register struct biglist *tp, *t;
X
X if(all) printf("%6x\t%d\n", where * sect0.dd_bit, size * sect0.dd_bit);
X if(size < sizeof freecount/sizeof freecount[0]) freecount[size]++;
X else {
X for(tp = (struct biglist *)&blp; (t = tp->next) != NULL
X && t->size < size; tp = t) {}
X if(tp->next == NULL || tp->next->size != size) {
X tp->next = (struct biglist *) malloc(sizeof (struct biglist));
X tp->next->next = t;
X tp->next->size = size;
X tp->next->count = 1;
X } else t->count++;
X }
X}
END_OF_FILE
if test 3988 -ne `wc -c <'freeb.c'`; then
echo shar: \"'freeb.c'\" unpacked with wrong size!
fi
# end of 'freeb.c'
fi
if test -f 'lcldrv.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lcldrv.h'\"
else
echo shar: Extracting \"'lcldrv.h'\" \(0 characters\)
sed "s/^X//" >'lcldrv.h' <<'END_OF_FILE'
END_OF_FILE
if test 0 -ne `wc -c <'lcldrv.h'`; then
echo shar: \"'lcldrv.h'\" unpacked with wrong size!
fi
# end of 'lcldrv.h'
fi
echo shar: End of shell archive.
exit 0
Bob Larson Arpa: blarson@skat.usc.edu
Uucp: {uunet,cit-vax}!usc!skat!blarson
Prime mailing list: info-prime-request%ais1@ecla.usc.edu
usc!ais1!info-prime-request