shithub: neoventi

ref: 4b60d3dd32efd00a1d07cb08662926ba9836719f
dir: /badcheck.c/

View raw version
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "neoventi.h"

extern VtArena *arenas;
extern u32int numarenas;

int
checkarenas(void)
{
	int bad = 0;
	u8int magicbuf[4];
	u32int magic;
	u64int addr;
	for(int i = numarenas-1; i >= 0; i -= 1){
		addr = 0;
		fprint(2, ".");
		if(i % 20 == 19 || i+1 == numarenas)
			fprint(2, "\n");
		for(int j = 0 ; 1 ; j += 1){
			if(vtreadarena(&arenas[i], addr, magicbuf, 4) != 4){
				sysfatal("corrupt arena");
			}
			magic = U32GET(magicbuf);
			if(magic == 0) // TODO: verify stopping point
				break;
			if(magic == arenas[i].clumpmagic)
				fprint(2, "valid!...");
			else{
				fprint(2, "arena contains invalid clumps!");
				break;
			}
		}
	};
	return bad;
}

void
threadmain(int argc, char **argv)
{
	if(argc != 1)
		sysfatal("i'm a dummy, sorry.");
	fprint(2, "loading arena partition metadata... ");
	initarenas();
	fprint(2, "...scanning.\n");
	if(!checkarenas())
		sysfatal("arenas do be corrupt, yo!");
	fprint(2, "looks like you're good - for now...\n");
}