xref: /inferno-os/module/sys.m (revision 3a0400887de9df81e4d4fb3bc3dec52af2d49f80)
146439007SCharles.Forsyth
246439007SCharles.ForsythSELF:	con	"$self";		# Language support for loading my instance
346439007SCharles.Forsyth
446439007SCharles.ForsythSys: module
546439007SCharles.Forsyth{
646439007SCharles.Forsyth	PATH:	con	"$Sys";
746439007SCharles.Forsyth
846439007SCharles.Forsyth	Maxint:	con	2147483647;
946439007SCharles.Forsyth
1046439007SCharles.Forsyth	# Unique file identifier for file objects
1146439007SCharles.Forsyth	Qid: adt
1246439007SCharles.Forsyth	{
1346439007SCharles.Forsyth		path:	big;
1446439007SCharles.Forsyth		vers:	int;
1546439007SCharles.Forsyth		qtype:	int;
1646439007SCharles.Forsyth	};
1746439007SCharles.Forsyth
1846439007SCharles.Forsyth	QTDIR:	con 16r80;
1946439007SCharles.Forsyth	QTAPPEND:	con 16r40;
2046439007SCharles.Forsyth	QTEXCL:	con 16r20;
2146439007SCharles.Forsyth	QTAUTH:	con 16r08;
2246439007SCharles.Forsyth	QTTMP:	con 16r04;
2346439007SCharles.Forsyth	QTFILE:	con 0;
2446439007SCharles.Forsyth
2546439007SCharles.Forsyth	# Return from stat and directory read
2646439007SCharles.Forsyth	Dir: adt
2746439007SCharles.Forsyth	{
2846439007SCharles.Forsyth		name:	string;
2946439007SCharles.Forsyth		uid:	string;
3046439007SCharles.Forsyth		gid:	string;
3146439007SCharles.Forsyth		muid:	string;
3246439007SCharles.Forsyth		qid:	Qid;
3346439007SCharles.Forsyth		mode:	int;
3446439007SCharles.Forsyth		atime:	int;
3546439007SCharles.Forsyth		mtime:	int;
3646439007SCharles.Forsyth		length:	big;
3746439007SCharles.Forsyth		dtype:	int;
3846439007SCharles.Forsyth		dev:	int;
3946439007SCharles.Forsyth	};
4046439007SCharles.Forsyth	nulldir:	con Dir(nil, nil, nil, nil, (~big 0, ~0, ~0), ~0, ~0, ~0, ~big 0, ~0, ~0);
4146439007SCharles.Forsyth	zerodir:	con Dir(nil, nil, nil, nil, (big 0, 0, 0), 0, 0, 0, big 0, 0, 0);
4246439007SCharles.Forsyth
4346439007SCharles.Forsyth	# File descriptor
4446439007SCharles.Forsyth	#
4546439007SCharles.Forsyth	FD: adt
4646439007SCharles.Forsyth	{
4746439007SCharles.Forsyth		fd:	int;
4846439007SCharles.Forsyth	};
4946439007SCharles.Forsyth
5046439007SCharles.Forsyth	# Network connection returned by dial
5146439007SCharles.Forsyth	#
5246439007SCharles.Forsyth	Connection: adt
5346439007SCharles.Forsyth	{
5446439007SCharles.Forsyth		dfd:	ref FD;
5546439007SCharles.Forsyth		cfd:	ref FD;
5646439007SCharles.Forsyth		dir:	string;
5746439007SCharles.Forsyth	};
5846439007SCharles.Forsyth
5946439007SCharles.Forsyth	# File IO structures returned from file2chan
6046439007SCharles.Forsyth	# read:  (offset, bytes, fid, chan)
6146439007SCharles.Forsyth	# write: (offset, data, fid, chan)
6246439007SCharles.Forsyth	#
6346439007SCharles.Forsyth	Rread:	type chan of (array of byte, string);
6446439007SCharles.Forsyth	Rwrite:	type chan of (int, string);
6546439007SCharles.Forsyth	FileIO: adt
6646439007SCharles.Forsyth	{
6746439007SCharles.Forsyth		read:	chan of (int, int, int, Rread);
6846439007SCharles.Forsyth		write:	chan of (int, array of byte, int, Rwrite);
6946439007SCharles.Forsyth	};
7046439007SCharles.Forsyth
7146439007SCharles.Forsyth	# Maximum read which will be completed atomically;
7246439007SCharles.Forsyth	# also the optimum block size
7346439007SCharles.Forsyth	#
7446439007SCharles.Forsyth	ATOMICIO:	con 8192;
7546439007SCharles.Forsyth
7646439007SCharles.Forsyth	SEEKSTART:	con 0;
7746439007SCharles.Forsyth	SEEKRELA:	con 1;
7846439007SCharles.Forsyth	SEEKEND:	con 2;
7946439007SCharles.Forsyth
8046439007SCharles.Forsyth	NAMEMAX:	con 256;
8146439007SCharles.Forsyth	ERRMAX:		con 128;
8246439007SCharles.Forsyth	WAITLEN:	con ERRMAX+64;
8346439007SCharles.Forsyth
8446439007SCharles.Forsyth	OREAD:		con 0;
8546439007SCharles.Forsyth	OWRITE:		con 1;
8646439007SCharles.Forsyth	ORDWR:		con 2;
8746439007SCharles.Forsyth	OTRUNC:		con 16;
8846439007SCharles.Forsyth	ORCLOSE:	con 64;
8946439007SCharles.Forsyth	OEXCL:		con 16r1000;
9046439007SCharles.Forsyth
9146439007SCharles.Forsyth	DMDIR:		con int 1<<31;
9246439007SCharles.Forsyth	DMAPPEND:	con int 1<<30;
9346439007SCharles.Forsyth	DMEXCL:		con int 1<<29;
9446439007SCharles.Forsyth	DMAUTH:		con int 1<<27;
9546439007SCharles.Forsyth	DMTMP:		con int 1<<26;
9646439007SCharles.Forsyth
9746439007SCharles.Forsyth	MREPL:		con 0;
9846439007SCharles.Forsyth	MBEFORE:	con 1;
9946439007SCharles.Forsyth	MAFTER:		con 2;
10046439007SCharles.Forsyth	MCREATE:	con 4;
10146439007SCharles.Forsyth	MCACHE:		con 16;
10246439007SCharles.Forsyth
10346439007SCharles.Forsyth	NEWFD:		con (1<<0);
10446439007SCharles.Forsyth	FORKFD:		con (1<<1);
10546439007SCharles.Forsyth	NEWNS:		con (1<<2);
10646439007SCharles.Forsyth	FORKNS:		con (1<<3);
10746439007SCharles.Forsyth	NEWPGRP:	con (1<<4);
10846439007SCharles.Forsyth	NODEVS:		con (1<<5);
10946439007SCharles.Forsyth	NEWENV:		con (1<<6);
11046439007SCharles.Forsyth	FORKENV:	con (1<<7);
11146439007SCharles.Forsyth
11246439007SCharles.Forsyth	EXPWAIT:	con 0;
11346439007SCharles.Forsyth	EXPASYNC:	con 1;
11446439007SCharles.Forsyth
115*3a040088SCharles Forsyth	UTFmax:		con 4;	# maximum bytes per rune in UTF-8
116*3a040088SCharles Forsyth	UTFerror:	con 16rFFFD;	# decoding error in UTF
117*3a040088SCharles Forsyth	Runemax:	con 16r10FFFF;	# 21-bit rune
118*3a040088SCharles Forsyth	Runemask:	con 16r1FFFFF;	# bits used by runes
11946439007SCharles.Forsyth
12046439007SCharles.Forsyth	announce:	fn(addr: string): (int, Connection);
12146439007SCharles.Forsyth	aprint:		fn(s: string, *): array of byte;
12246439007SCharles.Forsyth	bind:		fn(s, on: string, flags: int): int;
12346439007SCharles.Forsyth	byte2char:	fn(buf: array of byte, n: int): (int, int, int);
12446439007SCharles.Forsyth	char2byte:	fn(c: int, buf: array of byte, n: int): int;
12546439007SCharles.Forsyth	chdir:		fn(path: string): int;
12646439007SCharles.Forsyth	create:		fn(s: string, mode, perm: int): ref FD;
12746439007SCharles.Forsyth	dial:		fn(addr, local: string): (int, Connection);
12846439007SCharles.Forsyth	dirread:	fn(fd: ref FD): (int, array of Dir);
12946439007SCharles.Forsyth	dup:		fn(old, new: int): int;
13046439007SCharles.Forsyth	export:		fn(c: ref FD, dir: string, flag: int): int;
13146439007SCharles.Forsyth	fauth:		fn(fd: ref FD, aname: string): ref FD;
13246439007SCharles.Forsyth	fd2path:	fn(fd: ref FD): string;
13346439007SCharles.Forsyth	fildes:		fn(fd: int): ref FD;
13446439007SCharles.Forsyth	file2chan:	fn(dir, file: string): ref FileIO;
13546439007SCharles.Forsyth	fprint:		fn(fd: ref FD, s: string, *): int;
13646439007SCharles.Forsyth	fstat:		fn(fd: ref FD): (int, Dir);
13746439007SCharles.Forsyth	fversion:	fn(fd: ref FD, msize: int, version: string): (int, string);
13846439007SCharles.Forsyth	fwstat:		fn(fd: ref FD, d: Dir): int;
13946439007SCharles.Forsyth	iounit:		fn(fd: ref FD): int;
14046439007SCharles.Forsyth	listen:		fn(c: Connection): (int, Connection);
14146439007SCharles.Forsyth	millisec:	fn(): int;
14246439007SCharles.Forsyth	mount:		fn(fd: ref FD, afd: ref FD, on: string, flags: int, spec: string): int;
14346439007SCharles.Forsyth	open:		fn(s: string, mode: int): ref FD;
14446439007SCharles.Forsyth	pctl:		fn(flags: int, movefd: list of int): int;
14546439007SCharles.Forsyth	pipe:		fn(fds: array of ref FD): int;
14646439007SCharles.Forsyth	print:		fn(s: string, *): int;
14746439007SCharles.Forsyth	pread:	fn(fd: ref FD, buf: array of byte, n: int, off: big): int;
14846439007SCharles.Forsyth	pwrite:	fn(fd: ref FD, buf: array of byte, n: int, off: big): int;
14946439007SCharles.Forsyth	read:		fn(fd: ref FD, buf: array of byte, n: int): int;
150ad885397SCharles.Forsyth	readn:		fn(fd: ref FD, buf: array of byte, n: int): int;
15146439007SCharles.Forsyth	remove:		fn(s: string): int;
15246439007SCharles.Forsyth	seek:		fn(fd: ref FD, off: big, start: int): big;
15346439007SCharles.Forsyth	sleep:		fn(period: int): int;
15446439007SCharles.Forsyth	sprint:		fn(s: string, *): string;
15546439007SCharles.Forsyth	stat:		fn(s: string): (int, Dir);
15646439007SCharles.Forsyth	stream:		fn(src, dst: ref FD, bufsiz: int): int;
15746439007SCharles.Forsyth	tokenize:	fn(s, delim: string): (int, list of string);
15846439007SCharles.Forsyth	unmount:	fn(s1: string, s2: string): int;
15946439007SCharles.Forsyth	utfbytes:	fn(buf: array of byte, n: int): int;
16046439007SCharles.Forsyth	werrstr:	fn(s: string): int;
16146439007SCharles.Forsyth	write:		fn(fd: ref FD, buf: array of byte, n: int): int;
16246439007SCharles.Forsyth	wstat:		fn(s: string, d: Dir): int;
16346439007SCharles.Forsyth};
164