DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦f6c82f8c9⟧ TextFile

    Length: 2980 (0xba4)
    Types: TextFile
    Notes: UNIX file
    Names: »check.bak«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦2d53db1df⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »frankh/src/fsck/check.bak« 

TextFile

/*
 * check -- check all of the normally-used filesystems
 * or those specified by calling `icheck' and `dcheck'.
 * If `-s' is specified, also try to correct any
 * problems encountered in any of these filesystems.
 */

/*

return '-2' (254) if an internal error occurred; '-1' (255) if
there are unfixed errors; '0' if no errors were found; and '1'
if errors were found, but fixed (system should then be rebooted).

*/

#include <stdio.h>
#include <check.h>
#include <access.h>

char	icheck[] = "/bin/icheck";
char	dcheck[] = "/bin/dcheck";
char	cklist[] = "checklist";
char	fixopt[] = "-s";

int	sflag;
long	lseek();

main(argc, argv)
char *argv[];
{
	register estat = 0;
	register char **fsp;
	int i;
	printf("argc = %d\n", argc);
	for (i = 0; i < 3; ++i)
		printf("argv[%d] = %s\n", i, argv[i]);
	if (argc>1 && *argv[1]=='-') {
		if (argv[1][1]=='s' && argv[1][2]=='\0')
			sflag = 1;
		else
			usage();
		argv++;
		argc--;
	}
	if (argc == 1 && access(cklist, AREAD) == 0)
		rlist(argv);
	else
		usage();
	if (argc > 1)
		fsp = &argv[1];
	else
		usage();
	while (*fsp != NULL)
		estat |= check(*fsp++);
	exit(estat);
}

/*
 * Do check for a single filesystem.
 */
check(fs)
char *fs;
{
	register int ierror, derror;
	register int bad = 0;

	if (ierror = run(icheck, fs, NULL))
		bad |= 1;
	if (derror = run(dcheck, fs, NULL))
		bad |= 1;
	if (sflag) {
		if ((ierror & ~IC_FIX) == 0) {
			if (derror & ~DC_FIX)
				return(-1);
			if (derror & DC_FIX) {
				if (derror = run(dcheck, fixopt, fs, NULL))
					return(-1);
				ierror = IC_MISS;	/*force fixup icheck*/
			}
			if (ierror & IC_FIX)
				if (ierror = run(icheck, fixopt, fs, NULL))
					return(-1);
		} else
			return(-1);
	}
	return (bad);
}

/*
 * Do a command -- either icheck or dcheck normally.
 */
/* VARARGS */
run(command, args)
char *command;
{
	register int pid;
	int status;

	if ((pid = fork()) < 0) {
		fprintf(stderr, "check: try again\n");
		exit(-2);
	}
	if (pid) {
		wait(&status);
		if ((status&0377) != 0)
			return(-2);
		return ((status>>8)&0377);
	} else {
		execv(command, &command);
		fprintf(stderr, "check: someone moved %s\n", command);
		exit(-2);
	}
	/* NOTREACHED */
}

rlist(strng)
register char **strng;
{
char *tmp, *tmp1, *t1;
register int i, fd, cnt, tp, tt;

	tmp = "                                                          ";
	tmp1 = tmp;
	t1 = " ";

	printf("rlist: here!");
	printf("strng[0] = %s\n", strng[0]);
	printf("file: %s\n", cklist);
	if ((fd = open(cklist, 0)) == EOF) {
		printf("can't open: %s\n", cklist);
		exit(-2);
	}

	printf("fd = %d\n", fd);
	cnt = 1;
	for (i = 0; i < 60; ++i) {
		if ((tp = read(fd, t1, 1)) != 1) {
			printf("tmp1 = %s\n", tmp1);
			printf("EOF\n");
			exit(-2);
		}
		tmp = t1;
		tt = t1;
		printf("t1 = %s   %x\n", t1, tt);
		if (tmp == "\n") {
			printf("newline\n");
			tmp = "\0";
			strng[cnt] = tmp1;
			cnt += 1;
			tmp = tmp1;
		}
		*tmp++;
	}
	
}
usage()
{
	fprintf(stderr, "Usage: check [-s] filesystem [ ... ]\n");
	exit(-2);
}