xref: /inferno-os/module/styx.m (revision 46439007cf417cbd9ac8049bb4122c890097a0fa)
1Styx: module
2{
3	PATH:	con "/dis/lib/styx.dis";
4	PATHV1:	con "/dis/lib/styx1.dis";
5
6	VERSION:	con "9P2000";
7	MAXWELEM:	con 16;
8
9	NOTAG:	con 16rFFFF;
10	NOFID:	con int ~0;	# 32 bits in this version of Styx
11
12	BIT8SZ:	con 1;
13	BIT16SZ:	con 2;
14	BIT32SZ:	con 4;
15	BIT64SZ:	con 8;
16	QIDSZ:	con BIT8SZ+BIT32SZ+BIT64SZ;
17
18	STATFIXLEN:	con BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+BIT64SZ;	# amount of fixed length data in a stat buffer
19	IOHDRSZ:	con 24;	# room for Twrite/Rread header
20	MAXFDATA: con 8192;	# `reasonable' iounit
21	MAXRPC:	con IOHDRSZ+MAXFDATA;	# usable default for fversion and iounit
22
23	Tversion,		# 100
24	Rversion,
25	Tauth,		# 102
26	Rauth,
27	Tattach,		# 104
28	Rattach,
29	Terror,		# 106, illegal
30	Rerror,
31	Tflush,		#108
32	Rflush,
33	Twalk,		# 110
34	Rwalk,
35	Topen,		# 112
36	Ropen,
37	Tcreate,		# 114
38	Rcreate,
39	Tread,		# 116
40	Rread,
41	Twrite,		# 118
42	Rwrite,
43	Tclunk,		# 120
44	Rclunk,
45	Tremove,		# 122
46	Rremove,
47	Tstat,		# 124
48	Rstat,
49	Twstat,		#126
50	Rwstat,
51	Tmax: con 100+iota;
52
53	ERRMAX:	con 128;
54
55	OREAD:	con 0; 		# open for read
56	OWRITE:	con 1; 		# write
57	ORDWR:	con 2; 		# read and write
58	OEXEC:	con 3; 		# execute, == read but check execute permission
59	OTRUNC:	con 16; 		# or'ed in (except for exec), truncate file first
60	ORCLOSE: con 64; 		# or'ed in, remove on close
61
62	# mode bits in Dir.mode used by the protocol
63	DMDIR:		con int 1<<31;		# mode bit for directory
64	DMAPPEND:	con int 1<<30;		# mode bit for append-only files
65	DMEXCL:		con int 1<<29;		# mode bit for exclusive use files
66	DMAUTH:		con int 1<<27;		# mode bit for authentication files
67
68	# Qid.qtype
69	QTDIR:	con 16r80;
70	QTAPPEND:	con 16r40;
71	QTEXCL:	con 16r20;
72	QTAUTH:	con 16r08;
73	QTFILE:	con 16r00;
74
75	Tmsg: adt {
76		tag: int;
77		pick {
78		Readerror =>
79			error: string;		# tag is unused in this case
80		Version =>
81			msize: int;
82			version: string;
83		Auth =>
84			afid: int;
85			uname, aname: string;
86		Attach =>
87			fid, afid: int;
88			uname, aname: string;
89		Flush =>
90			oldtag: int;
91		Walk =>
92			fid, newfid: int;
93			names: array of string;
94		Open =>
95			fid, mode: int;
96		Create =>
97			fid: int;
98			name: string;
99			perm, mode: int;
100		Read =>
101			fid: int;
102			offset: big;
103			count: int;
104		Write =>
105			fid: int;
106			offset: big;
107			data: array of byte;
108		Clunk or
109		Stat or
110		Remove =>
111			fid: int;
112		Wstat =>
113			fid: int;
114			stat: Sys->Dir;
115		}
116
117		read:	fn(fd: ref Sys->FD, msize: int): ref Tmsg;
118		unpack:	fn(a: array of byte): (int, ref Tmsg);
119		pack:	fn(nil: self ref Tmsg): array of byte;
120		packedsize:	fn(nil: self ref Tmsg): int;
121		text:	fn(nil: self ref Tmsg): string;
122		mtype: fn(nil: self ref Tmsg): int;
123	};
124
125	Rmsg: adt {
126		tag: int;
127		pick {
128		Readerror =>
129			error: string;		# tag is unused in this case
130		Version =>
131			msize: int;
132			version: string;
133		Auth =>
134			aqid: Sys->Qid;
135		Attach =>
136			qid: Sys->Qid;
137		Flush =>
138		Error =>
139			ename: string;
140		Clunk or
141		Remove or
142		Wstat =>
143		Walk =>
144			qids: array of Sys->Qid;
145		Create or
146		Open =>
147			qid: Sys->Qid;
148			iounit: int;
149		Read =>
150			data: array of byte;
151		Write =>
152			count: int;
153		Stat =>
154			stat: Sys->Dir;
155		}
156
157		read:	fn(fd: ref Sys->FD, msize: int): ref Rmsg;
158		unpack:	fn(a: array of byte): (int, ref Rmsg);
159		pack:	fn(nil: self ref Rmsg): array of byte;
160		packedsize:	fn(nil: self ref Rmsg): int;
161		text:	fn(nil: self ref Rmsg): string;
162		mtype: fn(nil: self ref Rmsg): int;
163	};
164
165	init:	fn();
166
167	readmsg:	fn(fd: ref Sys->FD, msize: int): (array of byte, string);
168	istmsg:	fn(f: array of byte): int;
169
170	compatible:	fn(t: ref Tmsg.Version, msize: int, version: string): (int, string);
171
172	packdirsize:	fn(d: Sys->Dir): int;
173	packdir:	fn(d: Sys->Dir): array of byte;
174	unpackdir: fn(f: array of byte): (int, Sys->Dir);
175	dir2text:	fn(d: Sys->Dir): string;
176	qid2text:	fn(q: Sys->Qid): string;
177
178	utflen:	fn(s: string): int;
179
180	# temporary undocumented compatibility function
181	write:	fn(fd: ref Sys->FD, a: array of byte, n: int): int;
182};
183