xref: /plan9/sys/src/cmd/9nfs/dat.h (revision 883a8c51bed350ea85a0220461d31e311550db04)
1 enum
2 {
3 	FHSIZE	= 32
4 };
5 
6 typedef struct Accept	Accept;
7 typedef struct Auth	Auth;
8 typedef struct Authunix	Authunix;
9 typedef struct Chalstuff Chalstuff;
10 typedef uchar		Fhandle[FHSIZE];
11 typedef struct Fid	Fid;
12 typedef struct Procmap	Procmap;
13 typedef struct Progmap	Progmap;
14 typedef struct Reject	Reject;
15 typedef struct Rpccall	Rpccall;
16 typedef struct Rpccache	Rpccache;
17 typedef struct Sattr	Sattr;
18 typedef struct Session	Session;
19 typedef struct String	String;
20 typedef struct Strnode	Strnode;
21 typedef struct Unixid	Unixid;
22 typedef struct Unixidmap Unixidmap;
23 typedef struct Unixmap	Unixmap;
24 typedef struct Unixscmap Unixscmap;
25 typedef struct Xfid	Xfid;
26 typedef struct Xfile	Xfile;
27 
28 struct String
29 {
30 	ulong	n;
31 	char *	s;
32 };
33 
34 struct Progmap
35 {
36 	int	progno;
37 	int	vers;
38 	void	(*init)(int, char**);
39 	Procmap *pmap;
40 };
41 
42 struct Procmap
43 {
44 	int	procno;
45 	int	(*procp)(int, Rpccall*, Rpccall*);
46 };
47 
48 struct Auth
49 {
50 	ulong	flavor;
51 	ulong	count;
52 	void *	data;
53 };
54 
55 struct Authunix
56 {
57 	ulong	stamp;
58 	String	mach;
59 	ulong	uid;
60 	ulong	gid;
61 	int	gidlen;
62 	ulong	gids[10];
63 };
64 
65 struct Accept
66 {
67 	Auth	averf;
68 	ulong	astat;
69 	union{
70 		void *	results;	/* SUCCESS */
71 		struct{			/* PROG_MISMATCH */
72 			ulong	plow;	/* acceptable version numbers */
73 			ulong	phigh;
74 		};
75 	};
76 };
77 
78 struct Reject
79 {
80 	ulong	rstat;
81 	union{
82 		struct{			/* RPC_MISMATCH */
83 			ulong	rlow;	/* acceptable  rpc version numbers */
84 			ulong	rhigh;
85 		};
86 		ulong	authstat;	/* AUTH_ERROR */
87 	};
88 };
89 
90 struct Rpccall
91 {
92 	/* corresponds to Udphdr */
93 	uchar	prefix0[12];
94 	ulong	host;		/* ipv4 subset: prefixed to RPC message */
95 	uchar	prefix1[12];
96 	ulong	lhost;		/* ipv4 subset: prefixed to RPC message */
97 	/* ignore ifcaddr */
98 	ulong	port;		/* prefixed to RPC message */
99 	ulong	lport;		/* prefixed to RPC message */
100 
101 	ulong	xid;		/* transaction id */
102 	ulong	mtype;		/* CALL or REPLY */
103 	union{
104 		struct{		/* CALL */
105 			ulong	rpcvers;	/* must be equal to two (2) */
106 			ulong	prog;		/* program number */
107 			ulong	vers;		/* program version */
108 			ulong	proc;		/* procedure number */
109 			Auth	cred;		/* authentication credentials */
110 			Auth	verf;		/* authentication verifier */
111 			Unixidmap *up;
112 			char *	user;
113 			void *	args;		/* procedure-specific */
114 		};
115 		struct{		/* REPLY */
116 			ulong	stat;		/* MSG_ACCEPTED or MSG_DENIED */
117 			union{
118 				Accept;
119 				Reject;
120 			};
121 		};
122 	};
123 };
124 
125 struct Rpccache
126 {
127 	Rpccache *prev;
128 	Rpccache *next;
129 	ulong	host;
130 	ulong	port;
131 	ulong	xid;
132 	int	n;
133 	uchar	data[4];
134 };
135 
136 struct Sattr
137 {
138 	ulong	mode;
139 	ulong	uid;
140 	ulong	gid;
141 	ulong	size;
142 	ulong	atime;		/* sec's */
143 	ulong	ausec;		/* microsec's */
144 	ulong	mtime;
145 	ulong	musec;
146 };
147 
148 struct Strnode
149 {
150 	Strnode *next;	/* in hash bucket */
151 	char	str[4];
152 };
153 
154 struct Unixid
155 {
156 	Unixid *next;
157 	char *	name;
158 	int	id;
159 };
160 
161 struct Unixmap
162 {
163 	char *	file;
164 	int	style;
165 	long	timestamp;
166 	Unixid *ids;
167 };
168 
169 struct Unixidmap
170 {
171 	Unixidmap *next;
172 	int	flag;
173 	char *	server;
174 	char *	client;
175 	Reprog *sexp;
176 	Reprog *cexp;
177 	Unixmap	u;
178 	Unixmap	g;
179 };
180 
181 struct Unixscmap
182 {
183 	Unixscmap *next;
184 	char *	server;
185 	ulong	clientip;
186 	Unixidmap *map;
187 };
188 
189 struct Xfile
190 {
191 	Xfile *	next;		/* hash chain */
192 	Session	*s;
193 	Qid		qid;	/* from stat */
194 	Xfile *	parent;
195 	Xfile *	child;		/* if directory */
196 	Xfile *	sib;		/* siblings */
197 	char *	name;		/* path element */
198 	Xfid *	users;
199 };
200 
201 enum
202 {
203 	Oread	= 1,
204 	Owrite	= 2,
205 	Open	= 3,
206 	Trunc	= 4
207 };
208 
209 struct Xfid
210 {
211 	Xfid *	next;		/* Xfile's user list */
212 	Xfile *	xp;
213 	char *	uid;
214 	Fid *	urfid;
215 	Fid *	opfid;
216 	ulong	mode;		/* open mode, if opfid is non-zero */
217 	ulong	offset;
218 };
219 
220 struct Fid
221 {
222 	Fid **	owner;		/* null for root fids */
223 	Fid *	prev;
224 	Fid *	next;
225 	long	tstale;		/* auto-clunk */
226 };
227 
228 enum
229 {
230 	Maxfdata = 8192,
231 	Maxstatdata = 2048,
232 };
233 
234 struct Session
235 {
236 	Session *next;
237 	char *	service;		/* for dial */
238 	int	fd;
239 #define CHALLEN 1
240 	char	cchal[CHALLEN];		/* client challenge */
241 	char	schal[CHALLEN];		/* server challenge */
242 	char	authid[ANAMELEN];	/* server encryption uid */
243 	char	authdom[DOMLEN];	/* server encryption domain */
244 	char *	spec;			/* for attach */
245 	Xfile *	root;			/* to answer mount rpc */
246 	ushort	tag;
247 	Fcall	f;
248 	uchar	data[IOHDRSZ+Maxfdata];
249 	uchar	statbuf[Maxstatdata];
250 	Fid *	free;			/* available */
251 	Fid	list;			/* active, most-recently-used order */
252 	Fid	fids[1000];
253 	int	noauth;
254 };
255 
256 struct Chalstuff
257 {
258 	Chalstuff *next;
259 	Xfid *	xf;
260 	long	tstale;
261 	Chalstate;
262 };
263 
264 extern int	rpcdebug;
265 extern int	p9debug;
266 extern int	chatty;
267 extern void	(*rpcalarm)(void);
268 extern long	starttime;
269 extern long	nfstime;
270 extern char *	config;
271 extern int	staletime;
272 extern int	messagesize;
273 extern char *	commonopts;
274