code: mafs

Download patch

ref: cfb63eceee23064149992ca27a04c9679d4c2cf0
parent: 0325bdc87b12a33c16b792c6ed50400b8ffce325
author: 9ferno <gophone2015@gmail.com>
date: Mon Jan 9 22:46:29 EST 2023

more error routines out of misc.c to avoid their dependency

--- /dev/null
+++ b/error.c
@@ -1,0 +1,42 @@
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "fns.h"
+
+s8 envpidx = -1;		/* the index in _privates holding the Errenv location. hack: hoping that this will be the same across all processes */
+Errenv **envpp = nil;
+
+int
+waserror(void)
+{
+	Errenv *env = _privates[envpidx];
+	++env->nlabel;
+	return setjmp(env->label[env->nlabel-1]);
+}
+
+void
+poperror(void)
+{
+	Errenv *env = *envpp;
+	--env->nlabel;
+}
+
+void
+nexterror(void)
+{
+	Errenv *env = _privates[envpidx];
+	longjmp(env->label[--env->nlabel], 1);
+}
+
+void
+error(s8 *fmt, ...)
+{
+	va_list arg;
+	char buf[ERRMAX];
+
+	va_start(arg, fmt);
+	vseprint(buf, buf+ERRMAX, fmt, arg);
+	va_end(arg);
+	errstr(buf, ERRMAX);
+	nexterror();
+}
--- a/misc.c
+++ b/misc.c
@@ -3,9 +3,6 @@
 #include "dat.h"
 #include "fns.h"
 
-s8 envpidx = -1;		/* the index in _privates holding the Errenv location. hack: hoping that this will be the same across all processes */
-Errenv **envpp = nil;
-
 void
 chkrunlock(RWLock *q)
 {
@@ -94,40 +91,4 @@
 emalloc(u32 sz)
 {
 	return mallocz((ulong)sz, 1);
-}
-
-int
-waserror(void)
-{
-	Errenv *env = _privates[envpidx];
-	++env->nlabel;
-	return setjmp(env->label[env->nlabel-1]);
-}
-
-void
-poperror(void)
-{
-	Errenv *env = *envpp;
-	--env->nlabel;
-}
-
-void
-nexterror(void)
-{
-	Errenv *env = _privates[envpidx];
-	longjmp(env->label[--env->nlabel], 1);
-}
-
-void
-error(s8 *fmt, ...)
-{
-	Errenv *env = _privates[envpidx];
-	va_list arg;
-	char buf[ERRMAX];
-
-	va_start(arg, fmt);
-	vseprint(buf, buf+ERRMAX, fmt, arg);
-	va_end(arg);
-	errstr(buf, ERRMAX);
-	nexterror();
 }
--- a/mkfile
+++ b/mkfile
@@ -10,6 +10,7 @@
 	dat.$O\
 	dentry.$O\
 	dev.$O\
+	error.$O\
 	iobuf.$O\
 	misc.$O\
 	names.$O\
@@ -41,28 +42,28 @@
 	test -d /sys/man/4 && cp man/mafs.4 /sys/man/4/mafs
 	test -d /sys/man/8 && cp man/mafs.8 /sys/man/8/mafs
 
-$O.fsok:	blk.$O dat.$O dev.$O misc.$O tag.$O fsok.$O
+$O.fsok:	blk.$O dat.$O dev.$O error.$O misc.$O tag.$O fsok.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.updatefrees:	blk.$O dat.$O dev.$O misc.$O tag.$O updatefrees.$O
+$O.updatefrees:	blk.$O dat.$O dev.$O error.$O misc.$O tag.$O updatefrees.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.unused:	blk.$O dat.$O dev.$O unused.$O misc.$O
+$O.unused:	blk.$O dat.$O dev.$O error.$O unused.$O misc.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.used:	blk.$O dat.$O dev.$O misc.$O tag.$O used.$O
+$O.used:	blk.$O dat.$O dev.$O error.$O misc.$O tag.$O used.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.free:	blk.$O dat.$O dev.$O free.$O misc.$O tag.$O
+$O.free:	blk.$O dat.$O dev.$O error.$O free.$O misc.$O tag.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.block:	blk.$O dat.$O dev.$O misc.$O tag.$O block.$O
+$O.block:	blk.$O dat.$O dev.$O error.$O misc.$O tag.$O block.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.find:	blk.$O dat.$O dev.$O misc.$O tag.$O find.$O
+$O.find:	blk.$O dat.$O dev.$O error.$O misc.$O tag.$O find.$O
 	$LD $LDFLAGS -o $target $prereq
 
-$O.reconcile:	dat.$O misc.$O reconcile.$O
+$O.reconcile:	dat.$O misc.$O error.$O reconcile.$O
 	$LD $LDFLAGS -o $target $prereq
 
 $O.loader:	$OFILES
--- a/tests/sizes.c
+++ b/tests/sizes.c
@@ -8,19 +8,6 @@
 {
 	int t;
 	u64 n;
-	Errenv env;
-
-	envpp = privalloc();
-	envpidx = _nprivates;	/* the index in _privates holding the Errenv location */
-	*envpp = &env;
-	if(waserror()){
-		print(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
-			env.nlabel,
-			env.label[0][JMPBUFPC], env.label[1][JMPBUFPC],
-			env.label[2][JMPBUFPC], env.label[3][JMPBUFPC],
-			env.label[4][JMPBUFPC], env.label[5][JMPBUFPC]);
-		exits("error");
-	}
 
 	print("Blocksize %llud Maxdatablockunits %d\n",
 			Blocksize, Maxdatablockunits);
--- a/tests/testconfig.c
+++ b/tests/testconfig.c
@@ -23,19 +23,6 @@
 main(int argc, char *argv[])
 {
 	s8 buf[Ddatasize];
-	Errenv env;
-
-	envpp = privalloc();
-	envpidx = _nprivates;	/* the index in _privates holding the Errenv location */
-	*envpp = &env;
-	if(waserror()){
-		print(0, "err stack %d: %lux %lux %lux %lux %lux %lux",
-			env.nlabel,
-			env.label[0][JMPBUFPC], env.label[1][JMPBUFPC],
-			env.label[2][JMPBUFPC], env.label[3][JMPBUFPC],
-			env.label[4][JMPBUFPC], env.label[5][JMPBUFPC]);
-		exits("error");
-	}
 
 	ARGBEGIN{
 	default:	usage();