summaryrefslogtreecommitdiff
path: root/appl/alphabet/main/mount.b
blob: 1b27617d7e59b48110d39260371adc05d51e48a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
implement Mount,Mainmodule;
include "sys.m";
	sys: Sys;
include "draw.m";
include "sh.m";
include "alphabet/reports.m";
	reports: Reports;
		Report, report: import reports;
include "alphabet.m";
	alphabet: Alphabet;
		Value: import alphabet;

Mount: module {};

typesig(): string
{
	return "rws-a-b-c-xs";
}

init()
{
	sys = load Sys Sys->PATH;
	alphabet = load Alphabet Alphabet->PATH;
	reports = load Reports Reports->PATH;
}

quit()
{
}

After, Before, Create: con 1<<iota;

run(nil: ref Draw->Context, report: ref Reports->Report, nil: chan of string,
		opts: list of (int, list of ref Alphabet->Value),
		args: list of ref Alphabet->Value): ref Alphabet->Value
{
	flag := Sys->MREPL;
	aname := "";
	for(; opts != nil; opts = tl opts){
		case (hd opts).t0 {
		'a' =>
			flag = After & (flag&Sys->MCREATE);
		'b' =>
			flag = Before & (flag&Sys->MCREATE);
		'c' =>
			flag |= Create;
		'x' =>
			aname = (hd (hd opts).t1).s().i;
		}
	}
	r := chan of string;
	spawn mountproc(r, (hd args).w().i, (hd tl args).s().i, aname, flag, report.start("mount"));
	return ref Value.Vr(r);
}

mountproc(r: chan of string, w: chan of ref Sys->FD, dir, aname: string, flag: int, errorc: chan of string)
{
	if(<-r != nil){
		errorc <-= nil;
		<-w;
		w <-= nil;
		exit;
	}
	fd := <-w;
	if(fd == nil){
		sys->pipe(p := array[2] of ref Sys->FD);
		w <-= p[0];
		fd = p[1];
	}else
		w <-= nil;
	if(sys->mount(fd, nil, dir, flag, aname) == -1){
		e := sys->sprint("mount error on %#q: %r", dir);
		report(errorc, e);
		r <-= e;
		exit;
	}

	errorc <-= nil;
	r <-= nil;
}