code: mafs

ref: 80e6c118c65b013bde24f8b9c95881c0e3a73d3e
dir: /blk.c/

View raw version
#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);
}

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) ||
		(ms[0].verd >= ms[1].verd)){
		if(new != nil)
			*new = ms+1;
		if(cur != nil)
			*cur = ms;
		return 0;
	}

	if(new != nil)
		*new = ms;
	if(cur != nil)
		*cur = ms+1;
	return 1;
}