coda.h revision 1.3 1 /* $NetBSD: coda.h,v 1.3 1998/09/12 15:05:50 rvb Exp $ */
2
3 /*
4 *
5 * Coda: an Experimental Distributed File System
6 * Release 3.1
7 *
8 * Copyright (c) 1987-1998 Carnegie Mellon University
9 * All Rights Reserved
10 *
11 * Permission to use, copy, modify and distribute this software and its
12 * documentation is hereby granted, provided that both the copyright
13 * notice and this permission notice appear in all copies of the
14 * software, derivative works or modified versions, and any portions
15 * thereof, and that both notices appear in supporting documentation, and
16 * that credit is given to Carnegie Mellon University in all documents
17 * and publicity pertaining to direct or indirect use of this code or its
18 * derivatives.
19 *
20 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
21 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
22 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
23 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
24 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
25 * ANY DERIVATIVE WORK.
26 *
27 * Carnegie Mellon encourages users of this software to return any
28 * improvements or extensions that they make, and to grant Carnegie
29 * Mellon the rights to redistribute these changes without encumbrance.
30 *
31 * @(#) cfs/coda.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp
32 */
33
34 /*
35 *
36 * Based on cfs.h from Mach, but revamped for increased simplicity.
37 * Linux modifications by Peter Braam, Aug 1996
38 */
39
40 #ifndef _CODA_HEADER_
41 #define _CODA_HEADER_
42
43
44
45 /* Catch new _KERNEL defn for NetBSD */
46 #ifdef __NetBSD__
47 #include <sys/types.h>
48 #endif
49
50 #if defined(__linux__) || defined(__CYGWIN32__)
51 #define cdev_t u_quad_t
52 #if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
53 #define _UQUAD_T_ 1
54 typedef unsigned long long u_quad_t;
55 #endif
56 #else
57 #define cdev_t dev_t
58 #endif
59
60 #ifdef __CYGWIN32__
61 typedef unsigned char u_int8_t;
62 struct timespec {
63 time_t tv_sec; /* seconds */
64 long tv_nsec; /* nanoseconds */
65 };
66 #endif
67
68
69 /*
70 * Coda constants
71 */
72 #define CODA_MAXNAMLEN 255
73 #define CODA_MAXPATHLEN 1024
74 #define CODA_MAXSYMLINK 10
75
76 /* these are Coda's version of O_RDONLY etc combinations
77 * to deal with VFS open modes
78 */
79 #define C_O_READ 0x001
80 #define C_O_WRITE 0x002
81 #define C_O_TRUNC 0x010
82 #define C_O_EXCL 0x100
83
84 /* these are to find mode bits in Venus */
85 #define C_M_READ 00400
86 #define C_M_WRITE 00200
87
88 /* for access Venus will use */
89 #define C_A_R_OK 4 /* Test for read permission. */
90 #define C_A_W_OK 2 /* Test for write permission. */
91 #define C_A_X_OK 1 /* Test for execute permission. */
92 #define C_A_F_OK 0 /* Test for existence. */
93
94
95
96 #ifndef _VENUS_DIRENT_T_
97 #define _VENUS_DIRENT_T_ 1
98 struct venus_dirent {
99 unsigned long d_fileno; /* file number of entry */
100 unsigned short d_reclen; /* length of this record */
101 char d_type; /* file type, see below */
102 char d_namlen; /* length of string in d_name */
103 char d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
104 };
105 #undef DIRSIZ
106 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
107 (((dp)->d_namlen+1 + 3) &~ 3))
108
109 /*
110 * File types
111 */
112 #define CDT_UNKNOWN 0
113 #define CDT_FIFO 1
114 #define CDT_CHR 2
115 #define CDT_DIR 4
116 #define CDT_BLK 6
117 #define CDT_REG 8
118 #define CDT_LNK 10
119 #define CDT_SOCK 12
120 #define CDT_WHT 14
121
122 /*
123 * Convert between stat structure types and directory types.
124 */
125 #define IFTOCDT(mode) (((mode) & 0170000) >> 12)
126 #define CDTTOIF(dirtype) ((dirtype) << 12)
127
128 #endif
129
130 #ifndef _FID_T_
131 #define _FID_T_ 1
132 typedef u_long VolumeId;
133 typedef u_long VnodeId;
134 typedef u_long Unique_t;
135 typedef u_long FileVersion;
136 #endif
137
138 #ifndef _VICEFID_T_
139 #define _VICEFID_T_ 1
140 typedef struct ViceFid {
141 VolumeId Volume;
142 VnodeId Vnode;
143 Unique_t Unique;
144 } ViceFid;
145 #endif /* VICEFID */
146
147 #ifdef __linux__
148 static inline ino_t coda_f2i(struct ViceFid *fid)
149 {
150 if ( fid ) {
151 return (fid->Unique + (fid->Vnode << 10) + (fid->Volume << 20));
152 } else {
153 return 0;
154 }
155 }
156 #endif
157
158 #ifndef _VUID_T_
159 #define _VUID_T_
160 typedef u_long vuid_t;
161 typedef u_long vgid_t;
162 #endif /*_VUID_T_ */
163
164 #ifndef _CODACRED_T_
165 #define _CODACRED_T_
166 struct coda_cred {
167 vuid_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
168 #if defined(__NetBSD__) || defined(__FreeBSD__)
169 vgid_t cr_groupid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
170 #else
171 vgid_t cr_gid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
172 #endif
173 };
174 #endif
175
176 #ifndef _VENUS_VATTR_T_
177 #define _VENUS_VATTR_T_
178 /*
179 * Vnode types. VNON means no type.
180 */
181 enum coda_vtype { C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };
182
183 struct coda_vattr {
184 enum coda_vtype va_type; /* vnode type (for create) */
185 u_short va_mode; /* files access mode and type */
186 short va_nlink; /* number of references to file */
187 vuid_t va_uid; /* owner user id */
188 vgid_t va_gid; /* owner group id */
189 long va_fileid; /* file id */
190 u_quad_t va_size; /* file size in bytes */
191 long va_blocksize; /* blocksize preferred for i/o */
192 struct timespec va_atime; /* time of last access */
193 struct timespec va_mtime; /* time of last modification */
194 struct timespec va_ctime; /* time file changed */
195 u_long va_gen; /* generation number of file */
196 u_long va_flags; /* flags defined for file */
197 cdev_t va_rdev; /* device special file represents */
198 u_quad_t va_bytes; /* bytes of disk space held by file */
199 u_quad_t va_filerev; /* file modification number */
200 };
201
202 #endif
203
204 /*
205 * Kernel <--> Venus communications.
206 */
207
208 #define CODA_ROOT ((u_long) 2)
209 #define CODA_SYNC ((u_long) 3)
210 #define CODA_OPEN ((u_long) 4)
211 #define CODA_CLOSE ((u_long) 5)
212 #define CODA_IOCTL ((u_long) 6)
213 #define CODA_GETATTR ((u_long) 7)
214 #define CODA_SETATTR ((u_long) 8)
215 #define CODA_ACCESS ((u_long) 9)
216 #define CODA_LOOKUP ((u_long) 10)
217 #define CODA_CREATE ((u_long) 11)
218 #define CODA_REMOVE ((u_long) 12)
219 #define CODA_LINK ((u_long) 13)
220 #define CODA_RENAME ((u_long) 14)
221 #define CODA_MKDIR ((u_long) 15)
222 #define CODA_RMDIR ((u_long) 16)
223 #define CODA_READDIR ((u_long) 17)
224 #define CODA_SYMLINK ((u_long) 18)
225 #define CODA_READLINK ((u_long) 19)
226 #define CODA_FSYNC ((u_long) 20)
227 #define CODA_INACTIVE ((u_long) 21)
228 #define CODA_VGET ((u_long) 22)
229 #define CODA_SIGNAL ((u_long) 23)
230 #define CODA_REPLACE ((u_long) 24)
231 #define CODA_FLUSH ((u_long) 25)
232 #define CODA_PURGEUSER ((u_long) 26)
233 #define CODA_ZAPFILE ((u_long) 27)
234 #define CODA_ZAPDIR ((u_long) 28)
235 #define CODA_ZAPVNODE ((u_long) 29)
236 #define CODA_PURGEFID ((u_long) 30)
237 #define CODA_NCALLS 31
238
239 #define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
240
241 #define VC_MAXDATASIZE 8192
242 #define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
243 VC_MAXDATASIZE
244
245
246
247 /*
248 * Venus <-> Coda RPC arguments
249 */
250 struct coda_in_hdr {
251 unsigned long opcode;
252 unsigned long unique; /* Keep multiple outstanding msgs distinct */
253 u_short pid; /* Common to all */
254 u_short pgid; /* Common to all */
255 u_short sid; /* Common to all */
256 struct coda_cred cred; /* Common to all */
257 };
258
259 /* Really important that opcode and unique are 1st two fields! */
260 struct coda_out_hdr {
261 unsigned long opcode;
262 unsigned long unique;
263 unsigned long result;
264 };
265
266 /* coda_root: NO_IN */
267 struct coda_root_out {
268 struct coda_out_hdr oh;
269 ViceFid VFid;
270 };
271
272 struct coda_root_in {
273 struct coda_in_hdr in;
274 };
275
276 /* coda_sync: */
277 /* Nothing needed for coda_sync */
278
279 /* coda_open: */
280 struct coda_open_in {
281 struct coda_in_hdr ih;
282 ViceFid VFid;
283 int flags;
284 };
285
286 struct coda_open_out {
287 struct coda_out_hdr oh;
288 cdev_t dev;
289 ino_t inode;
290 };
291
292
293 /* coda_close: */
294 struct coda_close_in {
295 struct coda_in_hdr ih;
296 ViceFid VFid;
297 int flags;
298 };
299
300 struct coda_close_out {
301 struct coda_out_hdr out;
302 };
303
304 /* coda_ioctl: */
305 struct coda_ioctl_in {
306 struct coda_in_hdr ih;
307 ViceFid VFid;
308 int cmd;
309 int len;
310 int rwflag;
311 char *data; /* Place holder for data. */
312 };
313
314 struct coda_ioctl_out {
315 struct coda_out_hdr oh;
316 int len;
317 caddr_t data; /* Place holder for data. */
318 };
319
320
321 /* coda_getattr: */
322 struct coda_getattr_in {
323 struct coda_in_hdr ih;
324 ViceFid VFid;
325 };
326
327 struct coda_getattr_out {
328 struct coda_out_hdr oh;
329 struct coda_vattr attr;
330 };
331
332
333 /* coda_setattr: NO_OUT */
334 struct coda_setattr_in {
335 struct coda_in_hdr ih;
336 ViceFid VFid;
337 struct coda_vattr attr;
338 };
339
340 struct coda_setattr_out {
341 struct coda_out_hdr out;
342 };
343
344 /* coda_access: NO_OUT */
345 struct coda_access_in {
346 struct coda_in_hdr ih;
347 ViceFid VFid;
348 int flags;
349 };
350
351 struct coda_access_out {
352 struct coda_out_hdr out;
353 };
354
355 /* coda_lookup: */
356 struct coda_lookup_in {
357 struct coda_in_hdr ih;
358 ViceFid VFid;
359 int name; /* Place holder for data. */
360 };
361
362 struct coda_lookup_out {
363 struct coda_out_hdr oh;
364 ViceFid VFid;
365 int vtype;
366 };
367
368
369 /* coda_create: */
370 struct coda_create_in {
371 struct coda_in_hdr ih;
372 ViceFid VFid;
373 struct coda_vattr attr;
374 int excl;
375 int mode;
376 int name; /* Place holder for data. */
377 };
378
379 struct coda_create_out {
380 struct coda_out_hdr oh;
381 ViceFid VFid;
382 struct coda_vattr attr;
383 };
384
385
386 /* coda_remove: NO_OUT */
387 struct coda_remove_in {
388 struct coda_in_hdr ih;
389 ViceFid VFid;
390 int name; /* Place holder for data. */
391 };
392
393 struct coda_remove_out {
394 struct coda_out_hdr out;
395 };
396
397 /* coda_link: NO_OUT */
398 struct coda_link_in {
399 struct coda_in_hdr ih;
400 ViceFid sourceFid; /* cnode to link *to* */
401 ViceFid destFid; /* Directory in which to place link */
402 int tname; /* Place holder for data. */
403 };
404
405 struct coda_link_out {
406 struct coda_out_hdr out;
407 };
408
409
410 /* coda_rename: NO_OUT */
411 struct coda_rename_in {
412 struct coda_in_hdr ih;
413 ViceFid sourceFid;
414 int srcname;
415 ViceFid destFid;
416 int destname;
417 };
418
419 struct coda_rename_out {
420 struct coda_out_hdr out;
421 };
422
423 /* coda_mkdir: */
424 struct coda_mkdir_in {
425 struct coda_in_hdr ih;
426 ViceFid VFid;
427 struct coda_vattr attr;
428 int name; /* Place holder for data. */
429 };
430
431 struct coda_mkdir_out {
432 struct coda_out_hdr oh;
433 ViceFid VFid;
434 struct coda_vattr attr;
435 };
436
437
438 /* coda_rmdir: NO_OUT */
439 struct coda_rmdir_in {
440 struct coda_in_hdr ih;
441 ViceFid VFid;
442 int name; /* Place holder for data. */
443 };
444
445 struct coda_rmdir_out {
446 struct coda_out_hdr out;
447 };
448
449 /* coda_readdir: */
450 struct coda_readdir_in {
451 struct coda_in_hdr ih;
452 ViceFid VFid;
453 int count;
454 int offset;
455 };
456
457 struct coda_readdir_out {
458 struct coda_out_hdr oh;
459 int size;
460 caddr_t data; /* Place holder for data. */
461 };
462
463 /* coda_symlink: NO_OUT */
464 struct coda_symlink_in {
465 struct coda_in_hdr ih;
466 ViceFid VFid; /* Directory to put symlink in */
467 int srcname;
468 struct coda_vattr attr;
469 int tname;
470 };
471
472 struct coda_symlink_out {
473 struct coda_out_hdr out;
474 };
475
476 /* coda_readlink: */
477 struct coda_readlink_in {
478 struct coda_in_hdr ih;
479 ViceFid VFid;
480 };
481
482 struct coda_readlink_out {
483 struct coda_out_hdr oh;
484 int count;
485 caddr_t data; /* Place holder for data. */
486 };
487
488
489 /* coda_fsync: NO_OUT */
490 struct coda_fsync_in {
491 struct coda_in_hdr ih;
492 ViceFid VFid;
493 };
494
495 struct coda_fsync_out {
496 struct coda_out_hdr out;
497 };
498
499 /* coda_inactive: NO_OUT */
500 struct coda_inactive_in {
501 struct coda_in_hdr ih;
502 ViceFid VFid;
503 };
504
505 /* coda_vget: */
506 struct coda_vget_in {
507 struct coda_in_hdr ih;
508 ViceFid VFid;
509 };
510
511 struct coda_vget_out {
512 struct coda_out_hdr oh;
513 ViceFid VFid;
514 int vtype;
515 };
516
517
518 /* CODA_SIGNAL is out-of-band, doesn't need data. */
519 /* CODA_INVALIDATE is a venus->kernel call */
520 /* CODA_FLUSH is a venus->kernel call */
521
522 /* coda_purgeuser: */
523 /* CODA_PURGEUSER is a venus->kernel call */
524 struct coda_purgeuser_out {
525 struct coda_out_hdr oh;
526 struct coda_cred cred;
527 };
528
529 /* coda_zapfile: */
530 /* CODA_ZAPFILE is a venus->kernel call */
531 struct coda_zapfile_out {
532 struct coda_out_hdr oh;
533 ViceFid CodaFid;
534 };
535
536 /* coda_zapdir: */
537 /* CODA_ZAPDIR is a venus->kernel call */
538 struct coda_zapdir_out {
539 struct coda_out_hdr oh;
540 ViceFid CodaFid;
541 };
542
543 /* coda_zapnode: */
544 /* CODA_ZAPVNODE is a venus->kernel call */
545 struct coda_zapvnode_out {
546 struct coda_out_hdr oh;
547 struct coda_cred cred;
548 ViceFid VFid;
549 };
550
551 /* coda_purgefid: */
552 /* CODA_PURGEFID is a venus->kernel call */
553 struct coda_purgefid_out {
554 struct coda_out_hdr oh;
555 ViceFid CodaFid;
556 };
557
558 /* coda_rdwr: */
559 struct coda_rdwr_in {
560 struct coda_in_hdr ih;
561 ViceFid VFid;
562 int rwflag;
563 int count;
564 int offset;
565 int ioflag;
566 caddr_t data; /* Place holder for data. */
567 };
568
569 struct coda_rdwr_out {
570 struct coda_out_hdr oh;
571 int rwflag;
572 int count;
573 caddr_t data; /* Place holder for data. */
574 };
575
576
577 /* coda_replace: */
578 /* CODA_REPLACE is a venus->kernel call */
579 struct coda_replace_out { /* coda_replace is a venus->kernel call */
580 struct coda_out_hdr oh;
581 ViceFid NewFid;
582 ViceFid OldFid;
583 };
584
585 /*
586 * Occasionally, don't cache the fid returned by CODA_LOOKUP. For instance, if
587 * the fid is inconsistent. This case is handled by setting the top bit of the
588 * return result parameter.
589 */
590 #define CODA_NOCACHE 0x80000000
591
592 union inputArgs {
593 struct coda_in_hdr ih; /* NB: every struct below begins with an ih */
594 struct coda_open_in coda_open;
595 struct coda_close_in coda_close;
596 struct coda_ioctl_in coda_ioctl;
597 struct coda_getattr_in coda_getattr;
598 struct coda_setattr_in coda_setattr;
599 struct coda_access_in coda_access;
600 struct coda_lookup_in coda_lookup;
601 struct coda_create_in coda_create;
602 struct coda_remove_in coda_remove;
603 struct coda_link_in coda_link;
604 struct coda_rename_in coda_rename;
605 struct coda_mkdir_in coda_mkdir;
606 struct coda_rmdir_in coda_rmdir;
607 struct coda_readdir_in coda_readdir;
608 struct coda_symlink_in coda_symlink;
609 struct coda_readlink_in coda_readlink;
610 struct coda_fsync_in coda_fsync;
611 struct coda_inactive_in coda_inactive;
612 struct coda_vget_in coda_vget;
613 struct coda_rdwr_in coda_rdwr;
614 };
615
616 union outputArgs {
617 struct coda_out_hdr oh; /* NB: every struct below begins with an oh */
618 struct coda_root_out coda_root;
619 struct coda_open_out coda_open;
620 struct coda_ioctl_out coda_ioctl;
621 struct coda_getattr_out coda_getattr;
622 struct coda_lookup_out coda_lookup;
623 struct coda_create_out coda_create;
624 struct coda_mkdir_out coda_mkdir;
625 struct coda_readdir_out coda_readdir;
626 struct coda_readlink_out coda_readlink;
627 struct coda_vget_out coda_vget;
628 struct coda_purgeuser_out coda_purgeuser;
629 struct coda_zapfile_out coda_zapfile;
630 struct coda_zapdir_out coda_zapdir;
631 struct coda_zapvnode_out coda_zapvnode;
632 struct coda_purgefid_out coda_purgefid;
633 struct coda_rdwr_out coda_rdwr;
634 struct coda_replace_out coda_replace;
635 };
636
637 union coda_downcalls {
638 /* CODA_INVALIDATE is a venus->kernel call */
639 /* CODA_FLUSH is a venus->kernel call */
640 struct coda_purgeuser_out purgeuser;
641 struct coda_zapfile_out zapfile;
642 struct coda_zapdir_out zapdir;
643 struct coda_zapvnode_out zapvnode;
644 struct coda_purgefid_out purgefid;
645 struct coda_replace_out replace;
646 };
647
648
649 /*
650 * Used for identifying usage of "Control" and pioctls
651 */
652
653 #define PIOCPARM_MASK 0x0000ffff
654 struct ViceIoctl {
655 caddr_t in, out; /* Data to be transferred in, or out */
656 short in_size; /* Size of input buffer <= 2K */
657 short out_size; /* Maximum size of output buffer, <= 2K */
658 };
659
660 struct PioctlData {
661 const char *path;
662 int follow;
663 struct ViceIoctl vi;
664 };
665
666 #define CODA_CONTROL ".CONTROL"
667 #define CODA_CONTROLLEN 8
668 #define CTL_VOL -1
669 #define CTL_VNO -1
670 #define CTL_UNI -1
671 #define CTL_INO -1
672 #define CTL_FILE "/coda/.CONTROL"
673
674
675 #define IS_CTL_FID(fidp) ((fidp)->Volume == CTL_VOL &&\
676 (fidp)->Vnode == CTL_VNO &&\
677 (fidp)->Unique == CTL_UNI)
678 #endif
679
680