shithub: riscv

Download patch

ref: 2c8c2bc7272815f4535d4922a73ec5b484f42c3a
parent: a469cffafe23135da443b078bf82ad45833ff37a
author: cinap_lenrek <[email protected]>
date: Sun Jul 12 14:54:22 EDT 2020

hjfs: update mtime and qid.vers for directory on rename

when wstating a file, its directory should be updated to
reflect this change.

here is what the manpage states:

> The mtime field reflects the time of the last change of content
> (except when later changed by wstat). For a directory it is the
> time of the most recent remove, create, or wstat of a file in the
> directory.

--- a/sys/src/cmd/hjfs/fns.h
+++ b/sys/src/cmd/hjfs/fns.h
@@ -41,7 +41,7 @@
 Loc *	cloneloc(Fs *, Loc *);
 void	putloc(Fs *, Loc *, int);
 int	findentry(Fs *, FLoc *, Buf *, char *, FLoc *, int);
-void	modified(Chan *, Dentry *);
+void	modified(Loc *, Dentry *, short);
 int	trunc(Fs *, FLoc *, Buf *, uvlong);
 int	dprint(char *fmt, ...);
 int	delete(Fs *, FLoc *, Buf *);
--- a/sys/src/cmd/hjfs/fs1.c
+++ b/sys/src/cmd/hjfs/fs1.c
@@ -849,12 +849,12 @@
 }
 
 void
-modified(Chan *ch, Dentry *d)
+modified(Loc *loc, Dentry *d, short uid)
 {
 	d->mtime = time(0);
 	d->atime = d->mtime;
-	d->muid = ch->uid;
-	ch->loc->vers = ++d->vers;
+	d->muid = uid;
+	loc->vers = ++d->vers;
 }
 
 typedef struct Del Del;
--- a/sys/src/cmd/hjfs/fs2.c
+++ b/sys/src/cmd/hjfs/fs2.c
@@ -149,7 +149,7 @@
 	if(newqid(ch->fs, &f.path) < 0)
 		goto error;
 	l = getloc(ch->fs, f, ch->loc);
-	modified(ch, d);
+	modified(ch->loc, d, ch->uid);
 	b->op |= BDELWRI;
 	pgid = d->gid;
 	putbuf(b);
@@ -273,7 +273,7 @@
 	}
 	if((mode & OTRUNC) != 0){
 		trunc(ch->fs, ch->loc, b, 0);
-		modified(ch, d);
+		modified(ch->loc, d, ch->uid);
 		b->op |= BDELWRI;
 	}
 	if((mode & ORCLOSE) != 0)
@@ -380,7 +380,7 @@
 		p += rn;
 	}
 done:
-	modified(ch, d);
+	modified(ch->loc, d, ch->uid);
 	e = off + (p - (uchar *) buf);
 	if(e > d->size)
 		d->size = e;
@@ -679,7 +679,7 @@
 chanwstat(Chan *ch, Dir *di)
 {
 	Buf *b, *pb;
-	Dentry *d;
+	Dentry *d, *pd;
 	int isdir, owner, rc;
 	short nuid, ngid;
 
@@ -689,16 +689,19 @@
 		goto inval;
 	if(willmodify(ch->fs, ch->loc, ch->flags & CHFNOLOCK) < 0)
 		goto error;
+	pd = nil;
 	if(*di->name){
 		FLoc f;
 
 		if(!namevalid(di->name) || ch->loc->next == nil)
 			goto inval;
+		if(willmodify(ch->fs, ch->loc->next, ch->flags & CHFNOLOCK) < 0)
+			goto error;
 		pb = getbuf(ch->fs->d, ch->loc->next->blk, TDENTRY, 0);
 		if(pb == nil)
 			goto error;
-		d = getdent(ch->loc->next, pb);
-		if(d == nil)
+		pd = getdent(ch->loc->next, pb);
+		if(pd == nil)
 			goto error;
 		rc = findentry(ch->fs, ch->loc->next, pb, di->name, &f, ch->flags & CHFDUMP);
 		if(rc < 0)
@@ -705,7 +708,7 @@
 			goto error;
 		else if(rc == 0){
 			if((ch->flags & CHFNOPERM) == 0)
-				if(!permcheck(ch->fs, d, ch->uid, OWRITE))
+				if(!permcheck(ch->fs, pd, ch->uid, OWRITE))
 					goto perm;
 		} else if(f.blk != ch->loc->blk || f.deind != ch->loc->deind){
 			werrstr(Eexists);
@@ -748,7 +751,7 @@
 	d->gid = ngid;
 	if(di->length != ~0 && di->length != d->size && !isdir){
 		trunc(ch->fs, ch->loc, b, di->length);
-		modified(ch, d);
+		modified(ch->loc, d, ch->uid);
 	}
 	if(di->mtime != ~0)
 		d->mtime = di->mtime;
@@ -761,8 +764,11 @@
 		strcpy(d->name, di->name);
 	}
 	b->op |= BDELWRI;
-	if(pb != nil)
+	if(pb != nil){
+		modified(ch->loc->next, pd, ch->uid);
+		pb->op |= BDELWRI;
 		putbuf(pb);
+	}
 	putbuf(b);
 	chend(ch);
 	return 1;