shithub: gefs

Download patch

ref: 51d16fc61273db6d88691e9777066b70cbb397a1
parent: 803f04ef814a62635631a90baff43d631e5ed47c
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Dec 23 15:08:35 EST 2023

fs: add check for data blocks

--- a/check.c
+++ b/check.c
@@ -107,8 +107,6 @@
 		if(c != nil && checktree(fd, c, h - 1, &y, nil))
 			fail++;
 		dropblk(c);
-	}
-	if(b->type == Tpivot){
 		if(b->nbuf > 0){
 			getmsg(b, 0, &mx);
 			if(hi && keycmp(&mx, hi) >= 0){
@@ -197,6 +195,32 @@
 }
 
 static int
+checkdata(int, Tree *t)
+{
+	char pfx[1];
+	Bptr bp;
+	Scan s;
+	Blk *b;
+
+	pfx[0] = Klabel;
+	btnewscan(&s, pfx, 1);
+	btenter(t, &s);
+	while(1){
+		if(!btnext(&s, &s.kv))
+			break;
+		bp = unpackbp(s.kv.v, s.kv.nv);
+		if(isfree(bp.addr)){
+			fprint(2, "free block in use: %B\n", bp);
+			error("free block in use");
+		}
+		b = getblk(bp, GBraw);
+		dropblk(b);
+	}
+	btexit(&s);
+	return 0;
+}
+
+static int
 checkdlist(int fd)
 {
 	char pfx[1];
@@ -266,6 +290,8 @@
 		fprint(fd, "checking snap %s: %B\n", name, t->bp);
 		b = getroot(t, &height);
 		if(checktree(fd, b, height-1, nil, 0))
+			ok = 0;
+		if(checkdata(fd, t))
 			ok = 0;
 		dropblk(b);
 		poperror();