plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

flchk.c (1857B)


      1 #include "stdinc.h"
      2 #include <bio.h>
      3 #include "dat.h"
      4 #include "fns.h"
      5 
      6 Biobuf bout;
      7 Fsck fsck;
      8 
      9 static void
     10 usage(void)
     11 {
     12 	fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
     13 	threadexitsall("usage");
     14 }
     15 
     16 #pragma	varargck	argpos	flprint	1
     17 
     18 static int
     19 flprint(char *fmt, ...)
     20 {
     21 	int n;
     22 	va_list arg;
     23 
     24 	va_start(arg, fmt);
     25 	n = Bvprint(&bout, fmt, arg);
     26 	va_end(arg);
     27 	return n;
     28 }
     29 
     30 static void
     31 flclre(Fsck *chk, Block *b, int o)
     32 {
     33 	USED(chk);
     34 	Bprint(&bout, "# clre 0x%ux %d\n", b->addr, o);
     35 }
     36 
     37 static void
     38 flclrp(Fsck *chk, Block *b, int o)
     39 {
     40 	USED(chk);
     41 	Bprint(&bout, "# clrp 0x%ux %d\n", b->addr, o);
     42 }
     43 
     44 static void
     45 flclri(Fsck *chk, char *name, MetaBlock *mb, int i, Block *b)
     46 {
     47 	USED(chk);
     48 	USED(mb);
     49 	USED(i);
     50 	USED(b);
     51 	Bprint(&bout, "# clri %s\n", name);
     52 }
     53 
     54 static void
     55 flclose(Fsck *chk, Block *b, u32int epoch)
     56 {
     57 	USED(chk);
     58 	Bprint(&bout, "# bclose 0x%ux %ud\n", b->addr, epoch);
     59 }
     60 
     61 void
     62 threadmain(int argc, char *argv[])
     63 {
     64 	int csize = 1000;
     65 	VtConn *z;
     66 	char *host = nil;
     67 
     68 	fsck.useventi = 1;
     69 	Binit(&bout, 1, OWRITE);
     70 	ARGBEGIN{
     71 	default:
     72 		usage();
     73 	case 'c':
     74 		csize = atoi(ARGF());
     75 		if(csize <= 0)
     76 			usage();
     77 		break;
     78 	case 'f':
     79 		fsck.useventi = 0;
     80 		break;
     81 	case 'h':
     82 		host = ARGF();
     83 		break;
     84 	case 'v':
     85 		fsck.printdirs = 1;
     86 		break;
     87 	}ARGEND;
     88 
     89 	if(argc != 1)
     90 		usage();
     91 
     92 	fmtinstall('L', labelFmt);
     93 	fmtinstall('V', scoreFmt);
     94 
     95 	/*
     96 	 * Connect to Venti.
     97 	 */
     98 	z = vtdial(host);
     99 	if(z == nil){
    100 		if(fsck.useventi)
    101 			sysfatal("could not connect to server: %r");
    102 	}else if(vtconnect(z) < 0)
    103 		sysfatal("vtconnect: %r");
    104 
    105 	/*
    106 	 * Initialize file system.
    107 	 */
    108 	fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
    109 	if(fsck.fs == nil)
    110 		sysfatal("could not open file system: %r");
    111 
    112 	fsck.print = flprint;
    113 	fsck.clre = flclre;
    114 	fsck.clrp = flclrp;
    115 	fsck.close = flclose;
    116 	fsck.clri = flclri;
    117 
    118 	fsCheck(&fsck);
    119 
    120 	threadexitsall(0);
    121 }