2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * In which the structures needed to facilitate interception of file system
12 * related system calls by a user process ("agent", or "venus").
15 #define RT_VERSION 3 /* Version number, should be incremented
16 * before incompatible changes are released */
18 * Version 1 - April 4/84.
19 * Version 2 - May 4/84.
20 * Version 3 - May 30/85.
21 * Version 4 - June 19/85.
24 /* Maximum number of arguments to a system call */
25 #define RT_MAX_ARGS ( (sizeof u.u_arg) / (sizeof (int)) )
30 /* Maximum size of combined string or structure arguments passed between
31 the kernel and a venus */
32 #define RT_MAXDATASIZE (MAXPATHLEN*2)
34 /* The format of the message passed between Venus and the kernel */
35 struct intercept_message {
36 u_short im_type; /* Message type */
37 u_short im_dsize; /* Number of bytes in im_data */
38 int im_client; /* The process id of the client side of the
40 short im_uid; /* The effective user id of the client */
41 short im_gid; /* The effective group id of the client */
42 int im_seq; /* The sequence number of this transaction.
44 afs_int32 im_wdfid[3]; /* Current directory on the remote file system
46 int im_error; /* u.u_error copied from this */
47 char im_follow1; /* 1=>follow last component of first pathname
48 * if symbolic link; 0=>don't */
49 char im_follow2; /* ditto for second pathname */
50 afs_int32 im_pag; /* process authentication group */
51 /* im_arg contains a representation of the arguments to the intercepted
52 * system call, when transmitted from the kernel to Venus.
53 * Returned values are passed back from Venus to the kernel the same way */
55 int im_aval; /* Value of the argument
56 * OR index of argument in im_data */
57 int im_asize; /* If im_aval is the index of an argument in
58 * im_data, then this is its size in bytes.
59 * Otherwise this is 0. */
60 } im_arg[RT_MAX_ARGS];
61 char im_data[RT_MAXDATASIZE];
62 /* Variable length field containing string
63 * or structure arguments */
64 /* No fields should be added here, the record may be truncated on
65 * transmission in either direction to an appropriate size */
70 #define RT_HEADERSIZE ((sizeof (struct intercept_message)) - RT_MAXDATASIZE)
73 /* The following shouldn't be done in this manner, but there doesn't
74 seem to be an easy mechanism to discover the device id. The auto-
75 config stuff is only for real devices, I think.
84 /* Sleep priorities */
85 #define RMT_NOINT_PRI (PINOD+1) /* Sleep with signal handling enabled */
86 #define RMT_INTOK_PRI (PSLEP-1) /* Disallow aborts due to signal handling */
88 /* Private data used by the remote intercept routines in the kernel */
89 /* Note: this was originally designed for only a single remote device.
90 To make it work for multiple devices, I simply unfolded the code
91 by turning this into an array (1 entry per device) and using a macro
92 in the code to reference the appropriate entry. */
94 int rt_flags; /* for flag values, see below */
95 int rt_seq; /* sequence number generator */
96 char rt_open; /* 1 if the device is open *//* XXX UNALIGNED */
97 struct proc *rt_selproc; /* process waiting for select */
98 char rt_attach; /* wait channel for process waiting to attach
100 char rt_read; /* wait channel for a venus waiting for an
102 char rt_reply; /* wait channel for a client process waiting
104 struct intercept_message rt_imr; /* buffer for agent reads */
105 struct intercept_message rt_imw; /* buffer for agent writes */
110 /* Hack to unfold code for multiple devices */
112 #define devhack(dev) register struct remote *rmtp = &remote[minor(dev)]
114 /* Flags for rmt.rt_flags */
115 #define RT_RBUF 1 /* processing venus read request */
116 #define RT_WBUF 2 /* processing venus write request */
117 #define RT_SENDING 4 /* sending the structure to the venus */
118 #define RT_REPLY 8 /* reply from venus to client */
119 #define RT_SIGNAL 16 /* signal occured, want to send message to
120 * venus at next opportunity */
122 /* This bogus stuff is used for rename/link */
124 int func; /* This used to be a function in BSD 4.2... */
129 enum { havePath, isLocal, haveDev, isRemote } state;
132 extern struct inode *RemoteNamei();
133 extern int RemoteMaybe();
137 * Message type codes for messages sent from the kernel.
138 * NB: the kernel ignores the type field on reply (it merely matches
139 * sequence numbers). Unexpected messages from an venus are ignored (they
140 * may have been destined for a process which has died in the meantime).
141 * At all times, the kernel tries to maintain its own integrity, so that
142 * in the worst case an venus restart should work fine.
146 * In the capsule descriptions below, "(?)" means that the flagged item
147 * is probably a good candidate for negotiation.
151 /* For debugging purposes in kernel */
154 /* From kernel: 0: uninterpreted part of pathname
156 * NB: uid/gid for this call are the real (not effective) uid/gid's.
158 * if im_error == EABSPATH1 then:
159 * 0: Resolved absolute path name.
160 * NB: return value is implicit in im_error.
164 /* From kernel: 0: uninterpreted part of pathname
166 * 0: new pathname (with ..'s removed, symbolic
167 * links NOT expanded).
168 * length<MAXPATHLEN. Null terminated.
171 * im_wdfid: the file identifier (volume, vnode, unique)
172 * of the new working directory.
174 * if im_error == EABSPATH1 then:
175 * 0: Resolved absolute path name.
179 /* From kernel: 0: uninterpreted part of pathname
182 * if im_error == EABSPATH1 then:
183 * 0: Resolved absolute path name.
187 /* From kernel: 0: uninterpreted part of pathname
191 * if im_error == EABSPATH1 then:
192 * 0: Resolved absolute path name.
196 /* From kernel: 0: file identifier.
197 * im_error: either 0 or one of the error codes
198 * listed below (RTE_*, see RT_open).
199 * Response: im_error (for programs that want to know)
200 * N.B.: close MUST always cleanup state; it will never be issued
201 * twice for the same identifier. If RT_signal is received during
202 * a close, venus can use this as a hint to return early from the
203 * close. Venus should not return EINTR for this system call, however.
207 /* From kernel: 0: file identifier
213 /* From kernel: 0: file identifier
220 /* Not implemented */
223 /* From kernel: 0: file identifier
229 /* From kernel: 0: file identifier.
230 * Response: 0: struct stat
235 /* From kernel: 0: file identifier.
239 #define RT_ftruncate 12
240 /* From kernel: 0: file identifier.
241 * 1: truncated length. (? right now, kernel truncates
247 /* From kernel: 0: the uninterpreted part of the original path
248 * 1: the uninterpreted part of the pathname which
249 * will be the new link
251 * if im_error == EABSPATH1 or EABSPATH2 then:
252 * 0: Resolved absolute path name.
256 /* Obsolete--not generated by the kernel. The im_follow1
257 field is used in conjunction with RT_stat to implement
258 lstat. VICE I will continue to work since it does not
259 distinguish between stat and lstat */
262 /* From kernel: 0: uninterpreted part of pathname
265 * if im_error == EABSPATH1 then:
266 * 0: Resolved absolute path name.
270 /* From kernel: 0: uninterpreted part of pathname
274 * 0: file identifier assigned (for subsequent
275 * messages dealing with open files).
276 * 1: pathname of the local, cached file.
278 * Note: the returned filename is not created, truncated(?),
279 * or otherwise fiddled with by the kernel. It must
280 * exist and must be a plain file. N.B: Protection modes
281 * are ignored when it is finally opened. The exec bit,
282 * however, should never be set unless the file is
283 * really executable. (It should never be set for
284 * directories). If there are problems opening the
285 * file, the user gets an error, the kernel gets a close
286 * message (possibly with one of the RTE_* errors, below,
289 * 0: file identifier assigned (for subsequent
290 * messages dealing with open files).
291 * 1: device where the file resides.
292 * 2: inode number of the file.
294 * if im_error == EABSPATH1 then:
295 * 0: Resolved absolute path name.
296 * (?) Non-blocking open.
299 #define RT_readlink 17
300 /* From kernel: 0: uninterpreted part of link pathname
301 * Response: 0: number of characters read from link
302 * 1: contents of link (not null terminated). Size must not be
303 * greater than MAXPATHLEN (because this is checked by the
304 * kernel intercept code).
306 * if im_error == EABSPATH1 then:
307 * 0: Resolved absolute path name.
311 /* From kernel: 0: uninterpreted part of original pathname
312 * 1: ditto for new pathname
314 * if im_error == EABSPATH1 or EABSPATH2 then:
315 * 0: Resolved absolute path name.
319 /* From kernel: 0: uninterpreted part of pathname
321 * if im_error == EABSPATH1 then:
322 * 0: Resolved absolute path name.
326 /* From kernel: 0: uninterpreted part of pathname
327 * Response: 0: struct stat
329 * if im_error == EABSPATH1 then:
330 * 0: Resolved absolute path name.
331 * Note: this now implements the lstat call, as well,
332 * by means of the im_follow1 field in the header.
335 #define RT_symlink 21
336 /* From kernel: 0: the string value of the new symbolic link.
337 * 1: the uninterpreted part of the pathname to
340 * if im_error == EABSPATH1 then:
341 * 0: Resolved absolute path name.
344 #define RT_truncate 22
345 /* From kernel: 0: uninterpreted part of pathname
346 * 1: truncated length
348 * if im_error == EABSPATH1 then:
349 * 0: Resolved absolute path name.
353 /* From kernel: 0: uninterpreted part of pathname
355 * if im_error == EABSPATH1 then:
356 * 0: Resolved absolute path name.
360 /* From kernel: 0: uninterpreted part of pathname
361 * 1: struct timeval tvp[2]
363 * if im_error == EABSPATH1 then:
364 * 0: Resolved absolute path name.
368 /* Request to abort the previous operation requested WITH THE
369 * SAME im_seq FIELD. No action is expected on the part of
370 * the venus--this is merely advice that the operation may
371 * be completed early. VENUS SHOULD NOT REPLY TO THIS MESSAGE.
372 * The error returned on final completion by the venus need not
373 * acknowledge that the system call was interrupted. The interrupt
374 * will occur at the end of the system call regardless. EINTR
375 * should be returned if the system call actually is aborted.
376 * VENUS MAY RETURN EARLY FROM A C L O S E SYSTEM CALL, BUT MUST STILL
377 * CLEANUP STATE FOR THE CLOSE--ANOTHER CLOSE CALL FOR THE SAME
378 * DESCRIPTOR WILL NEVER BE ISSUED.
379 * RT_signal messages for which a reply has already been issued
380 * sholuld be ignored by venus.
385 * From kernel: 0: file identifier
386 * 1: command (see below)
387 * 2: uninterpreted data (up to RT_MAXDATASIZE).
388 * Response: 0: data to be returned to user
390 * NOTE: the information passed to/from venus is not in the
391 * same format as that coming to/from the user. See the file
398 * From kernel: 0: uninterpreted part of pathname
399 * 1: command (as in RT_ioctl)
400 * 2: uninterpreted data
401 * Note: argument 3, do not follow symbolic links, is
402 * obsolete; this is compatible with VICE I, since the
403 * field was ignored anyway.
404 * Response: 0: data to be returned to user
406 * if im_error == EABSPATH1 then:
407 * 0: Resolved absolute path name.
411 /* Error codes -- each is set by the kernel for the explicit error indicated.
412 * These are set in im_error (which should normally be 0 in every message from
413 * the kernel). Errors of this form indicate that the venus process has
414 * almost certainly done something wrong. The associated user process gets an
415 * ERFS (remote file system error) for each of these error types.
418 /* The following error codes all occur at open (exec?) and are sent by the
419 * kernel with the associated close message for the file identifier returned
423 #define RTE_BADARG 1 /* The size of a structure or string argument returned
424 * by the venus to the kernel is bogus.
425 * (the im_size field is not zero, or part of the
426 * argument is outside the message buffer, or the
427 * argument is too large) */
429 #define RTE_NOFILE 2 /* The file name (or inode, in VICE II) returned to
430 * the kernel, to open or exec in lieu of the original
431 * name supplied by the process cannot be opened or
434 #define RTE_NOTREG 3 /* The file (or inode, in VICE II) returned to the
435 * kernel, to open or exec in lieu of the original
436 * name supplied by the process, is not a IF_REG
437 * type file, i.e. it is a device, socket, or
441 /* The following error codes are set by Venus when a pathname argument supplied
442 * by the kernel resolves to an absolute pathname outside of the name space
443 * of this venus. The resolved absolute pathname is returned in argument 0.
444 * The kernel is expected to retry the system call with this new information.
445 * The kernel never passes this error on to the original issuer of the system
448 #define EABSPATH1 126 /* The first pathname, or only pathname, of a system
449 * call resolved to an absolute pathname */
450 #define EABSPATH2 127 /* The second pathname of the rename or link system
451 * call resolved to an absolute pathname */