summaryrefslogtreecommitdiff
path: root/module/sys.m
blob: 2e1a4e02a8781e3c8248a9e03b03d4e738b752c8 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

SELF:	con	"$self";		# Language support for loading my instance

Sys: module
{
	PATH:	con	"$Sys";

	Maxint:	con	2147483647;

	# Unique file identifier for file objects
	Qid: adt
	{
		path:	big;
		vers:	int;
		qtype:	int;
	};

	QTDIR:	con 16r80;
	QTAPPEND:	con 16r40;
	QTEXCL:	con 16r20;
	QTAUTH:	con 16r08;
	QTTMP:	con 16r04;
	QTFILE:	con 0;

	# Return from stat and directory read
	Dir: adt
	{
		name:	string;
		uid:	string;
		gid:	string;
		muid:	string;
		qid:	Qid;
		mode:	int;
		atime:	int;
		mtime:	int;
		length:	big;
		dtype:	int;
		dev:	int;
	};
	nulldir:	con Dir(nil, nil, nil, nil, (~big 0, ~0, ~0), ~0, ~0, ~0, ~big 0, ~0, ~0);
	zerodir:	con Dir(nil, nil, nil, nil, (big 0, 0, 0), 0, 0, 0, big 0, 0, 0);

	# File descriptor
	#
	FD: adt
	{
		fd:	int;
	};

	# Network connection returned by dial
	#
	Connection: adt
	{
		dfd:	ref FD;
		cfd:	ref FD;
		dir:	string;
	};

	# File IO structures returned from file2chan
	# read:  (offset, bytes, fid, chan)
	# write: (offset, data, fid, chan)
	#
	Rread:	type chan of (array of byte, string);
	Rwrite:	type chan of (int, string);
	FileIO: adt
	{
		read:	chan of (int, int, int, Rread);
		write:	chan of (int, array of byte, int, Rwrite);
	};

	# Maximum read which will be completed atomically;
	# also the optimum block size
	#
	ATOMICIO:	con 8192;

	SEEKSTART:	con 0;
	SEEKRELA:	con 1;
	SEEKEND:	con 2;

	NAMEMAX:	con 256;
	ERRMAX:		con 128;
	WAITLEN:	con ERRMAX+64;

	OREAD:		con 0;
	OWRITE:		con 1;
	ORDWR:		con 2;
	OTRUNC:		con 16;
	ORCLOSE:	con 64;
	OEXCL:		con 16r1000;

	DMDIR:		con int 1<<31;
	DMAPPEND:	con int 1<<30;
	DMEXCL:		con int 1<<29;
	DMAUTH:		con int 1<<27;
	DMTMP:		con int 1<<26;

	MREPL:		con 0;
	MBEFORE:	con 1;
	MAFTER:		con 2;
	MCREATE:	con 4;
	MCACHE:		con 16;

	NEWFD:		con (1<<0);
	FORKFD:		con (1<<1);
	NEWNS:		con (1<<2);
	FORKNS:		con (1<<3);
	NEWPGRP:	con (1<<4);
	NODEVS:		con (1<<5);
	NEWENV:		con (1<<6);
	FORKENV:	con (1<<7);

	EXPWAIT:	con 0;
	EXPASYNC:	con 1;

	UTFmax:		con 4;
	UTFerror:	con 16r80;

	announce:	fn(addr: string): (int, Connection);
	aprint:		fn(s: string, *): array of byte;
	bind:		fn(s, on: string, flags: int): int;
	byte2char:	fn(buf: array of byte, n: int): (int, int, int);
	char2byte:	fn(c: int, buf: array of byte, n: int): int;
	chdir:		fn(path: string): int;
	create:		fn(s: string, mode, perm: int): ref FD;
	dial:		fn(addr, local: string): (int, Connection);
	dirread:	fn(fd: ref FD): (int, array of Dir);
	dup:		fn(old, new: int): int;
	export:		fn(c: ref FD, dir: string, flag: int): int;
	fauth:		fn(fd: ref FD, aname: string): ref FD;
	fd2path:	fn(fd: ref FD): string;
	fildes:		fn(fd: int): ref FD;
	file2chan:	fn(dir, file: string): ref FileIO;
	fprint:		fn(fd: ref FD, s: string, *): int;
	fstat:		fn(fd: ref FD): (int, Dir);
	fversion:	fn(fd: ref FD, msize: int, version: string): (int, string);
	fwstat:		fn(fd: ref FD, d: Dir): int;
	iounit:		fn(fd: ref FD): int;
	listen:		fn(c: Connection): (int, Connection);
	millisec:	fn(): int;
	mount:		fn(fd: ref FD, afd: ref FD, on: string, flags: int, spec: string): int;
	open:		fn(s: string, mode: int): ref FD;
	pctl:		fn(flags: int, movefd: list of int): int;
	pipe:		fn(fds: array of ref FD): int;
	print:		fn(s: string, *): int;
	pread:	fn(fd: ref FD, buf: array of byte, n: int, off: big): int;
	pwrite:	fn(fd: ref FD, buf: array of byte, n: int, off: big): int;
	read:		fn(fd: ref FD, buf: array of byte, n: int): int;
	readn:		fn(fd: ref FD, buf: array of byte, n: int): int;
	remove:		fn(s: string): int;
	seek:		fn(fd: ref FD, off: big, start: int): big;
	sleep:		fn(period: int): int;
	sprint:		fn(s: string, *): string;
	stat:		fn(s: string): (int, Dir);
	stream:		fn(src, dst: ref FD, bufsiz: int): int;
	tokenize:	fn(s, delim: string): (int, list of string);
	unmount:	fn(s1: string, s2: string): int;
	utfbytes:	fn(buf: array of byte, n: int): int;
	werrstr:	fn(s: string): int;
	write:		fn(fd: ref FD, buf: array of byte, n: int): int;
	wstat:		fn(s: string, d: Dir): int;
};