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

⟦0dd3ea0dc⟧ TextFile

    Length: 2841 (0xb19)
    Types: TextFile
    Notes: UNIX file
    Names: »check.c«

Derivation

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

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[] = "/etc/checklist";
char	fixopt[] = "-s";

int	sflag;
long	lseek();

main(argc, argv)
char *argv[];
{
	register estat = 0;
	register char **fsp;
	int i;
	argv[2] = "/dev/crap1";
	argv[3] = "/dev/crap1";
	argv[4] = "/dev/crap1";
	printf("argc = %d\n", argc);
	for( i = 0; i < 4; ++i)
		printf("argv[%d] = %s\n", argc, argv[i]);
	if (argc>1 && *argv[1]=='-') {
/*		if (argv[1][1]=='s' && argv[1][2]=='\0') */
		if (argv[1][1]=='s')
			sflag = 1;
		else
			usage();
		printf("here\n");
		argv++;
		argc--;
	}
	if (argc == 1 && access(cklist, AREAD) == 0) {
		rlist(&argc, argv);
/*
		for (i = 0; i < 5; ++i)
			printf("argv[%d] = %s\n", i, argv[i]); */
	}
	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 (access(fs, AREAD | AWRITE) != 0) {
		fprintf(stderr, "can't stat %s\n", fs);
		return(-2);
	}
	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(agc, strng)
register char **strng;
int	*agc;
{
register FILE *fdp;
char buf[80];

	if ((fdp = fopen(cklist, "r")) == NULL) {
		fprintf(stderr, "check: can't open %s\n", cklist);
		exit(-2);
	}
	while (fscanf(fdp, "%s", strng[*agc]) == 1)
		*agc += 1;
	strng[*agc] = NULL;
}
usage()
{
	fprintf(stderr, "Usage: check [-s] filesystem [ ... ]\n");
	exit(-2);
}