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