code: mafs

ref: 7038b412045ad003366804789e7fecaf0552f77c
dir: /fsok.c/

View raw version
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"

/*
	do Super.fsok = 1
	disk/fsok fsfile
 */

int debug = 0;
char *devfile = nil, *freesfile = nil;

static void
usage(void)
{
	fprint(2, "usage: fsok [-D] fsfile\n");
	exits("usage");
}

void
main(int argc, char *argv[])
{
	u64 size;
	s8 buf[Blocksize];
	Dentry *d;
	Errenv env = {0};

	envpp = privalloc();
	*envpp = &env;
	if(waserror()){
		panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
			env.nlabel,
			env.label[0][JMPBUFPC], env.label[1][JMPBUFPC],
			env.label[2][JMPBUFPC], env.label[3][JMPBUFPC],
			env.label[4][JMPBUFPC], env.label[5][JMPBUFPC]);
	}

	ARGBEGIN{
	default:	usage();
	case 'D':	debug++; break;
	}ARGEND

	if(argc != 1)
		usage();

	devfile = argv[0];
	if(devfile == nil)
		sysfatal("no disk file");

	if (access(devfile, AREAD|AWRITE) == -1)
		sysfatal("%s cannot access device", devfile);

	size = devinit(devfile);
	if(size == 0)
		panic("null size %s", devfile);

	devread(Bdsuper, buf, 1);
	// showblock(1, buf);
	d = (Dentry*)buf;

	if(d->fsok)
		fprint(2, "fsok: %s fsok is already %llud\n", devfile, d->fsok);
	else{
		d->fsok = 1;
		d->mtime = nsec();
		devwrite(Bdsuper, buf, 1);
	}
	close(devfd);
	exits(0);
}