ref: b7e11e6c459c75585be93fbb4823a13591c08e65
parent: 2d28717d80571e9469a59098150996b28404709f
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Aug 4 18:43:07 EDT 2025
gefs: implement '-R' flag for mounting file systems read-only
--- a/sys/man/4/gefs
+++ b/sys/man/4/gefs
@@ -4,7 +4,7 @@
.SH SYNOPSIS
.B gefs
[
-.B -ASsc
+.B -ASRsc
]
[
.B -r
@@ -89,6 +89,10 @@
as the name of the service.
If unspecified, the default service name is
.IR gefs .
+.TP
+.B -R
+Mounts file system read-only.
+No modifications will be made to the disk.
.TP
.BI "-r " user
Ream the file system, erasing all of the old data.
--- a/sys/src/cmd/gefs/main.c
+++ b/sys/src/cmd/gefs/main.c
@@ -136,7 +136,7 @@
}
static void
-initfs(vlong cachesz)
+initfs(vlong cachesz, int rdonly)
{
Bfree *f, *g;
Blk *b;
@@ -148,6 +148,7 @@
fs->trace = emalloc(tracesz, 1);
fs->ntrace = tracesz/sizeof(Trace);
}
+ fs->rdonly = rdonly;
fs->lrurz.l = &fs->lrulk;
fs->syncrz.l = &fs->synclk;
fs->bfreerz.l = &fs->bfreelk;
@@ -279,7 +280,7 @@
static void
usage(void)
{
- fprint(2, "usage: %s [-SA] [-r user] [-m mem] [-n srv] [-a net]... -f dev\n", argv0);
+ fprint(2, "usage: %s [-SARsc] [-r user] [-m mem] [-n srv] [-a net]... -f dev\n", argv0);
exits("usage");
}
@@ -286,12 +287,13 @@
void
main(int argc, char **argv)
{
- int i, srvfd, ctlfd, nann;
+ int i, srvfd, rdonly, ctlfd, nann;
char *s, *e, *ann[16];
vlong v, memsz;
Conn *c;
nann = 0;
+ rdonly = 0;
memsz = memsize();
cachesz = 25*memsz/100;
ARGBEGIN{
@@ -348,6 +350,9 @@
case 'f':
dev = EARGF(usage());
break;
+ case 'R':
+ rdonly = 1;
+ break;
default:
usage();
break;
@@ -363,7 +368,7 @@
assert(2*Msgmax < Bufspc);
assert(Treesz < Inlmax);
- initfs(cachesz);
+ initfs(cachesz, rdonly);
initshow();
errctx = privalloc();
if((*errctx = mallocz(sizeof(Errctx), 1)) == nil)
--
⑨