code: mafs

ref: b3e875d7db45fca0cde9f4efa12872f61afc54d7
dir: /tests/reli.c/

View raw version
#include <u.h>
#include <libc.h>
#include "../dat.h"
#include "../fns.h"

/*
	write out a single formatted block based on the tag
	./6.reli 23; ./6.reli 24;  ./6.reli 74
	./6.reli 75; ./6.reli 3100 '
 */

int debug = 0;
char *devfile = nil;

static void
usage(void)
{
	fprint(2, "usage: reli [-D] reli\n");
	exits("usage");
}

void
drilldown(u8 tag, u64 reli)
{
	print("%s reli %llud is at [%llud] nperindunit %llud\n",
		 tagnames[tag], reli, reli/nperindunit(tag), nperindunit(tag));
	if(tag > Tind0)
		drilldown(tag-1, reli%nperindunit(tag));
}

void
main(int argc, char *argv[])
{
	u64 reli;
	u8 tag;

	ARGBEGIN{
	default:	usage();
	case 'D':	debug++; break;
	}ARGEND

	if(argc != 1)
		usage();

	reli = atoll(argv[0]);
	print("reli %llud\n", reli);

	if(debug)
		print("maxreli %llud\n", maxreli(Maxtind-1));
	if(reli > maxreli(Maxtind-1))
		exits("invalid reli");

	if(reli < Ndblock){
		print("dblock[%llud]\n", reli);
	}else{
		tag = rel2tind(reli);
		print("iblock[%d] tagstartreli %llud\n", tag-Tind0, tagstartreli(tag));
		drilldown(tag, reli-tagstartreli(tag));
	}
	exits(0);
}