1implement Fsmodule; 2 3include "sys.m"; 4 sys: Sys; 5 6include "draw.m"; 7 8include "sh.m"; 9 10include "daytime.m"; 11 daytime: Daytime; 12 13include "fslib.m"; 14 fslib: Fslib; 15 Report, Value, type2s, quit: import fslib; 16 Fschan, Fsdata, Entrychan, Entry, 17 Gatechan, Gatequery, Nilentry, Option, 18 Next, Down, Skip, Quit: import Fslib; 19 20types(): string 21{ 22 return "vt-us-gs"; 23} 24 25badmod(p: string) 26{ 27 sys->fprint(sys->fildes(2), "fs: log: cannot load %s: %r\n", p); 28 raise "fail:bad module"; 29} 30 31init() 32{ 33 sys = load Sys Sys->PATH; 34 fslib = load Fslib Fslib->PATH; 35 if(fslib == nil) 36 badmod(Fslib->PATH); 37 daytime = load Daytime Daytime->PATH; 38 if(daytime == nil) 39 badmod(Daytime->PATH); 40} 41 42run(nil: ref Draw->Context, report: ref Report, 43 opts: list of Option, args: list of ref Value): ref Value 44{ 45 uid, gid: string; 46 for(; opts != nil; opts = tl opts){ 47 o := hd (hd opts).args; 48 case (hd opts).opt { 49 'u' => uid = o.s().i; 50 'g' => gid = o.s().i; 51 } 52 } 53 sync := chan of int; 54 spawn logproc(sync, (hd args).t().i, report.start("log"), uid, gid); 55 return ref Value.V(sync); 56} 57 58logproc(sync: chan of int, c: Entrychan, errorc: chan of string, uid: string, gid: string) 59{ 60 if(<-sync == 0){ 61 c.sync <-= 0; 62 quit(errorc); 63 exit; 64 } 65 c.sync <-= 1; 66 67 now := daytime->now(); 68 for(seq := 0; ((d, p, nil) := <-c.c).t0 != nil; seq++){ 69 if(uid != nil) 70 d.uid = uid; 71 if(gid != nil) 72 d.gid = gid; 73 sys->print("%ud %ud %c %q - - %uo %q %q %ud %bd%s\n", now, seq, 'a', p, d.mode, d.uid, d.gid, d.mtime, d.length, ""); 74 } 75 quit(errorc); 76} 77