ref: 0906df260dba0a482190c91103cb3041baf704fc
dir: /blk.c/
#include <u.h> #include <libc.h> #include "dat.h" #include "fns.h" void showdentryhdr(int fd, u8 *buf) { Dentry *d; d = (Dentry*)buf; fprint(fd, "name %s\n", d->name); fprint(fd, "uid %d\n", d->uid); fprint(fd, "gid %d\n", d->gid); fprint(fd, "muid %d\n", d->muid); fprint(fd, "size %llud\n", d->size); fprint(fd, "pdblkno %llud\n", d->pdblkno); fprint(fd, "pqpath %llud\n", d->pqpath); fprint(fd, "mtime %llud\n", d->mtime); fprint(fd, "path %llud\n", d->path); fprint(fd, "version %ud\n", d->version); fprint(fd, "mode %uo\n", d->mode); } void showmagic(int fd, u8 *d) { fprint(fd, "%s", ((Dentry*)d)->buf); } void showconfig(int fd, u8 *d) { fprint(fd, "%s", ((Dentry*)d)->buf); } void showsuper(int fd, u8 *d) { Dentry *s; s = (Dentry*)d; fprint(fd, "qidgen %llud\n", s->qidgen); fprint(fd, "fsok %llud\n", s->fsok); } void showdentry(int fd, u8 *buf) { int j; Dentry *d; showdentryhdr(fd, buf); d = (Dentry*)buf; if(d->path == Qpconfig || d->path == Qpconfig0) showconfig(fd, buf); else if(d->path == Qpsuper || d->path == Qpsuper0) showsuper(fd, buf); else if(d->path == Qpmagic) showmagic(fd, buf); else if(d->size <= Ddatasize && (d->mode&DMDIR) == 0 && d->path != Qproot0){ fprint(fd, "%s", d->buf); }else{ fprint(fd, "direct blocks\n"); for(j = 0; j<Ndblock; j++) fprint(fd, " %d %llud\n", j, d->dblocks[j]); fprint(fd, "indirect blocks\n"); for(j = 0; j<Niblock; j++) fprint(fd, " %d %llud\n", j, d->iblocks[j]); } } void showind(int fd, u8 *buf) { int j; Indirect *t; t = (Indirect*)buf; for(j = 0; j<Nindperblock; j++) fprint(fd, " %d %llud\n", j, t->bufa[j]); } void showdata(int fd, u8 *buf) { Data *c; c = (Data*)buf; fprint(fd, "%s", (s8*)c->buf); } void showblock(int fd, u8 *buf) { u8 tag; Data *t; Dentry *d; Indirect *r; tag = buf[0]; t = (Data*)buf; r = (Indirect*)buf; d = (Dentry*)buf; if(tag == Tblank){ fprint(fd, "%s\n", tagnames[tag]); return; }else if(tag == Tdentry){ fprint(fd, "%s %llud %d\n", tagnames[tag], d->path, d->verd); showdentry(fd, buf); return; }else if(tag == Tdata){ fprint(fd, "%s %llud %llud %d\n", tagnames[tag], ((u64*)buf)[t->len*Nu64perblock -1], t->dblkno, t->len); showdata(fd, buf); return; }else if(tag < Maxtind) fprint(fd, "%s %llud %d %llud\n", tagnames[tag], r->path, r->veri, r->dblkno); if(tag >= Tind0 && tag < Maxtind) showind(fd, buf); else fprint(fd, "unknown tag type %d\n", tag); } /* 0 1 latest ------------------ 1. 0 255 0 2. 255 0 1 3. == 1 so that new will be 0 4. > 0 5. < 1 */ u8 recentmetadata(void *buf, void **cur, void **new) { Metadataunit *ms; if(buf == nil) panic("recentmetadata buf == nil\n"); ms = buf; if(ms[0].verd == 0 && ms[1].verd == 255) goto Cur0; else if(ms[0].verd == 255 && ms[1].verd == 0) goto Cur1; else if(ms[0].verd == ms[1].verd) goto Cur1; /* so the new contents go in the first block */ else if(ms[0].verd > ms[1].verd) goto Cur0; else goto Cur1; Cur0: if(new != nil) *new = ms+1; if(cur != nil) *cur = ms; return 0; Cur1: if(new != nil) *new = ms; if(cur != nil) *cur = ms+1; return 1; }