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