implement Mount;
include "sys.m";
sys: Sys;
include "draw.m";
include "iauth.m";
iauth: Iauth;
include "arg.m";
Mount: module {
init: fn(nil: ref Draw->Context, argv: list of string);
};
init(nil: ref Draw->Context, argv: list of string)
{
sys = load Sys Sys->PATH;
iauth = load Iauth Iauth->PATH;
if(iauth == nil){
sys->fprint(sys->fildes(2), "mount: cannot load %s: %r\n", Iauth->PATH);
raise "fail:bad module";
}
iauth->init();
arg := load Arg Arg->PATH;
keyspec := "";
how := Sys->MREPL;
flags := 0;
arg->init(argv);
arg->setusage("mount [-abcA] [-k keyspec] file|addr old [spec]");
while((opt := arg->opt()) != 0){
case opt {
'a' =>
how = Sys->MAFTER;
'b' =>
how = Sys->MBEFORE;
'c' =>
flags |= Sys->MCREATE;
'A' =>
flags |= Iauth->MNOAUTH;
'k' =>
keyspec = arg->earg();
* =>
arg->usage();
}
}
argv = arg->argv();
if(len argv != 2 && len argv != 3)
arg->usage();
what := hd argv;
where := hd tl argv;
aname := "";
if(len argv == 3)
aname = hd tl tl argv;
how |= flags;
if(sys->stat(what).t0 != -1){
fd := sys->open(what, Sys->ORDWR);
if(fd == nil)
error(sys->sprint("cannot open %q: %r", what));
if(sys->mount(fd, nil, where, how & ~Iauth->MNOAUTH, aname) == -1)
error(sys->sprint("cannot mount %q on %q: %r", what, where));
return;
}
(ok, user) := iauth->mount(what, where, how, aname, keyspec);
if(ok == -1)
error(user);
}
error(e: string)
{
sys->fprint(sys->fildes(2), "mount: %s\n", e);
raise "fail:error";
}
|