diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | appl/cmd/disk/mkext.b | 45 | ||||
| -rw-r--r-- | appl/cmd/disk/mkfs.b | 140 | ||||
| -rw-r--r-- | dis/disk/mkext.dis | bin | 6861 -> 6519 bytes | |||
| -rw-r--r-- | dis/disk/mkfs.dis | bin | 11333 -> 10447 bytes | |||
| -rw-r--r-- | include/version.h | 2 | ||||
| -rw-r--r-- | man/8/mkfs | 154 |
7 files changed, 159 insertions, 185 deletions
@@ -1,3 +1,6 @@ +20090809 + bring mkfs(8) up to date (issue 176) + remove -q options from mkfs and mkext (-q was a transitional option to suppress quoting of file names) 20090806 increase `backlog' value in all listen calls in hosted Inferno (emu/*/ipif*.c) [powerman] 20090805 diff --git a/appl/cmd/disk/mkext.b b/appl/cmd/disk/mkext.b index fc13f2fe..63a2418c 100644 --- a/appl/cmd/disk/mkext.b +++ b/appl/cmd/disk/mkext.b @@ -30,17 +30,10 @@ tflag := 0; hflag := 0; vflag := 0; fflag := 0; -qflag := 1; stderr: ref Sys->FD; bout: ref Iobuf; argv0 := "mkext"; -usage() -{ - fprint(stderr, "Usage: mkext [-h] [-u] [-v] [-f] [-t] [-q] [-d dest-fs] [file ...]\n"); - raise "fail:usage"; -} - init(nil: ref Draw->Context, args: list of string) { sys = load Sys Sys->PATH; @@ -59,12 +52,11 @@ init(nil: ref Draw->Context, args: list of string) destdir := ""; arg->init(args); + arg->setusage("mkext [-h] [-d destdir] [-T] [-u] [-v] [file ...]"); while((c := arg->opt()) != 0) case c { 'd' => - destdir = arg->arg(); - if(destdir == nil) - error("destination directory name missing"); + destdir = arg->earg(); 'f' => fflag = 1; @@ -75,14 +67,13 @@ init(nil: ref Draw->Context, args: list of string) error(sys->sprint("can't access standard output: %r")); 'u' => uflag = 1; - 't' => + tflag = 1; + 't' or 'T' => tflag = 1; 'v' => vflag = 1; - 'q' => - qflag = 0; * => - usage(); + arg->usage(); } args = arg->argv(); @@ -94,14 +85,8 @@ init(nil: ref Draw->Context, args: list of string) fprint(stderr, "done\n"); quit(nil); } - fields: list of string; - nf: int; - if(qflag){ - fields = str->unquoted(p); - nf = len fields; - }else - (nf, fields) = sys->tokenize(p, " \t\n"); - if(nf != NFLDS){ + fields := str->unquoted(p); + if(len fields != NFLDS){ warn("too few fields in file header"); continue; } @@ -126,8 +111,8 @@ init(nil: ref Draw->Context, args: list of string) } name = destdir+name; if(hflag){ - bout.puts(sys->sprint("%s %s %s %s %ud %bd\n", - quoted(name), octal(mode), uid, gid, mtime, bytes)); + bout.puts(sys->sprint("%q %s %s %s %ud %bd\n", + name, octal(mode), uid, gid, mtime, bytes)); if(bytes != big 0) seekpast(bytes); continue; @@ -212,7 +197,6 @@ mkdir(name: string, mode: int, mtime: int, uid: string, gid: string) if(uflag){ d.uid = uid; d.gid = gid; - d.mtime = mtime; } d.mode = mode; if(sys->wstat(name, d) < 0) @@ -272,7 +256,7 @@ extract(name: string, mode: int, mtime: int, uid: string, gid: string, bytes: bi if(p == nil) p = name; d.name = p; - if(tflag || uflag) + if(tflag) d.mtime = mtime; if(uflag){ d.uid = uid; @@ -366,12 +350,3 @@ create(name : string, rw : int, mode : int) : ref Sys->FD } return fd; } - -quoted(s: string): string -{ - if(qflag) - for(i:=0; i<len s; i++) - if((c := s[i]) == ' ' || c == '\t' || c == '\n' || c == '\'') - return str->quoted(s :: nil); - return s; -} diff --git a/appl/cmd/disk/mkfs.b b/appl/cmd/disk/mkfs.b index 8b07aa8f..4c05fdf6 100644 --- a/appl/cmd/disk/mkfs.b +++ b/appl/cmd/disk/mkfs.b @@ -55,7 +55,6 @@ modes: int; ream: int; debug: int; xflag: int; -qflag := 1; sfd: ref Sys->FD; fskind: int; # Kfs, Fs, Archive user: string; @@ -63,12 +62,6 @@ stderr: ref Sys->FD; usrid, grpid : string; setuid: int; -usage() -{ - fprint(stderr, "usage: %s [-apqrvx] [-d root] [-n kfsname] [-s src-fs] [-u userfile] [-z n] proto ...\n", prog); - quit("usage"); -} - init(nil: ref Draw->Context, args: list of string) { sys = load Sys Sys->PATH; @@ -80,7 +73,7 @@ init(nil: ref Draw->Context, args: list of string) stderr = sys->fildes(2); if(arg == nil) - error(sys->sprint("can't load %s: %r", Arg->PATH)); + error(sys->sprint("can't load %q: %r", Arg->PATH)); user = getuser(); if(user == nil) @@ -95,6 +88,7 @@ init(nil: ref Draw->Context, args: list of string) users = nil; fskind = Kfs; # i suspect Inferno default should be different arg->init(args); + arg->setusage("mkfs [-aprvxS] [-d root] [-n kfscmdname] [-s src-fs] [-u userfile] [-z n] [-G group] [-U user] proto ..."); while((c := arg->opt()) != 0) case c { 'a' => @@ -105,49 +99,52 @@ init(nil: ref Draw->Context, args: list of string) error(sys->sprint("can't open standard output for archive: %r")); 'd' => fskind = Fs; - newroot = reqarg("destination directory (-d)"); + newroot = arg->earg(); 'D' => debug = 1; 'n' => - name = reqarg("kfs instance name (-n)"); + name = arg->earg(); 'p' => modes = 1; 'q' => - qflag = 0; + ; 'r' => ream = 1; 's' => - oldroot = reqarg("source directory (-d)"); + oldroot = arg->earg(); 'u' => - users = reqarg("/adm/users file (-u)"); + users = arg->earg(); 'v' => verb = 1; 'x' => xflag = 1; 'z' => - (buflen, nil) = str->toint(reqarg("buffer length (-z)"), 10); + (buflen, nil) = str->toint(arg->earg(), 10); buflen -= 8; # qid.path and tag at end of each kfs block 'U' => - usrid = reqarg("user name (-U)"); + usrid = arg->earg(); 'G' => - grpid = reqarg("group name (-G)"); + grpid = arg->earg(); 'S' => setuid = 1; * => - usage(); + arg->usage(); } args = arg->argv(); if(args == nil) - usage(); + arg->usage(); buf = array [buflen] of byte; zbuf = array [buflen] of { * => byte 0 }; - mountkfs(name); + if(name != nil) + openkfscmd(name); kfscmd("allow"); - proto = "users"; - setusers(); + if(users != nil){ + proto = "users"; # for diagnostics + setusers(); + } cputype = getenv("cputype"); if(cputype == nil) cputype = "dis"; @@ -159,7 +156,7 @@ init(nil: ref Draw->Context, args: list of string) b = bufio->open(proto, Sys->OREAD); if(b == nil){ - fprint(stderr, "%s: can't open %s: %r: skipping\n", prog, proto); + fprint(stderr, "%s: can't open %q: %r: skipping\n", prog, proto); errs++; continue; } @@ -190,15 +187,6 @@ quit(why: string) exit; } -reqarg(what: string): string -{ - if((o := arg->arg()) == nil){ - sys->fprint(stderr, "%s: missing %s\n", prog, what); - quit("usage"); - } - return o; -} - mkfs(me: ref File, level: int) { (child, fp) := getfile(me); @@ -227,7 +215,7 @@ mktree(me: ref File, rec: int, filesonly: int) { fd := sys->open(oldfile, Sys->OREAD); if(fd == nil){ - warn(sys->sprint("can't open %s: %r", oldfile)); + warn(sys->sprint("can't open %q: %r", oldfile)); return; } @@ -282,7 +270,7 @@ mkfile(f: ref File): int { (i, dir) := sys->stat(oldfile); if(i < 0){ - warn(sys->sprint("can't stat file %s: %r", oldfile)); + warn(sys->sprint("can't stat file %q: %r", oldfile)); skipdir(); return 0; } @@ -294,7 +282,7 @@ copyfile(f: ref File, d: ref Dir, permonly: int): int mode: int; if(xflag && bout != nil){ - bout.puts(sys->sprint("%s\t%d\t%bd\n", quoted(f.new), d.mtime, d.length)); + bout.puts(sys->sprint("%q\t%d\t%bd\n", f.new, d.mtime, d.length)); return (d.mode & Sys->DMDIR) != 0; } d.name = f.elem; @@ -329,7 +317,7 @@ copyfile(f: ref File, d: ref Dir, permonly: int): int mkdir(d); else { if(verb) - fprint(stderr, "%s\n", f.new); + fprint(stderr, "%q\n", f.new); copy(d); } }else if(modes){ @@ -338,7 +326,7 @@ copyfile(f: ref File, d: ref Dir, permonly: int): int nd.mtime = d.mtime; nd.gid = d.gid; if(sys->wstat(newfile, nd) < 0) - warn(sys->sprint("can't set modes for %s: %r", f.new)); + warn(sys->sprint("can't set modes for %q: %r", f.new)); # do the uid separately since different file systems object nd = sys->nulldir; nd.uid = d.uid; @@ -368,7 +356,7 @@ copy(d: ref Dir) f := sys->open(oldfile, Sys->OREAD); if(f == nil){ - warn(sys->sprint("can't open %s: %r", oldfile)); + warn(sys->sprint("can't open %q: %r", oldfile)); return; } t = nil; @@ -381,7 +369,7 @@ copy(d: ref Dir) cptmp := dname+"__mkfstmp"; t = sys->create(cptmp, Sys->OWRITE, 8r666); if(t == nil){ - warn(sys->sprint("can't create %s: %r", newfile)); + warn(sys->sprint("can't create %q: %r", newfile)); return; } } @@ -389,7 +377,7 @@ copy(d: ref Dir) for(tot := big 0;; tot += big n){ n = sys->read(f, buf, buflen); if(n < 0){ - warn(sys->sprint("can't read %s: %r", oldfile)); + warn(sys->sprint("can't read %q: %r", oldfile)); break; } if(n == 0) @@ -399,9 +387,9 @@ copy(d: ref Dir) error(sys->sprint("write error: %r")); }else if(buf[0:buflen] == zbuf[0:buflen]){ if(sys->seek(t, big buflen, 1) < big 0) - error(sys->sprint("can't write zeros to %s: %r", newfile)); + error(sys->sprint("can't write zeros to %q: %r", newfile)); }else if(sys->write(t, buf, n) < n) - error(sys->sprint("can't write %s: %r", newfile)); + error(sys->sprint("can't write %q: %r", newfile)); } f = nil; if(tot != d.length){ @@ -420,11 +408,11 @@ copy(d: ref Dir) nd.mode = d.mode; nd.mtime = d.mtime; if(sys->fwstat(t, nd) < 0) - error(sys->sprint("can't move tmp file to %s: %r", newfile)); + error(sys->sprint("can't move tmp file to %q: %r", newfile)); nd = sys->nulldir; nd.gid = d.gid; if(sys->fwstat(t, nd) < 0) - warn(sys->sprint("can't set group id of %s to %s: %r", newfile, d.gid)); + warn(sys->sprint("can't set group id of %q to %q: %r", newfile, d.gid)); nd.gid = nil; nd.uid = d.uid; sys->fwstat(t, nd); @@ -444,16 +432,16 @@ mkdir(d: ref Dir) if(fd == nil){ (i, d1) := sys->stat(newfile); if(i < 0 || !(d1.mode & Sys->DMDIR)) - error(sys->sprint("can't create %s", newfile)); + error(sys->sprint("can't create %q", newfile)); if(sys->wstat(newfile, nd) < 0) - warn(sys->sprint("can't set modes for %s: %r", newfile)); + warn(sys->sprint("can't set modes for %q: %r", newfile)); nd = sys->nulldir; nd.uid = d.uid; sys->wstat(newfile, nd); return; } if(sys->fwstat(fd, nd) < 0) - warn(sys->sprint("can't set modes for %s: %r", newfile)); + warn(sys->sprint("can't set modes for %q: %r", newfile)); nd = sys->nulldir; nd.uid = d.uid; sys->fwstat(fd, nd); @@ -461,8 +449,8 @@ mkdir(d: ref Dir) arch(d: ref Dir) { - bout.puts(sys->sprint("%s %s %s %s %ud %bd\n", - quoted(newfile), octal(d.mode), d.uid, d.gid, d.mtime, d.length)); + bout.puts(sys->sprint("%q %uo %q %q %ud %bd\n", + newfile, d.mode, d.uid, d.gid, d.mtime, d.length)); } mkpath(prefix, elem: string): string @@ -543,11 +531,11 @@ getfile(old: ref File): (ref File, big) f = ref File; (elem, p) = getname(p); if(debug) - fprint(stderr, "getfile: %s root %s\n", elem, old.new); + fprint(stderr, "getfile: %q root %q\n", elem, old.new); f.new = mkpath(old.new, elem); (nil, f.elem) = str->splitr(f.new, "/"); if(f.elem == nil) - error(sys->sprint("can't find file name component of %s", f.new)); + error(sys->sprint("can't find file name component of %q", f.new)); (f.mode, p) = getmode(p); (f.uid, p) = getname(p); if(f.uid == nil) @@ -585,7 +573,7 @@ getname(p: string): (string, string) for(; (c = p[0]) != '\n' && (c != ' ' && c != '\t' || quoted); p = p[1:]){ if(quoted && c == '\'' && p[1] == '\'') p = p[1:]; - else if(c == '\'' && qflag){ + else if(c == '\''){ quoted = !quoted; continue; } @@ -594,7 +582,7 @@ getname(p: string): (string, string) if(len s > 0 && s[0] == '$'){ s = getenv(s[1:]); if(s == nil) - error(sys->sprint("can't read environment variable %s", s)); + error(sys->sprint("can't read environment variable %q", s)); } return (s, p); } @@ -654,13 +642,6 @@ getmode(p: string): (int, string) return (m|v, p); } -quoted(s: string): string -{ - if(qflag) - return sys->sprint("%q", s); - return s; -} - setusers() { if(fskind != Kfs) @@ -693,30 +674,14 @@ setusers() modes = m; } -# this isn't right for the current #K -mountkfs(name: string) +openkfscmd(name: string) { - kname: string; - if(fskind != Kfs) return; - if(name != nil) - kname = sys->sprint("/srv/kfs.%s", name); - else - kname = "/srv/kfs"; - fd := sys->open(kname, Sys->ORDWR); - if(fd == nil){ - fprint(stderr, "%s: can't open %s: %r\n", prog, kname); - quit("open kfs"); - } - if(sys->mount(fd, nil, "/n/kfs", Sys->MREPL|Sys->MCREATE, "") < 0){ - fprint(stderr, "%s: can't mount kfs on /n/kfs: %r\n", prog); - quit("mount kfs"); - } - kname += ".cmd"; + kname := sys->sprint("/chan/kfs.%s.cmd", name); sfd = sys->open(kname, Sys->ORDWR); if(sfd == nil){ - fprint(stderr, "%s: can't open %s: %r\n", prog, kname); + fprint(stderr, "%s: can't open %q: %r\n", prog, kname); quit("open kfscmd"); } } @@ -747,7 +712,7 @@ kfscmd(cmd: string) error(s: string) { - fprint(stderr, "%s: %s: %d: %s\n", prog, proto, lineno, s); + fprint(stderr, "%s: %s:%d: %s\n", prog, proto, lineno, s); kfscmd("disallow"); kfscmd("sync"); quit("error"); @@ -755,24 +720,13 @@ error(s: string) warn(s: string) { - fprint(stderr, "%s: %s: %d: %s\n", prog, proto, lineno, s); + fprint(stderr, "%s: %s:%d: %s\n", prog, proto, lineno, s); } printfile(f: ref File) { if(f.old != nil) - fprint(stderr, "%s from %s %s %s %s\n", f.new, f.old, f.uid, f.gid, octal(f.mode)); + fprint(stderr, "%q from %q %q %q %uo\n", f.new, f.old, f.uid, f.gid, f.mode); else - fprint(stderr, "%s %s %s %s\n", f.new, f.uid, f.gid, octal(f.mode)); -} - -octal(i: int): string -{ - s := ""; - do { - t: string; - t[0] = '0' + (i&7); - s = t+s; - } while((i = (i>>3)&~(7<<29)) != 0); - return s; + fprint(stderr, "%q %q %q %uo\n", f.new, f.uid, f.gid, f.mode); } diff --git a/dis/disk/mkext.dis b/dis/disk/mkext.dis Binary files differindex 8fa5ad23..02e5901f 100644 --- a/dis/disk/mkext.dis +++ b/dis/disk/mkext.dis diff --git a/dis/disk/mkfs.dis b/dis/disk/mkfs.dis Binary files differindex b6b8b6bc..ea8799f3 100644 --- a/dis/disk/mkfs.dis +++ b/dis/disk/mkfs.dis diff --git a/include/version.h b/include/version.h index 0cfddbce..1c008024 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20090806)" +#define VERSION "Fourth Edition (20090809)" @@ -3,7 +3,9 @@ mkfs, mkext \- archive or update a file system .SH SYNOPSIS .B disk/mkfs -.RB [ -aprvx ] +.RB [ -aprvxS ] +.RB [ -d +.IR dest ] .RB [ -n .IR name ] .RB [ -s @@ -12,15 +14,23 @@ mkfs, mkext \- archive or update a file system .IR users ] .RB [ -z .IR n ] +.RB [ -G +.IR group ] +.RB [ -U +.IR user ] .I proto ... .PP .B disk/mkext .RB [ -d .IR name ] -.RB [ -u ] +.RB [ -f ] .RB [ -h ] +.RB [ -T ] +.RB [ -u ] .RB [ -v ] +[ .I file ... +] .SH DESCRIPTION .I Mkfs copies files from the file tree @@ -30,24 +40,22 @@ copies files from the file tree to a .B kfs file system (see -.IR kfs (4)). -The kfs service is mounted on -.BR /n/kfs , -and -.BR /adm/users , -if it exists, is copied to -.BR /n/kfs/adm/users . +.IR kfs (4)) +assumed to be mounted on +.I dest +(default: +.BR /n/kfs ). The .I proto files are read, and any files specified in them that are out of date are copied to -.BR /n/kfs . +.IR dest . See .IR proto (6) for the description of file system prototype files. .PP .I Mkfs -copies only those files that are out of date. +by default copies only those files that are out of date. Such a file is first copied into a temporary file in the appropriate destination directory and then moved to the destination file. @@ -61,88 +69,122 @@ are not updated and not removed. The options to .I mkfs are: -.TF "s source" +.TF "-s source" .TP -.B a +.B -a Instead of writing to a .B kfs file system, write an archive file to standard output, suitable for .IR mkext . All files in -.IR proto , -not just those out of date, are archived. +.I proto +are archived, +not just those out of date. .TP -.B x +.B -x For use with .BR -a , this option writes a list of file names, dates, and sizes to standard output rather than producing an archive file. .TP -.BI "n " name +.BI -n " name" Use -.RI kfs. name -as the name of the kfs service (default -.BR kfs ). +.BI kfs. name .cmd +as the name of the command file for the +.IR kfs (4) +assumed to be mounted on +.IR dest . .TP -.B p +.B -p Update the permissions of a file even if it is up to date. .TP -.B r +.B -r Copy all files. .TP -.BI "s " source +.BI -s " source" Copy from files rooted at the tree .IR source . .TP -.BI "u " users -Copy file +.BI -u " users" +Before copying any other file, copy file .I users into -.B /adm/users -in the new system. +.IB dest /adm/users , +and if the +.B -n +option was given, also issue the +.IR kfs (4) +command +.B users +to update +.IR kfs 's +own user list. .TP -.B v +.B -v Print the names of all of the files as they are copied. .TP -.BI "z " n -Copy files assuming kfs block +.BI -z " n" +Copy files assuming +.I kfs +is using a block size of .I n -(default 1024) -bytes long. +bytes +(default 1024). If a block contains only 0-valued bytes, it is not copied. +.TP +.B -S +For use with the +.B -d +option, +make owner and group of each file copied match the original. +.TP +.BI -G " group" +Force all files copied to have the given +.IR group . +.TP +.BI -U " user" +Force all files copied to be owned by the given +.IR user . .PD .PP .I Mkext -unpacks archive files made by the +unpacks an archive created by the .B -a option of -.IR mkfs . -The -.B -d -option specifies a directory (default -.BR /n/kfs ) -to serve as the root of the unpacked file system. -The -.B -u -option, to be used only when initializing a new -.IR kfs (4) -file system, sets the owners of the files created to correspond to -those in the archive and restores the modification times of the files. -(This is only permitted at the initial load of the files into a file -system.) -Each file on the command line is unpacked in one pass through the archive. -If the file is a directory, +.IR mkfs , +read from the standard input. +If one or more files are specified on the command line, +only those files are unpacked. +If a +.I file +is a directory, all files and subdirectories of that directory are also unpacked. When a file is unpacked, the entire path is created if it does not exist. If no files are specified, the entire archive is unpacked; in this case, missing intermediate directories are not created. -The -.B -v -option prints the names and sizes of files as they are extracted; +The options are: +.TP +.BI -d " dir" +Treat +.I dir +(default +.LR / ) +as the root directory when unpacking the archive. +.TP .B -h -prints headers for the files on standard output +Print headers for the files on standard output instead of unpacking the files. +.TP +.B -T +Restore the modification times of the files. +.TP +.B -u +Set the owners of the files created to correspond to +those in the archive and restore the modification times of the files. +.TP +.B -v +Print the names and sizes of files as they are extracted. .SH EXAMPLES .PP Make an archive to establish a new file system @@ -153,7 +195,7 @@ is not referenced by .IP .EX bind '#U' /n/local -disk/mkfs -a -u files/adm.users -s /n/local proto > arch +disk/mkfs -a -s /n/local proto > arch .EE .PP Unpack that archive on another machine: @@ -168,8 +210,8 @@ disk/mkext -u -d /n/remote < arch .B /lib/proto directory of prototype files. .TP -.B /lib/proto/portproto -generic prototype file. +.B /lib/proto/all +contains a single + (archive any directory structure) .SH SOURCE .B /appl/cmd/disk/mkfs.b .br |
