shithub: gefs

Download patch

ref: d6d67651e5c89df7f767705e7eb56aa2b0bb439e
parent: 5c9d1ecdfb26ab64d8039d8e536d265e2cf8b774
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Oct 25 17:46:46 EDT 2021

cons: extract into its own file

--- /dev/null
+++ b/cons.c
@@ -1,0 +1,48 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <avl.h>
+
+#include "dat.h"
+#include "fns.h"
+
+void
+runcons(void *pfd)
+{
+	char buf[256], *arg[4];
+	int fd, n, narg;
+
+	fd = (uintptr)pfd;
+	while(1){
+		if((n = read(fd, buf, sizeof(buf)-1)) == -1)
+			break;
+		buf[n] = 0;
+		narg = tokenize(buf, arg, nelem(arg));
+		if(narg == 0 || strlen(arg[0]) == 0)
+			continue;
+		if(strcmp(arg[0], "show") == 0){
+			switch(narg){
+			case 1:
+				showfs(fd, "show");
+				break;
+			case 2:
+				if(strcmp(arg[1], "fid") == 0){
+					showfids(fd);
+					break;
+				}
+				if(strcmp(arg[1], "cache") == 0){
+					showcache(fd);
+					break;
+				}
+				/* wet floor */
+			default:
+				fprint(fd, "show me yours first\n");
+			}
+		}else if(strcmp(arg[0], "check") == 0)
+			checkfs();
+		else if(strcmp(arg[0], "dbg") && narg == 2)
+			debug = atoi(arg[1]);
+		else
+			fprint(fd, "unknown command %s\n", arg[0]);
+	}
+}
--- a/fns.h
+++ b/fns.h
@@ -57,6 +57,7 @@
 void	showblk(Blk*, char*, int);
 void	showpath(Path*, int);
 void	showfs(int, char*);
+void	showfids(int);
 void	showcache(int);
 void	showfree(char*);
 int	checkfs(void);
@@ -98,7 +99,7 @@
 void	runfs(void*);
 void	runwrite(void*);
 void	runread(void*);
-void	runctl(void*);
+void	runcons(void*);
 
 /* it's in libc... */
 extern int cas(long *, long, long);
--- a/fs.c
+++ b/fs.c
@@ -1123,44 +1123,3 @@
 		}
 	}
 }
-
-void
-runctl(void *pfd)
-{
-	char buf[256], *arg[4];
-	int fd, n, narg;
-
-	fd = (uintptr)pfd;
-	while(1){
-		if((n = read(fd, buf, sizeof(buf)-1)) == -1)
-			break;
-		buf[n] = 0;
-		narg = tokenize(buf, arg, nelem(arg));
-		if(narg == 0 || strlen(arg[0]) == 0)
-			continue;
-		if(strcmp(arg[0], "show") == 0){
-			switch(narg){
-			case 1:
-				showfs(fd, "show");
-				break;
-			case 2:
-				if(strcmp(arg[1], "fid") == 0){
-					showfids(fd);
-					break;
-				}
-				if(strcmp(arg[1], "cache") == 0){
-					showcache(fd);
-					break;
-				}
-				/* wet floor */
-			default:
-				fprint(fd, "show me yours first\n");
-			}
-		}else if(strcmp(arg[0], "check") == 0)
-			checkfs();
-		else if(strcmp(arg[0], "dbg") && narg == 2)
-			debug = atoi(arg[1]);
-		else
-			fprint(fd, "unknown command %s\n", arg[0]);
-	}
-}
--- a/main.c
+++ b/main.c
@@ -205,7 +205,7 @@
 		srvfd = postfd(srvname, "");
 		ctlfd = postfd(srvname, ".cmd");
 		loadfs(argv[0]);
-		launch(runctl, (void*)ctlfd, "ctl");
+		launch(runcons, (void*)ctlfd, "ctl");
 		launch(runwrite, nil, "writeio");
 		launch(runread, nil, "readio");
 //		launch(runfs, (void*)srvfd, "fs");
--- a/mkfile
+++ b/mkfile
@@ -5,6 +5,7 @@
 	blk.$O\
 	cache.$O\
 	check.$O\
+	cons.$O\
 	fs.$O\
 	hash.$O\
 	load.$O\