void main(int argc, char **argv) { int fd; Header h; Super s; ARGBEGIN{ default: usage(); }ARGEND if(argc == 0 || argc > 2) usage(); if((fd = open(argv[0], argc==2 ? ORDWR : OREAD)) < 0) sysfatal("open %s: %r", argv[0]); if(pread(fd, buf, HeaderSize, HeaderOffset) != HeaderSize) sysfatal("reading header: %r"); if(!headerUnpack(&h, buf)) sysfatal("unpacking header: %r"); if(pread(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize) sysfatal("reading super block: %r"); if(!superUnpack(&s, buf)) sysfatal("unpacking super block: %r"); print("epoch %d\n", s.epochLow); if(argc == 2){ s.epochLow = strtoul(argv[1], 0, 0); superPack(&s, buf); if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize) sysfatal("writing super block: %r"); } exits(0); }
Tnode* initxheader(void) { u8int buf[HeaderSize]; Tnode *t; if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize) return stringnode("error reading header: %r"); if(!headerUnpack(&h, buf)) return stringnode("error unpacking header: %r"); t = stringnode("header " "version=%#ux (%d) " "blockSize=%#ux (%d) " "super=%#lux (%ld) " "label=%#lux (%ld) " "data=%#lux (%ld) " "end=%#lux (%ld)", h.version, h.version, h.blockSize, h.blockSize, h.super, h.super, h.label, h.label, h.data, h.data, h.end, h.end); t->expand = xheaderexpand; return t; }
void main(int argc, char *argv[]) { int fd, force; Header h; ulong bn; Entry e; char *label = "vfs"; char *host = nil; char *score = nil; u32int root; Dir *d; force = 0; ARGBEGIN{ default: usage(); case 'b': bsize = unittoull(EARGF(usage())); if(bsize == ~0) usage(); break; case 'h': host = EARGF(usage()); break; case 'i': iso9660file = EARGF(usage()); iso9660off = atoi(EARGF(usage())); break; case 'l': label = EARGF(usage()); break; case 'v': score = EARGF(usage()); break; /* * This is -y instead of -f because flchk has a * (frequently used) -f option. I type flfmt instead * of flchk all the time, and want to make it hard * to reformat my file system accidentally. */ case 'y': force = 1; break; }ARGEND if(argc != 1) usage(); if(iso9660file && score) vtFatal("cannot use -i with -v"); vtAttach(); fmtinstall('V', scoreFmt); fmtinstall('R', vtErrFmt); fmtinstall('L', labelFmt); fd = open(argv[0], ORDWR); if(fd < 0) vtFatal("could not open file: %s: %r", argv[0]); buf = vtMemAllocZ(bsize); if(pread(fd, buf, bsize, HeaderOffset) != bsize) vtFatal("could not read fs header block: %r"); if(headerUnpack(&h, buf) && !force && !confirm("fs header block already exists; are you sure?")) goto Out; if((d = dirfstat(fd)) == nil) vtFatal("dirfstat: %r"); if(d->type == 'M' && !force && !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?")) goto Out; partition(fd, bsize, &h); headerPack(&h, buf); if(pwrite(fd, buf, bsize, HeaderOffset) < bsize) vtFatal("could not write fs header: %r"); disk = diskAlloc(fd); if(disk == nil) vtFatal("could not open disk: %r"); if(iso9660file) iso9660init(fd, &h, iso9660file, iso9660off); /* zero labels */ memset(buf, 0, bsize); for(bn = 0; bn < diskSize(disk, PartLabel); bn++) blockWrite(PartLabel, bn); if(iso9660file) iso9660labels(disk, buf, blockWrite); if(score) root = ventiRoot(host, score); else{ rootMetaInit(&e); root = rootInit(&e); } superInit(label, root, vtZeroScore); diskFree(disk); if(score == nil) topLevel(argv[0]); Out: vtDetach(); exits(0); }