changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: mostly cosmetic, more clear names.

changeset 108: 35094d0d4a2b
parent 107: f59da92b57d9
child 109: c4ccc5d9f9fe
author: Mechiel Lukkien <mechiel@ueber.net>
date: Thu, 16 Aug 2007 13:37:25 +0200
files: appl/cmd/vacfs.b
description: mostly cosmetic, more clear names.
     1.1--- a/appl/cmd/vacfs.b	Thu Aug 16 00:45:46 2007 +0200
     1.2+++ b/appl/cmd/vacfs.b	Thu Aug 16 13:37:25 2007 +0200
     1.3@@ -22,7 +22,7 @@
     1.4 print, sprint, fprint, fildes: import sys;
     1.5 Score, Session: import venti;
     1.6 Direntry, Vacdir, Vacfile, Source: import vac;
     1.7-Styxserver, Fid, Navigator, Navop, Enotfound: import styxservers;
     1.8+Styxserver, Fid, Navigator, Navop: import styxservers;
     1.9 
    1.10 Vacfs: module {
    1.11 	init:	fn(nil: ref Draw->Context, args: list of string);
    1.12@@ -38,7 +38,7 @@
    1.13 	qid:	int;
    1.14 	de: 	ref Direntry;
    1.15 	size:	big;
    1.16-	nused:	int;
    1.17+	nused:	int;	# fids using Elem
    1.18 	pick {
    1.19 	File =>	vf: 	ref Vacfile;
    1.20 	Dir =>	vd:	ref Vacdir;
    1.21@@ -51,13 +51,18 @@
    1.22 	stat:	fn(e: self ref Elem): ref Sys->Dir;
    1.23 };
    1.24 
    1.25+# maps vacfs dir qid to (vac qid, vacfs qid) of files in that dir
    1.26 Qidmap: adt {
    1.27 	qid:	int;
    1.28 	cqids:	list of (big, int);
    1.29 };
    1.30 
    1.31-elems := array[512] of list of ref Elem;
    1.32-qidmaps:= array[512] of list of ref Qidmap;
    1.33+Qfakeroot:	con 0;
    1.34+
    1.35+Mapsize:	con 512;
    1.36+fileelems := array[Mapsize] of list of ref Elem.File;
    1.37+direlems := array[Mapsize] of list of ref Elem.Dir;
    1.38+qidmaps:= array[Mapsize] of list of ref Qidmap;
    1.39 lastqid := 0;
    1.40 qidscores: list of (string, int);
    1.41 
    1.42@@ -111,7 +116,7 @@
    1.43 		error(sprint("handshake: %r"));
    1.44 	say("have handshake");
    1.45 
    1.46-	rqid := 0;
    1.47+	rqid: int;
    1.48 	red: ref Elem;
    1.49 	if(args == nil) {
    1.50 		de := Direntry.new();
    1.51@@ -119,6 +124,7 @@
    1.52 		de.ctime = de.atime = de.mtime = daytime->now();
    1.53 		de.mode = Vac->Modedir|8r555;
    1.54 		de.emode = Sys->DMDIR|8r555;
    1.55+		rqid = Qfakeroot;
    1.56 		red = Elem.mkdir(rqid, de, big 0, nil, rqid);
    1.57 	} else {
    1.58 		(vd, de, err) := vac->vdroot(session, *score);
    1.59@@ -127,7 +133,7 @@
    1.60 		rqid = ++lastqid;
    1.61 		red = Elem.mkdir(rqid, de, big 0, vd, rqid);
    1.62 	}
    1.63-	set(red);
    1.64+	elemput(red);
    1.65 
    1.66 	navchan := chan of ref Navop;
    1.67 	nav := Navigator.new(navchan);
    1.68@@ -177,13 +183,13 @@
    1.69 		Clunk =>
    1.70 			f := srv.getfid(m.fid);
    1.71 			if(f != nil) {
    1.72-				pick e := get(int f.path) {
    1.73+				pick e := elemget(int f.path) {
    1.74 				Dir =>
    1.75-					if(e.pqid != 0 && --e.nused <= 0)
    1.76-						del(e);
    1.77+					if(e.pqid != Qfakeroot && --e.nused <= 0)
    1.78+						elemdel(e);
    1.79 				File =>
    1.80 					if(--e.nused <= 0)
    1.81-						del(e);
    1.82+						elemdel(e);
    1.83 				}
    1.84 			}
    1.85 			srv.default(m);
    1.86@@ -222,7 +228,7 @@
    1.87 	while((navop := <-c) != nil)
    1.88 		pick n := navop {
    1.89 		Stat =>
    1.90-			n.reply <-= (get(int n.path).stat(), nil);
    1.91+			n.reply <-= (elemget(int n.path).stat(), nil);
    1.92 
    1.93 		Walk =>
    1.94 			ed := getdir(int n.path);
    1.95@@ -237,7 +243,7 @@
    1.96 
    1.97 		Readdir =>
    1.98 			if(dflag) say(sprint("have readdir path=%bd offset=%d count=%d", n.path, n.offset, n.count));
    1.99-			if(n.path == big 0) {
   1.100+			if(n.path == big Qfakeroot) {
   1.101 				n.reply <-= (nil, nil);
   1.102 				continue;
   1.103 			}
   1.104@@ -249,7 +255,7 @@
   1.105 
   1.106 			# prev is needed because styxservers can request the previously returned Dir
   1.107 			(loffset, d) := ed.prev;
   1.108-			if(loffset != n.offset) {
   1.109+			if(n.offset == loffset+1) {
   1.110 				(ok, de) := ed.vd.readdir();
   1.111 				if(ok < 0) {
   1.112 					say(sprint("readdir error: %r"));
   1.113@@ -257,18 +263,19 @@
   1.114 					continue;
   1.115 				}
   1.116 				if(de != nil) {
   1.117-					cqid := childget(ed.qid, de.qid);
   1.118+					cqid := qidget(ed.qid, de.qid);
   1.119 					if(cqid < 0)
   1.120-						cqid = childput(ed.qid, de.qid);
   1.121-					ne := get(cqid);
   1.122+						cqid = qidput(ed.qid, de.qid);
   1.123+					ne := elemget(cqid);
   1.124 					if(ne == nil)
   1.125 						ne = Elem.new(cqid, ed.vd, de, ed.qid);
   1.126-					if(dflag) say(sprint("readdir, childget(%d, %bd) = %d", ed.qid, de.qid, ne.qid));
   1.127+					if(dflag) say(sprint("readdir, qidget(%d, %bd) = %d", ed.qid, de.qid, ne.qid));
   1.128 					ed.prev = (n.offset, ne.stat());
   1.129 				} else {
   1.130 					ed.prev = (n.offset, nil);
   1.131 				}
   1.132-			}
   1.133+			} else if(n.offset != loffset)
   1.134+				error("internal error");
   1.135 			(nil, d) = ed.prev;
   1.136 			if(d != nil)
   1.137 				n.reply <-= (d, nil);
   1.138@@ -276,7 +283,7 @@
   1.139 		}
   1.140 }
   1.141 
   1.142-childget(qid: int, vqid: big): int
   1.143+qidget(qid: int, vqid: big): int
   1.144 {
   1.145 	for(l := qidmaps[qid % len qidmaps]; l != nil; l = tl l) {
   1.146 		if((hd l).qid != qid)
   1.147@@ -290,7 +297,7 @@
   1.148 	return -1;
   1.149 }
   1.150 
   1.151-childput(qid: int, vqid: big): int
   1.152+qidput(qid: int, vqid: big): int
   1.153 {
   1.154 	qd: ref Qidmap;
   1.155 	for(l := qidmaps[qid % len qidmaps]; l != nil; l = tl l)
   1.156@@ -311,7 +318,7 @@
   1.157 	for(l := qidscores; l != nil; l = tl l) {
   1.158 		(s, n) := hd l;
   1.159 		if(s == score)
   1.160-			return get(n);
   1.161+			return elemget(n);
   1.162 	}
   1.163 	return nil;
   1.164 }
   1.165@@ -348,9 +355,9 @@
   1.166 walk(ed: ref Elem.Dir, name: string): (ref Elem, string)
   1.167 {
   1.168 	if(name == "..")
   1.169-		return (get(ed.pqid), nil);
   1.170+		return (elemget(ed.pqid), nil);
   1.171 
   1.172-	if(ed.qid == 0) {
   1.173+	if(ed.qid == Qfakeroot) {
   1.174 		ne := scoreget(name);
   1.175 		if(ne == nil) {
   1.176 			(ok, score) := Score.parse(name);
   1.177@@ -363,7 +370,7 @@
   1.178 
   1.179 			nqid := scoreput(name);
   1.180 			ne = Elem.mkdir(nqid, de, big 0, vd, ed.qid);
   1.181-			set(ne);
   1.182+			elemput(ne);
   1.183 		}
   1.184 		return (ne, nil);
   1.185 	}
   1.186@@ -371,30 +378,33 @@
   1.187 	de := ed.vd.walk(name);
   1.188 	if(de == nil)
   1.189 		return (nil, sprint("%r"));
   1.190-	cqid := childget(ed.qid, de.qid);
   1.191 	ne: ref Elem;
   1.192+	cqid := qidget(ed.qid, de.qid);
   1.193 	if(cqid < 0)
   1.194-		cqid = childput(ed.qid, de.qid);
   1.195+		cqid = qidput(ed.qid, de.qid);
   1.196 	else
   1.197-		ne = get(cqid);
   1.198+		ne = elemget(cqid);
   1.199 	if(ne == nil) {
   1.200 		ne = Elem.new(cqid, ed.vd, de, ed.qid);
   1.201-		set(ne);
   1.202+		elemput(ne);
   1.203 	}
   1.204 	return (ne, nil);
   1.205 }
   1.206 
   1.207-get(qid: int): ref Elem
   1.208+elemget(qid: int): ref Elem
   1.209 {
   1.210-	for(l := elems[qid % len elems]; l != nil; l = tl l)
   1.211-		if((hd l).qid == qid)
   1.212-			return hd l;
   1.213-	return nil;
   1.214+	e := getdir(qid);
   1.215+	if(e != nil)
   1.216+		return e;
   1.217+	return getfile(qid);
   1.218 }
   1.219 
   1.220-set(e: ref Elem)
   1.221+elemput(e: ref Elem)
   1.222 {
   1.223-	elems[e.qid % len elems] = e::elems[e.qid % len elems];
   1.224+	pick ee := e {
   1.225+	File =>	fileelems[e.qid % len fileelems] = ee::fileelems[e.qid % len fileelems];
   1.226+	Dir =>	direlems[e.qid % len direlems] = ee::direlems[e.qid % len direlems];
   1.227+	}
   1.228 }
   1.229 
   1.230 remove[T](l: list of T, e: T): list of T
   1.231@@ -406,27 +416,28 @@
   1.232 	return r;
   1.233 }
   1.234 
   1.235-del(e: ref Elem)
   1.236+elemdel(e: ref Elem)
   1.237 {
   1.238-	i := e.qid % len elems;
   1.239-	elems[i] = remove(elems[i], e);
   1.240+	i := e.qid % Mapsize;
   1.241+	pick ee := e {
   1.242+	File =>	fileelems[i] = remove(fileelems[i], ee);
   1.243+	Dir =>	direlems[i] = remove(direlems[i], ee);
   1.244+	}
   1.245 }
   1.246 
   1.247 getfile(qid: int): ref Elem.File
   1.248 {
   1.249-	pick file := get(qid) {
   1.250-	File =>	return file;
   1.251-	}
   1.252-	error("internal error, getfile");
   1.253+	for(l := fileelems[qid % len fileelems]; l != nil; l = tl l)
   1.254+		if((hd l).qid == qid)
   1.255+			return hd l;
   1.256 	return nil;
   1.257 }
   1.258 
   1.259 getdir(qid: int): ref Elem.Dir
   1.260 {
   1.261-	pick d := get(qid) {
   1.262-	Dir =>	return d;
   1.263-	}
   1.264-	error("internal error, getdir");
   1.265+	for(l := direlems[qid % len direlems]; l != nil; l = tl l)
   1.266+		if((hd l).qid == qid)
   1.267+			return hd l;
   1.268 	return nil;
   1.269 }
   1.270