changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: remove Elem (file/directory) when no longer referenced by a fid.

changeset 102: 2415b13613b1
parent 101: b3487ae9e237
child 103: c6c061169cb7
author: Mechiel Lukkien <mechiel@ueber.net>
date: Tue, 07 Aug 2007 00:14:14 +0200
files: appl/cmd/vacfs.b
description: remove Elem (file/directory) when no longer referenced by a fid.
     1.1--- a/appl/cmd/vacfs.b	Mon Aug 06 23:31:26 2007 +0200
     1.2+++ b/appl/cmd/vacfs.b	Tue Aug 07 00:14:14 2007 +0200
     1.3@@ -110,7 +110,7 @@
     1.4 
     1.5 Elem.mkdir(qid: int, de: ref Direntry, size: big, vd: ref Vacdir, pqid: int): ref Elem.Dir
     1.6 {
     1.7-	return ref Elem.Dir(qid, de, size, 1, vd, pqid, (-1, nil));
     1.8+	return ref Elem.Dir(qid, de, size, 0, vd, pqid, (-1, nil));
     1.9 }
    1.10 
    1.11 Elem.new(nqid: int, vd: ref Vacdir, de: ref Direntry, pqid: int): ref Elem
    1.12@@ -120,7 +120,7 @@
    1.13 		return nil;
    1.14 	if(de.mode & Vac->Modedir)
    1.15 		return Elem.mkdir(nqid, de, e.size, Vacdir.new(session, e, me), pqid);
    1.16-	return ref Elem.File(nqid, de, e.size, 1, Vacfile.new(session, e));
    1.17+	return ref Elem.File(nqid, de, e.size, 0, Vacfile.new(session, e));
    1.18 }
    1.19 
    1.20 Elem.stat(e: self ref Elem): ref Sys->Dir
    1.21@@ -158,9 +158,11 @@
    1.22 	if(de == nil)
    1.23 		return (nil, sprint("%r"));
    1.24 	cqid := childget(ed.qid, de.qid);
    1.25+	ne: ref Elem;
    1.26 	if(cqid < 0)
    1.27 		cqid = childput(ed.qid, de.qid);
    1.28-	ne := get(cqid);
    1.29+	else
    1.30+		ne = get(cqid);
    1.31 	if(ne == nil) {
    1.32 		ne = Elem.new(cqid, ed.vd, de, ed.qid);
    1.33 		set(ne);
    1.34@@ -192,7 +194,6 @@
    1.35 
    1.36 del(e: ref Elem)
    1.37 {
    1.38-	return;
    1.39 	i := e.qid % len elems;
    1.40 	elems[i] = remove(elems[i], e);
    1.41 }
    1.42@@ -328,17 +329,19 @@
    1.43 				break;
    1.44 			}
    1.45 			c.open(mode, f.qid);
    1.46-			e := get(int c.path);
    1.47-			if(e != nil)
    1.48-				e.nused++;
    1.49 			ss.reply(ref Rmsg.Open(m.tag, f.qid, ss.iounit()));
    1.50 
    1.51 		Clunk =>
    1.52 			f := ss.getfid(m.fid);
    1.53 			if(f != nil) {
    1.54-				e := get(int f.path);
    1.55-				if(e != nil && --e.nused <= 0)
    1.56-					del(e);
    1.57+				pick e := get(int f.path) {
    1.58+				Dir =>
    1.59+					if(e.pqid != 0 && --e.nused <= 0)
    1.60+						del(e);
    1.61+				File =>
    1.62+					if(--e.nused <= 0)
    1.63+						del(e);
    1.64+				}
    1.65 			}
    1.66 			ss.default(m);
    1.67 
    1.68@@ -389,6 +392,8 @@
    1.69 				n.reply <-= (nil, err);
    1.70 				break;
    1.71 			}
    1.72+			ed.nused--;
    1.73+			ne.nused++;
    1.74 			n.reply <-= (ne.stat(), nil);
    1.75 
    1.76 		Readdir =>