code: mafs

ref: 61ab76ca10766edc8728de5cc6e1d0972c99ebc9
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;

	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);
}