From: Romano Date: Fri, 17 May 2024 08:08:34 +0000 Subject: [PATCH] ramfs: document usage and provide clearer usage errors --- diff b1e897ae44d25909ebc99992a32a93ac019b98b1 6d02b515abae742baf37cde7817ebc34cd0656d1 --- a/sys/man/4/ramfs +++ b/sys/man/4/ramfs @@ -4,7 +4,7 @@ .SH SYNOPSIS .B ramfs [ -.B -Dipsu +.B -Dipsubac ] [ .B -m @@ -15,23 +15,43 @@ .I srvname ] .SH DESCRIPTION +.PP .I Ramfs -starts a process that mounts itself (see -.IR bind (2)) -on -.I mountpoint -(default -.BR /tmp ). +implements a file tree which keeps all files in memory. +Initially the file tree is empty. +.PP The .I ramfs -process implements a file tree rooted at -.IR dir , -keeping all files in memory. -Initially the file tree is empty. +process mounts the +.IR mountpoint (or +.B /tmp , +if not provided) +with the mount flags +.B MREPL and +.B MCREATE . +The mount flags can be set explicitly +using +.B -b , +.B -a , and +.B -c , +corresponding respectively to the flags +.B MBEFORE , +.B MAFTER , or +.B MCREATE (see +.IR bind(2)). .PP The +.B -p +flag causes +.I ramfs +to make its memory `private' +(see +.IR proc (3)) +so that its files are not accessible through the debugging interface. +.PP +The .B -D -option enables a trace of general debugging messages. +flag enables a trace of general debugging messages. .PP The .B -i @@ -38,7 +58,8 @@ flag tells .I ramfs to use file descriptors 0 and 1 for its communication channel -rather than create a pipe. +rather than create a pipe or mount at +.IR mountpoint . This makes it possible to use .I ramfs as a file server on a remote machine: the file descriptors 0 @@ -47,15 +68,6 @@ to the client machine. .PP The -.B -p -flag causes -.I ramfs -to make its memory `private' -(see -.IR proc (3)) -so that its files are not accessible through the debugging interface. -.PP -The .B -s .RB ( -S ) flag causes @@ -62,17 +74,26 @@ .I ramfs to post its channel on .B /srv/ramfs -.RB ( /srv/ \fIsrvname\fR) -rather than mounting it on -.IR mountpoint , +.RB ( /srv/ \fIsrvname\fR) , enabling multiple clients to access its files. -However, it does not authenticate its clients and its +The flag also causes +.I ramfs +to not use the default +.IR mountpoint +.B /tmp , +however it will use the mountpoint +.IR mountpoint +explicitly set using the +.B -m +flag. +.I Ramfs +does not authenticate its clients and its implementation of groups is simplistic, so it should not be used for precious data. .PP The .B -u -option permits +flag permits .I ramfs to consume as much memory as needed; without it, @@ -86,4 +107,5 @@ .SH SOURCE .B /sys/src/cmd/ramfs.c .SH "SEE ALSO" -.IR bind (2) +.IR bind (2) , +.IR proc (3) --- a/sys/src/cmd/ramfs.c +++ b/sys/src/cmd/ramfs.c @@ -455,27 +455,40 @@ { char *srvname = nil; char *mtpt = "/tmp"; - int mountflags, stdio; + int marg, mountflags, stdio; fs.tree = alloctree(nil, nil, DMDIR|0777, fsdestroyfile); - mountflags = stdio = 0; + marg = mountflags = stdio = 0; ARGBEGIN{ case 'D': chatty9p++; break; case 's': + if(stdio) + sysfatal("-s cannot be used with -i flag"); srvname = "ramfs"; - mtpt = nil; + if(!marg) + mtpt = nil; break; case 'S': + if(stdio) + sysfatal("-S cannot be used with -i flag"); + if(srvname) + sysfatal("-s cannot be used with -S"); srvname = EARGF(usage()); - mtpt = nil; + if(!marg) + mtpt = nil; break; case 'm': + if(stdio) + sysfatal("-m cannot be used with -i flag"); mtpt = EARGF(usage()); + marg = 1; break; case 'i': + if(srvname || marg) + sysfatal("-i cannot be used with -s, -S, or -m flag"); stdio = 1; break; case 'p': @@ -500,14 +513,14 @@ usage(); if(stdio){ + if(mountflags) + perror("mount flags ignored when using -i"); + fs.infd = 0; fs.outfd = 1; srv(&fs); exits(0); } - - if(srvname == nil && mtpt == nil) - sysfatal("must specify -S, or -m option"); if(mountflags == 0) mountflags = MREPL | MCREATE;