Allow passing in human-readable units for specifying amounts of space
[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 /*
11  * In which the structures needed to facilitate interception of file system
12  * related system calls by a user process ("agent", or "venus").
13  */
14
15 #define RT_VERSION      3       /* Version number, should be incremented
16                                  * before incompatible changes are released */
17 /*
18  *      Version 1 - April 4/84.
19  *      Version 2 - May 4/84.
20  *      Version 3 - May 30/85.
21  *      Version 4 - June 19/85.
22  */
23
24 /* Maximum number of arguments to a system call */
25 #define RT_MAX_ARGS             ( (sizeof u.u_arg) / (sizeof (int)) )
26
27 #ifndef KERNEL
28 extern struct user u;
29 #endif /* KERNEL */
30 /* Maximum size of combined string or structure arguments passed between
31    the kernel and a venus */
32 #define RT_MAXDATASIZE          (MAXPATHLEN*2)
33
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
39                                  * transaction */
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.
43                                  * Never 0 */
44     afs_int32 im_wdfid[3];      /* Current directory on the remote file system
45                                  * Vice II only. */
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 */
54     struct im_arg {
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 */
66 };
67
68
69
70 #define RT_HEADERSIZE   ((sizeof (struct intercept_message)) - RT_MAXDATASIZE)
71
72 #ifdef KERNEL
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.
76  */
77 #ifdef sun
78 #define RMT_MAJ         30
79 #endif
80 #ifdef vax
81 #define RMT_MAJ         33
82 #endif
83
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 */
87
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. */
93 struct remote {
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
99                                  * this structure */
100     char rt_read;               /* wait channel for a venus waiting for an
101                                  * intercept */
102     char rt_reply;              /* wait channel for a client process waiting
103                                  * for a reply */
104     struct intercept_message rt_imr;    /* buffer for agent reads */
105     struct intercept_message rt_imw;    /* buffer for agent writes */
106 #include "rfs.h"
107 } remote[NRFS];
108 #undef NRFS
109
110 /* Hack to unfold code for multiple devices */
111 #define rmt     (*rmtp)
112 #define devhack(dev) register struct remote *rmtp = &remote[minor(dev)]
113
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 */
121
122 /* This bogus stuff is used for rename/link */
123 struct Name {
124     int func;                   /* This used to be a function in BSD 4.2... */
125     int follow;
126     struct buf *buf;
127     char *name;
128     dev_t dev;
129     enum { havePath, isLocal, haveDev, isRemote } state;
130 };
131
132 extern struct inode *RemoteNamei();
133 extern int RemoteMaybe();
134 #endif /* KERNEL */
135
136 /*
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.
143  */
144
145 /*
146  * In the capsule descriptions below, "(?)" means that the flagged item
147  * is probably a good candidate for negotiation.
148  */
149
150 #define RT_BOGUS        0
151 /* For debugging purposes in kernel */
152
153 #define RT_access       1
154 /* From kernel: 0: uninterpreted part of pathname
155  *              1: mode
156  * NB: uid/gid for this call are the real (not effective) uid/gid's.
157  * Response:    im_error
158  * if im_error == EABSPATH1 then:
159  *              0: Resolved absolute path name.
160  * NB: return value is implicit in im_error.
161  */
162
163 #define RT_chdir        2
164 /* From kernel: 0: uninterpreted part of pathname
165  * Vice I response:
166  *              0: new pathname (with ..'s removed, symbolic
167  *                 links NOT expanded).
168  *                 length<MAXPATHLEN.  Null terminated.
169  *              im_error
170  * Vice II response:
171  *              im_wdfid:  the file identifier (volume, vnode, unique)
172  *                 of the new working directory.
173  *              im_error
174  * if im_error == EABSPATH1 then:
175  *              0: Resolved absolute path name.
176  */
177
178 #define RT_chmod        3
179 /* From kernel: 0: uninterpreted part of pathname
180  *              1: mode
181  * Response:    im_error
182  * if im_error == EABSPATH1 then:
183  *              0: Resolved absolute path name.
184  */
185
186 #define RT_chown        4
187 /* From kernel: 0: uninterpreted part of pathname
188  *              1: new uid
189  *              2: new gid
190  * Response:    im_error
191  * if im_error == EABSPATH1 then:
192  *              0: Resolved absolute path name.
193  */
194
195 #define RT_close        5
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.
204  */
205
206 #define RT_fchmod       6
207 /* From kernel: 0: file identifier
208  *              1: mode
209  * Response:    im_error
210  */
211
212 #define RT_fchown       7
213 /* From kernel: 0: file identifier
214  *              1: new uid
215  *              2: new gid
216  * Response:    im_error
217  */
218
219 #define RT_fcntl        8
220 /* Not implemented */
221
222 #define RT_flock        9
223 /* From kernel: 0: file identifier
224  *              1: operation
225  * Response:    im_error
226  */
227
228 #define RT_fstat        10
229 /* From kernel: 0: file identifier.
230  * Response:    0: struct stat
231  *              im_error
232  */
233
234 #define RT_fsync        11
235 /* From kernel: 0: file identifier.
236  * Response:    im_error
237  */
238
239 #define RT_ftruncate    12
240 /* From kernel: 0: file identifier.
241  *              1: truncated length. (? right now, kernel truncates
242  *                 open cached inode)
243  * Response:    im_error
244  */
245
246 #define RT_link         13
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
250  * Response:    im_error
251  * if im_error == EABSPATH1 or EABSPATH2 then:
252  *              0: Resolved absolute path name.
253  */
254
255 #define RT_lstat        14
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 */
260
261 #define RT_mkdir        15
262 /* From kernel: 0: uninterpreted part of pathname
263  *              1: mode
264  * Response:    im_error
265  * if im_error == EABSPATH1 then:
266  *              0: Resolved absolute path name.
267  */
268
269 #define RT_open         16
270 /* From kernel: 0: uninterpreted part of pathname
271  *              1: flags
272  *              2: mode
273  * Vice 1 Response:
274  *              0: file identifier assigned (for subsequent
275  *                 messages dealing with open files).
276  *              1: pathname of the local, cached file.  
277  *              im_error
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,
287  *              set in im_error).
288  * Vice 2 Response:
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.
293  *              im_error
294  * if im_error == EABSPATH1 then:
295  *              0: Resolved absolute path name.
296  * (?) Non-blocking open.
297  */
298
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).
305  *              im_error
306  * if im_error == EABSPATH1 then:
307  *              0: Resolved absolute path name.
308  */
309
310 #define RT_rename       18
311 /* From kernel: 0: uninterpreted part of original pathname
312  *              1: ditto for new pathname
313  * Response:    im_error
314  * if im_error == EABSPATH1 or EABSPATH2 then:
315  *              0: Resolved absolute path name.
316  */
317
318 #define RT_rmdir        19
319 /* From kernel: 0: uninterpreted part of pathname
320  * Response:    im_error
321  * if im_error == EABSPATH1 then:
322  *              0: Resolved absolute path name.
323  */
324
325 #define RT_stat         20
326 /* From kernel: 0: uninterpreted part of pathname
327  * Response:    0: struct stat
328  *              im_error
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.
333  */
334
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
338  *                 contain the link.
339  * Response:    im_error
340  * if im_error == EABSPATH1 then:
341  *              0: Resolved absolute path name.
342  */
343
344 #define RT_truncate     22
345 /* From kernel: 0: uninterpreted part of pathname
346  *              1: truncated length
347  * Response:    im_error
348  * if im_error == EABSPATH1 then:
349  *              0: Resolved absolute path name.
350  */
351
352 #define RT_unlink       23
353 /* From kernel: 0: uninterpreted part of pathname
354  * Response:    im_error
355  * if im_error == EABSPATH1 then:
356  *              0: Resolved absolute path name.
357  */
358
359 #define RT_utimes       24
360 /* From kernel: 0: uninterpreted part of pathname
361  *              1: struct timeval tvp[2]
362  * Response:    im_error
363  * if im_error == EABSPATH1 then:
364  *              0: Resolved absolute path name.
365  */
366
367 #define RT_signal       25
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.
381  */
382
383 #define RT_ioctl        26
384 /*
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
389  *              im_error
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
392  * vice.h.
393  */
394
395
396 #define RT_pioctl       27
397 /*
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
405  *              im_error
406  * if im_error == EABSPATH1 then:
407  *              0: Resolved absolute path name.
408  */
409
410
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.
416  */
417
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
420  * from the open.
421  */
422
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) */
428
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
432                                  * exec'd */
433
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
438                                  * directory */
439
440
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
446  * call.
447  */
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 */