ref: ce708f49bf5ec6c6b3fe1bb29d401c42b841b649
dir: /block.c/
#include <u.h> #include <libc.h> #include "dat.h" #include "fns.h" /* write out a single formatted block based on the tag TODO add a flag -r to show the recent block of metada */ int debug = 0; char *devfile = nil; static void usage(void) { fprint(2, "usage: block [-D] fsfile blkidx\n"); exits("usage"); } void main(int argc, char *argv[]) { u8 tag; u64 size, blkno; u8 buf[Maxdatablocksize]; Data *da; 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 != 2) usage(); devfile = argv[0]; if(devfile == nil) sysfatal("no disk file"); blkno = atoi(argv[1]); if (access(devfile, AREAD|AWRITE) == -1) sysfatal("%s cannot access device", devfile); size = devinit(devfile); if(size == 0) panic("null size %s", devfile); if(debug){ print("Dentry size %d\n", sizeof(Dentry)); print("Dentryhdr size %d Ddatasize %llud Servicelen %d\n", sizeof(Dentryhdr), Ddatasize, Servicelen); } // nunits = size/Blocksize; memset(buf, 0, Blocksize); devread(blkno, buf, 1); tag = buf[0]; if(tag == Tdata){ da = (Data*)buf; devread(blkno, buf, da->len); showblock(1, buf); }else showblock(1, buf); close(devfd); exits(0); }