ref: 1a4e1fc2e52ab80b55ef0d7fdccca973267fb4cc
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; 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 Namelen %d\n", sizeof(Dentryhdr), Ddatasize, Namelen); } // 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); }