From 9a3942718357a83c534ee5a37ae9bd3bc85a2f50 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sun, 18 Nov 2012 00:06:54 +0100 Subject: hjfs: fix dump / create getdent() introduced a bug as the qid check fails in the case when we walk to DUMPROOTQID, but get ROOTQID in the directory instead. newentry() getblk(..., GBCREATE) caused the whole directory to get dumped until it hit a free slot. we cannot do this because this changes the addresses of Dentries of files but doesnt update the loctree. this caused the bogus walks when we hit a different directory than we expected. what we do now is the following: newentry() was changed to never dump anything. it will just read the directory and return a the address of a free slot or create a new block having space for one. chancreat() then makes a loc in the loctree for the free slot, drops the dirent buffer and calls willmodify() on the new slot. this will dump the block containing the slot (and possible other slots) and updates the loctree to the new version. after that, chancreate() modifies the slot filling the Dentry. there should be no race, as newentry() skips slots that have a loc in the loctree. theres one case where newentry() can dump the block immidiately when it is called from dump. added new parameter for that and documented in the comment. createuserdir() was simplified by just calling chancreat(). to get arround the permission check, a new per channel flag CHFNOPERM was added. --- sys/src/cmd/hjfs/dump.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sys/src/cmd/hjfs/dump.c') diff --git a/sys/src/cmd/hjfs/dump.c b/sys/src/cmd/hjfs/dump.c index 210e57964..4a9982693 100644 --- a/sys/src/cmd/hjfs/dump.c +++ b/sys/src/cmd/hjfs/dump.c @@ -24,7 +24,7 @@ copydentry(Fs *fs, FLoc *a, Loc *b, char *nname) putbuf(ba); return -1; } - rc = newentry(fs, b, bb, nname, &c); + rc = newentry(fs, b, bb, nname, &c, 1); if(rc < 0){ err1: putbuf(bb); @@ -35,7 +35,7 @@ copydentry(Fs *fs, FLoc *a, Loc *b, char *nname) if(bc == nil) goto err1; d = &bc->de[c.deind]; - memcpy(d, &ba->de[a->deind], sizeof(Dentry)); + memcpy(d, &ba->de[a->deind], sizeof(*d)); strcpy(d->name, nname); for(i = 0; i < NDIRECT; i++) if(d->db[i] != 0) @@ -116,6 +116,7 @@ int willmodify(Fs *fs, Loc *l, int nolock) { Buf *p; + Loc *m; uvlong i, r; Dentry *d; int rc; @@ -150,7 +151,7 @@ again: continue; if(r == l->blk) goto found; - } + } phase: werrstr("willmodify -- phase error"); putbuf(p); @@ -164,7 +165,19 @@ found: if(rc == 0) goto phase; putbuf(p); - l->blk = r; + + if(r != l->blk){ + /* + * block got dumped, update the loctree so locs + * point to the new block. + */ + qlock(&fs->loctree); + for(m = l->cnext; m != l; m = m->cnext) + if(m->blk == l->blk) + m->blk = r; + l->blk = r; + qunlock(&fs->loctree); + } done: l->flags |= LDUMPED; if(!nolock){ -- cgit v1.2.3