code: mafs

Download patch

ref: 0906df260dba0a482190c91103cb3041baf704fc
parent: 9b76881a8e11c44aae5dfd447e1cd1bc074ec9f3
author: 9ferno <gophone2015@gmail.com>
date: Sat Dec 3 13:34:14 EST 2022

user friendly error message after an unsafe shutdown

--- a/dentry.c
+++ b/dentry.c
@@ -619,8 +619,11 @@
 	s8 *buf;
 
 	size = readfilesize(Bdfrees, Qpfrees);
-	if(size == 0)
-		panic("loadfrees size == 0");
+	if(size == 0){
+		panic("There are no free blocks.\n"
+				"If there was an unsafe shutdown,"
+				" use \'disk/fsck %s\' to correct the disk state\n", devfile);
+	}
 	buf = emalloc9p(size);
 	if(buf == nil)
 		panic("loadfrees: nil emalloc of %llud bytes", size);
--- a/mkfile
+++ b/mkfile
@@ -35,6 +35,11 @@
 </sys/src/cmd/mkmany
 # LDFLAGS=-p
 
+install:V:
+	for (i in $TARG)
+		mk $MKFLAGS $i.install
+	cp fsck $BIN/
+
 $O.fsok:	blk.$O dat.$O dev.$O misc.$O tag.$O fsok.$O
 	$LD $LDFLAGS -o $target $prereq
 
--- a/sub.c
+++ b/sub.c
@@ -535,9 +535,19 @@
 		return;
 	}
 	s = (Dentry*)sb->new;
-	if(s->fsok != 1 || config.size != size){
-		dprint("s->fsok %d config.size %llud size %llud\n",
-				s->fsok, config.size, size);
+	if(config.size != size){
+		dprint("corrupted disk or disk size changed:"
+				" config.size %llud size %llud\n"
+				"This is an unrecoverable situation."
+				" Ream the disk and start over.\n",
+				config.size, size);
+		panic(errstring[Edirty]);
+	}
+	if(s->fsok != 1){
+		panic("There was an unsafe shutdown:\n"
+				"	use \'disk/fsck %s\' to check the disk state.\n"
+				"	Or, use \'disk/fsok %s\' to flip the fsok flag.\n",
+				devfile, devfile);
 		panic(errstring[Edirty]);
 	}