shithub: dddb

ref: 2ab7efc23fd2137ce88d328441900e0a439a3508
dir: /appl/lib/mtptmirror.b/

View raw version
implement MtptMirror;

include "sys.m";
	sys: Sys;
include "hash.m";
	hash: Hash;
include "nametree.m"
	nametree: Nametree;

init()
{
	sys = load Sys Sys->PATH;
	hash = load Hash Hash->PATH;
	nametree = load Nametree Nametree->PATH;
}

new(mtpts: list of string, lower, upper: big)
{
	m: ref MtptMirror;
	m.mtpts = mtpts;
	m.qidmap = hash->new(HSSZ);
	m.lower = lower;
	m.upper = upper ;
	return m;
}

MtptMirror.refresh(m: self ref MtptMirror): string
{
	# find a non-empty mountpoint
	mtpt := "";
	for(i := 0; i < len m.mtpts; i++) {
		fd := sys->open(m.mtpts[i], Sys->OREAD);
		if(fd == nil)
			continue;
		(ec, nil) := sys->dirread(fd);
		if(ec > 0) {
			mtpt = m.mtpts[i];
			break;
		}
	}
	if(mtpt == "")
		return Emmnopath;

	queue: array of ref Sys->Dir;
	visited_nodes: array of string;
	qi := 1;

	# queue[0] = mtpt;
	walkloop:
	for(i := 0; i < qi; i++) {
		rpath := queue[i];
		(content, nil) := readdir->init(rpath, readdir->NAME|readdir->COMPACT);
		for(j := 0; j < len content; j++) {
			# if(rpath == "nodes")
			queue[qi] = content[j];
			qi++;
		}
	}
}

MtptMirror.get_path(m: self ref MtptMirror, path: string): big
{
	v := m.qidmap.find(path);
	if(v == nil)
		return -1;
	return v.i;
}

# mountpoint serving functions
mtpt_walk(tree: Tree, mtpt: string, Cnode, Mnodes: int): int
{

}