shithub: gefs

Download patch

ref: 46f76ab77132a315d1e6280b1b3a47f6eb5ddd7b
parent: fa5ed8b61d58e141790c263eba6caea2c67945b8
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Nov 6 10:11:18 EST 2022

cons: fix 'check' command

we would only scan the snapshot tree, this fixes it so we scan all trees

--- a/check.c
+++ b/check.c
@@ -124,8 +124,8 @@
 			case Oclearb:	/* delete kvp if exists */
 				break;
 			case Owstat:		/* kvp dirent */
-				if((my.v[0] & ~(Owsize|Owmode|Owmtime)) != 0){
-					fprint(2, "invalid stat op %x\n", my.v[0]);
+				if((my.v[0] & ~(Owsize|Owmode|Owmtime|Owatime|Owuid|Owgid|Owmuid)) != 0){
+					fprint(fd, "invalid stat op %x\n", my.v[0]);
 					fail++;
 				}
 				break;
@@ -179,6 +179,9 @@
 checkfs(int fd)
 {
 	int ok, height;
+	char *e, pfx[1], name[Keymax+1];
+	Tree *t;
+	Scan s;
 	Blk *b;
 
 	ok = 1;
@@ -185,6 +188,37 @@
 	if(badfree())
 		ok = 0;
 	if((b = getroot(&fs->snap, &height)) != nil){
+		if(badblk(fd, b, height-1, nil, 0))
+			ok = 0;
+		dropblk(b);
+	}
+	pfx[0] = Klabel;
+	btnewscan(&s, pfx, 1);
+	if((e = btenter(&fs->snap, &s)) != nil){
+		fprint(fd, "scanning snapshots: %s\n", e);
+		return 0;
+	}
+	while(1){
+		if((e = btnext(&fs->snap, &s, &s.kv)) != nil){
+			fprint(fd, "invalid snapshot tree: %s\n", e);
+			ok = 0;
+			break;
+		}
+		if(s.done)
+			break;
+		memcpy(name, s.kv.k+1, s.kv.nk-1);
+		name[s.kv.nk-1] = 0;
+		if((t = openlabel(name)) == nil){
+			fprint(2, "invalid snap label %s\n", name);
+			ok = 0;
+			break;
+		}
+		if((b = getroot(t, &height)) != nil){
+			if(badblk(fd, b, height-1, nil, 0))
+				ok = 0;
+			dropblk(b);
+			continue;
+		}
 		if(badblk(fd, b, height-1, nil, 0))
 			ok = 0;
 		dropblk(b);
--- a/cons.c
+++ b/cons.c
@@ -284,7 +284,7 @@
 	{.name="sync",	.sub=nil,	.minarg=0, .maxarg=0, .fn=syncfs},
 	{.name="halt",	.sub=nil,	.minarg=0, .maxarg=0, .fn=haltfs},
 	{.name="snap",	.sub=nil,	.minarg=2, .maxarg=2, .fn=snapfs},
-	{.name="check",	.sub=nil,	.minarg=1, .maxarg=1, .fn=fsckfs},
+	{.name="check",	.sub=nil,	.minarg=0, .maxarg=0, .fn=fsckfs},
 	{.name="help",	.sub=nil,	.minarg=0, .maxarg=0, .fn=help},
 	{.name="df",	.sub=nil, 	.minarg=0, .maxarg=0, .fn=showdf},
 	{.name="users",	.sub=nil,	.minarg=0, .maxarg=1, .fn=refreshusers},