attempt-more-portable-64bit-type-support-for-namei-fileserver-20010403
[openafs.git] / src / util / remote.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #if !defined(lint) && !defined(LOCORE)  && defined(RCS_HDRS)
11 #endif
12 /*
13  * In which the structures needed to facilitate interception of file system
14  * related system calls by a user process ("agent", or "venus").
15  */
16
17 #define RT_VERSION      3       /* Version number, should be incremented
18                                    before incompatible changes are released */
19 /*
20  *      Version 1 - April 4/84.
21  *      Version 2 - May 4/84.
22  *      Version 3 - May 30/85.
23  *      Version 4 - June 19/85.
24  */
25
26 /* Maximum number of arguments to a system call */
27 #define RT_MAX_ARGS             ( (sizeof u.u_arg) / (sizeof (int)) )
28
29 #ifndef KERNEL
30 extern struct user u;
31 #endif /* KERNEL */
32 /* Maximum size of combined string or structure arguments passed between
33    the kernel and a venus */
34 #define RT_MAXDATASIZE          (MAXPATHLEN*2)
35
36 /* The format of the message passed between Venus and the kernel */
37 struct  intercept_message {
38     u_short     im_type;        /* Message type */
39     u_short     im_dsize;       /* Number of bytes in im_data */
40     int         im_client;      /* The process id of the client side of the
41                                    transaction */
42     short       im_uid;         /* The effective user id of the client */
43     short       im_gid;         /* The effective group id of the client */
44     int         im_seq;         /* The sequence number of this transaction.
45                                    Never 0 */
46     afs_int32   im_wdfid[3];    /* Current directory on the remote file system
47                                    Vice II only. */
48     int         im_error;       /* u.u_error copied from this */
49     char        im_follow1;     /* 1=>follow last component of first pathname
50                                    if symbolic link; 0=>don't */
51     char        im_follow2;     /* ditto for second pathname */
52     afs_int32   im_pag;         /* process authentication group */
53     /* im_arg contains a representation of the arguments to the intercepted
54        system call, when transmitted from the kernel to Venus.
55        Returned values are passed back from Venus to the kernel the same way */
56     struct im_arg {
57         int     im_aval;        /* Value of the argument
58                                    OR index of argument in im_data */
59         int     im_asize;       /* If im_aval is the index of an argument in
60                                    im_data, then this is its size in bytes.
61                                    Otherwise this is 0. */
62     } im_arg[RT_MAX_ARGS];
63     char        im_data[RT_MAXDATASIZE];
64                                 /* Variable length field containing string
65                                    or structure arguments */
66     /* No fields should be added here, the record may be truncated on
67        transmission in either direction to an appropriate size */
68 };
69
70
71
72 #define RT_HEADERSIZE   ((sizeof (struct intercept_message)) - RT_MAXDATASIZE)
73
74 #ifdef KERNEL
75 /* The following shouldn't be done in this manner, but there doesn't
76    seem to be an easy mechanism to discover the device id.  The auto-
77    config stuff is only for real devices, I think.
78  */
79 #ifdef sun
80 #define RMT_MAJ         30
81 #endif
82 #ifdef vax
83 #define RMT_MAJ         33
84 #endif
85
86 /* Sleep priorities */
87 #define RMT_NOINT_PRI   (PINOD+1)/* Sleep with signal handling enabled */
88 #define RMT_INTOK_PRI   (PSLEP-1)/* Disallow aborts due to signal handling */
89
90 /* Private data used by the remote intercept routines in the kernel */
91 /* Note:  this was originally designed for only a single remote device.
92    To make it work for multiple devices, I simply unfolded the code
93    by turning this into an array (1 entry per device) and using a macro
94    in the code to reference the appropriate entry. */
95 struct remote {
96     int         rt_flags;       /* for flag values, see below */
97     int         rt_seq;         /* sequence number generator */
98     char        rt_open;        /* 1 if the device is open */  /* XXX UNALIGNED */
99     struct proc *rt_selproc;    /* process waiting for select */
100     char        rt_attach;      /* wait channel for process waiting to attach
101                                    this structure */
102     char        rt_read;        /* wait channel for a venus waiting for an
103                                    intercept */
104     char        rt_reply;       /* wait channel for a client process waiting
105                                    for a reply */
106     struct      intercept_message rt_imr;       /* buffer for agent reads */
107     struct      intercept_message rt_imw;       /* buffer for agent writes */
108 #include "rfs.h"
109 } remote[NRFS];
110 #undef NRFS
111
112 /* Hack to unfold code for multiple devices */
113 #define rmt     (*rmtp)
114 #define devhack(dev) register struct remote *rmtp = &remote[minor(dev)]
115
116 /* Flags for rmt.rt_flags */
117 #define RT_RBUF         1       /* processing venus read request */
118 #define RT_WBUF         2       /* processing venus write request */
119 #define RT_SENDING      4       /* sending the structure to the venus */
120 #define RT_REPLY        8       /* reply from venus to client */
121 #define RT_SIGNAL       16      /* signal occured, want to send message to
122                                    venus at next opportunity */
123
124 /* This bogus stuff is used for rename/link */
125 struct Name {
126     int func;        /* This used to be a function in BSD 4.2... */
127     int follow;
128     struct buf *buf;
129     char *name;
130     dev_t dev;
131     enum {havePath, isLocal, haveDev, isRemote} state;
132 };
133
134 extern struct inode *RemoteNamei();
135 extern int RemoteMaybe();
136 #endif /* KERNEL */
137
138 /*
139  * Message type codes for messages sent from the kernel.
140  * NB:  the kernel ignores the type field on reply (it merely matches
141  * sequence numbers).  Unexpected messages from an venus are ignored (they
142  * may have been destined for a process which has died in the meantime).
143  * At all times, the kernel tries to maintain its own integrity, so that
144  * in the worst case an venus restart should work fine.
145  */
146
147 /*
148  * In the capsule descriptions below, "(?)" means that the flagged item
149  * is probably a good candidate for negotiation.
150  */
151
152 #define RT_BOGUS        0
153 /* For debugging purposes in kernel */
154
155 #define RT_access       1
156 /* From kernel: 0: uninterpreted part of pathname
157  *              1: mode
158  * NB: uid/gid for this call are the real (not effective) uid/gid's.
159  * Response:    im_error
160  * if im_error == EABSPATH1 then:
161  *              0: Resolved absolute path name.
162  * NB: return value is implicit in im_error.
163  */
164
165 #define RT_chdir        2
166 /* From kernel: 0: uninterpreted part of pathname
167  * Vice I response:
168  *              0: new pathname (with ..'s removed, symbolic
169  *                 links NOT expanded).
170  *                 length<MAXPATHLEN.  Null terminated.
171  *              im_error
172  * Vice II response:
173  *              im_wdfid:  the file identifier (volume, vnode, unique)
174  *                 of the new working directory.
175  *              im_error
176  * if im_error == EABSPATH1 then:
177  *              0: Resolved absolute path name.
178  */
179
180 #define RT_chmod        3
181 /* From kernel: 0: uninterpreted part of pathname
182  *              1: mode
183  * Response:    im_error
184  * if im_error == EABSPATH1 then:
185  *              0: Resolved absolute path name.
186  */
187
188 #define RT_chown        4
189 /* From kernel: 0: uninterpreted part of pathname
190  *              1: new uid
191  *              2: new gid
192  * Response:    im_error
193  * if im_error == EABSPATH1 then:
194  *              0: Resolved absolute path name.
195  */
196
197 #define RT_close        5
198 /* From kernel: 0: file identifier.
199  *              im_error: either 0 or one of the error codes
200  *                        listed below (RTE_*, see RT_open).
201  * Response:    im_error (for programs that want to know)
202  * N.B.: close MUST always cleanup state; it will never be issued
203  * twice for the same identifier.  If RT_signal is received during
204  * a close, venus can use this as a hint to return early from the
205  * close.  Venus should not return EINTR for this system call, however.
206  */
207
208 #define RT_fchmod       6
209 /* From kernel: 0: file identifier
210  *              1: mode
211  * Response:    im_error
212  */
213
214 #define RT_fchown       7
215 /* From kernel: 0: file identifier
216  *              1: new uid
217  *              2: new gid
218  * Response:    im_error
219  */
220
221 #define RT_fcntl        8
222 /* Not implemented */
223
224 #define RT_flock        9
225 /* From kernel: 0: file identifier
226  *              1: operation
227  * Response:    im_error
228  */
229
230 #define RT_fstat        10
231 /* From kernel: 0: file identifier.
232  * Response:    0: struct stat
233  *              im_error
234  */
235
236 #define RT_fsync        11
237 /* From kernel: 0: file identifier.
238  * Response:    im_error
239  */
240
241 #define RT_ftruncate    12
242 /* From kernel: 0: file identifier.
243  *              1: truncated length. (? right now, kernel truncates
244  *                 open cached inode)
245  * Response:    im_error
246  */
247
248 #define RT_link         13
249 /* From kernel: 0: the uninterpreted part of the original path
250  *              1: the uninterpreted part of the pathname which
251  *                 will be the new link
252  * Response:    im_error
253  * if im_error == EABSPATH1 or EABSPATH2 then:
254  *              0: Resolved absolute path name.
255  */
256
257 #define RT_lstat        14
258 /* Obsolete--not generated by the kernel.  The im_follow1
259    field is used in conjunction with RT_stat to implement
260    lstat.  VICE I will continue to work since it does not
261    distinguish between stat and lstat */
262
263 #define RT_mkdir        15
264 /* From kernel: 0: uninterpreted part of pathname
265  *              1: mode
266  * Response:    im_error
267  * if im_error == EABSPATH1 then:
268  *              0: Resolved absolute path name.
269  */
270
271 #define RT_open         16
272 /* From kernel: 0: uninterpreted part of pathname
273  *              1: flags
274  *              2: mode
275  * Vice 1 Response:
276  *              0: file identifier assigned (for subsequent
277  *                 messages dealing with open files).
278  *              1: pathname of the local, cached file.  
279  *              im_error
280  * Note:        the returned filename is not created, truncated(?),
281  *              or otherwise fiddled with by the kernel.  It must
282  *              exist and must be a plain file.  N.B: Protection modes
283  *              are ignored when it is finally opened.  The exec bit,
284  *              however, should never be set unless the file is
285  *              really executable.  (It should never be set for
286  *              directories).  If there are problems opening the
287  *              file, the user gets an error, the kernel gets a close
288  *              message (possibly with one of the RTE_* errors, below,
289  *              set in im_error).
290  * Vice 2 Response:
291  *              0: file identifier assigned (for subsequent
292  *                 messages dealing with open files).
293  *              1: device where the file resides.
294  *              2: inode number of the file.
295  *              im_error
296  * if im_error == EABSPATH1 then:
297  *              0: Resolved absolute path name.
298  * (?) Non-blocking open.
299  */
300
301 #define RT_readlink     17
302 /* From kernel: 0: uninterpreted part of link pathname
303  * Response:    0: number of characters read from link
304  *              1: contents of link (not null terminated).  Size must not be
305  *                 greater than MAXPATHLEN (because this is checked by the
306  *                 kernel intercept code).
307  *              im_error
308  * if im_error == EABSPATH1 then:
309  *              0: Resolved absolute path name.
310  */
311
312 #define RT_rename       18
313 /* From kernel: 0: uninterpreted part of original pathname
314  *              1: ditto for new pathname
315  * Response:    im_error
316  * if im_error == EABSPATH1 or EABSPATH2 then:
317  *              0: Resolved absolute path name.
318  */
319
320 #define RT_rmdir        19
321 /* From kernel: 0: uninterpreted part of pathname
322  * Response:    im_error
323  * if im_error == EABSPATH1 then:
324  *              0: Resolved absolute path name.
325  */
326
327 #define RT_stat         20
328 /* From kernel: 0: uninterpreted part of pathname
329  * Response:    0: struct stat
330  *              im_error
331  * if im_error == EABSPATH1 then:
332  *              0: Resolved absolute path name.
333  * Note:  this now implements the lstat call, as well,
334  * by means of the im_follow1 field in the header.
335  */
336
337 #define RT_symlink      21
338 /* From kernel: 0: the string value of the new symbolic link.
339  *              1: the uninterpreted part of the pathname to
340  *                 contain the link.
341  * Response:    im_error
342  * if im_error == EABSPATH1 then:
343  *              0: Resolved absolute path name.
344  */
345
346 #define RT_truncate     22
347 /* From kernel: 0: uninterpreted part of pathname
348  *              1: truncated length
349  * Response:    im_error
350  * if im_error == EABSPATH1 then:
351  *              0: Resolved absolute path name.
352  */
353
354 #define RT_unlink       23
355 /* From kernel: 0: uninterpreted part of pathname
356  * Response:    im_error
357  * if im_error == EABSPATH1 then:
358  *              0: Resolved absolute path name.
359  */
360
361 #define RT_utimes       24
362 /* From kernel: 0: uninterpreted part of pathname
363  *              1: struct timeval tvp[2]
364  * Response:    im_error
365  * if im_error == EABSPATH1 then:
366  *              0: Resolved absolute path name.
367  */
368
369 #define RT_signal       25
370 /* Request to abort the previous operation requested WITH THE
371  * SAME im_seq FIELD.  No action is expected on the part of
372  * the venus--this is merely advice that the operation may
373  * be completed early.  VENUS SHOULD NOT REPLY TO THIS MESSAGE.
374  * The error returned on final completion by the venus need not
375  * acknowledge that the system call was interrupted.  The interrupt
376  * will occur at the end of the system call regardless.  EINTR
377  * should be returned if the system call actually is aborted.
378  * VENUS MAY RETURN EARLY FROM A   C L O S E  SYSTEM CALL, BUT MUST STILL
379  * CLEANUP STATE FOR THE CLOSE--ANOTHER CLOSE CALL FOR THE SAME
380  * DESCRIPTOR WILL NEVER BE ISSUED.
381  * RT_signal messages for which a reply has already been issued
382  * sholuld be ignored by venus.
383  */
384
385 #define RT_ioctl        26
386 /*
387  * From kernel: 0: file identifier
388  *              1: command (see below)
389  *              2: uninterpreted data (up to RT_MAXDATASIZE).
390  * Response:    0: data to be returned to user
391  *              im_error
392  * NOTE:  the information passed to/from venus is not in the
393  * same format as that coming to/from the user.  See the file
394  * vice.h.
395  */
396
397
398 #define RT_pioctl       27
399 /*
400  * From kernel: 0: uninterpreted part of pathname
401  *              1: command (as in RT_ioctl)
402  *              2: uninterpreted data
403  * Note: argument 3, do not follow symbolic links, is
404  *   obsolete; this is compatible with VICE I, since the
405  *   field was ignored anyway.
406  * Response:    0: data to be returned to user
407  *              im_error
408  * if im_error == EABSPATH1 then:
409  *              0: Resolved absolute path name.
410  */
411
412
413 /* Error codes -- each is set by the kernel for the explicit error indicated.
414  * These are set in im_error (which should normally be 0 in every message from
415  * the kernel).  Errors of this form indicate that the venus process has
416  * almost certainly done something wrong.  The associated user process gets an
417  * ERFS (remote file system error) for each of these error types.
418  */
419
420 /* The following error codes all occur at open (exec?) and are sent by the
421  * kernel with the associated close message for the file identifier returned
422  * from the open.
423  */
424
425 #define RTE_BADARG 1    /* The size of a structure or string argument returned
426                            by the venus to the kernel is bogus.
427                            (the im_size field is not zero, or part of the
428                            argument is outside the message buffer, or the
429                            argument is too large) */
430
431 #define RTE_NOFILE 2    /* The file name (or inode, in VICE II) returned to
432                            the kernel, to open or exec in lieu of the original
433                            name supplied by the process cannot be opened or
434                            exec'd */
435
436 #define RTE_NOTREG 3    /* The file (or inode, in VICE II) returned to the
437                            kernel, to open or exec in lieu of the original
438                            name supplied by the process, is not a IF_REG
439                            type file, i.e. it is a device, socket, or
440                            directory */
441
442
443 /* The following error codes are set by Venus when a pathname argument supplied
444  * by the kernel resolves to an absolute pathname outside of the name space 
445  * of this venus.  The resolved absolute pathname is returned in argument 0.
446  * The kernel is expected to retry the system call with this new information.
447  * The kernel never passes this error on to the original issuer of the system
448  * call.
449  */
450 #define EABSPATH1 126   /* The first pathname, or only pathname, of a system
451                            call resolved to an absolute pathname */
452 #define EABSPATH2 127   /* The second pathname of the rename or link system
453                            call resolved to an absolute pathname */