1 /* $NetBSD: coda.h,v 1.14 2007/03/04 06:01:11 christos Exp $ */
5 Coda: an Experimental Distributed File System
8 Copyright (c) 1987-1999 Carnegie Mellon University
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
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
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.
34 * Based on cfs.h from Mach, but revamped for increased simplicity.
35 * Linux modifications by
36 * Peter Braam, Aug 1996
42 #if defined(__NetBSD__) && defined(_KERNEL_OPT)
43 /* pull in optional CODA_COMPAT_5 flag */
44 #include "opt_coda_compat.h"
47 /* Catch new _KERNEL defn for NetBSD and DJGPP/__CYGWIN32__ */
48 #if defined(__NetBSD__) || \
49 ((defined(DJGPP) || defined(__CYGWIN32__)) && !defined(KERNEL))
50 #include <sys/types.h>
51 #include <sys/systm.h>
54 #ifndef CODA_MAXSYMLINKS
55 #define CODA_MAXSYMLINKS 10
58 #if defined(DJGPP) || defined(__CYGWIN32__)
60 typedef unsigned long u_long
;
61 typedef unsigned int u_int
;
62 typedef unsigned short u_short
;
67 typedef unsigned __int64 u_quad_t
;
69 typedef unsigned long long u_quad_t
;
78 #else /* DJGPP but not KERNEL */
80 typedef unsigned long long u_quad_t
;
85 #if defined(__linux__)
86 #define cdev_t u_quad_t
88 #if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
90 typedef unsigned long long u_quad_t
;
93 typedef unsigned long long u_quad_t
;
94 #endif /* __KERNEL__ */
99 /* Solaris Definitions */
101 #include <sys/types.h>
102 #include <sys/time.h>
103 typedef unsigned long long u_quad_t
;
104 #undef __BIT_TYPES_DEFINED__
107 /* Mac OS X / Darwin */
108 #if defined(__APPLE__) && defined(__MACH__)
109 #define __BIT_TYPES_DEFINED__
112 #ifndef __BIT_TYPES_DEFINED__
113 #define __BIT_TYPES_DEFINED__
114 typedef signed char int8_t;
115 typedef unsigned char u_int8_t
;
116 typedef short int16_t;
117 typedef unsigned short u_int16_t
;
119 typedef unsigned int u_int32_t
;
126 #define CODA_MAXNAMLEN 255
127 #define CODA_MAXPATHLEN 1024
128 #define CODA_MAXSYMLINK 10
130 /* these are Coda's version of O_RDONLY etc combinations
131 * to deal with VFS open modes
133 #define C_O_READ 0x001
134 #define C_O_WRITE 0x002
135 #define C_O_TRUNC 0x010
136 #define C_O_EXCL 0x100
137 #define C_O_CREAT 0x200
139 /* these are to find mode bits in Venus */
140 #define C_M_READ 00400
141 #define C_M_WRITE 00200
143 /* for access Venus will use */
144 #define C_A_C_OK 8 /* Test for writing upon create. */
145 #define C_A_R_OK 4 /* Test for read permission. */
146 #define C_A_W_OK 2 /* Test for write permission. */
147 #define C_A_X_OK 1 /* Test for execute permission. */
148 #define C_A_F_OK 0 /* Test for existence. */
151 #define _VENUS_DIRENT_T_ 1
152 struct venus_dirent
{
153 unsigned long d_fileno
; /* file number of entry */
154 unsigned short d_reclen
; /* length of this record */
155 unsigned short d_namlen
; /* length of string in d_name */
156 char d_name
[CODA_MAXNAMLEN
+ 1];/* name must be no longer than this */
159 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
160 (((dp)->d_namlen+1 + 3) &~ 3))
163 #ifndef _VENUS_DIRENT_T_
164 #define _VENUS_DIRENT_T_ 1
165 struct venus_dirent
{
166 unsigned long d_fileno
; /* file number of entry */
167 unsigned short d_reclen
; /* length of this record */
168 unsigned char d_type
; /* file type, see below */
169 unsigned char d_namlen
; /* length of string in d_name */
170 char d_name
[CODA_MAXNAMLEN
+ 1];/* name must be no longer than this */
173 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
174 (((dp)->d_namlen+1 + 3) &~ 3))
179 #define CDT_UNKNOWN 0
190 * Convert between stat structure types and directory types.
192 #define IFTOCDT(mode) (((mode) & 0170000) >> 12)
193 #define CDTTOIF(dirtype) ((dirtype) << 12)
205 static inline ino_t
coda_f2i(CodaFid
*fid
)
208 return (fid
->Unique
+ (fid
->Vnode
<<10) + (fid
->Volume
<<20));
211 static inline char * coda_f2s(CodaFid
*fid
)
213 static char fid_str
[35];
214 snprintf (fid_str
, 35, "[%lx.%lx.%lx]", fid
->Volume
,
215 fid
->Vnode
, fid
->Unique
);
219 static inline int coda_fid_eq (CodaFid
*fid1
, CodaFid
*fid2
)
221 return (fid1
->Volume
== fid2
->Volume
&&
222 fid1
->Vnode
== fid2
->Vnode
&&
223 fid1
->Unique
== fid2
->Unique
);
227 u_int32_t cr_uid
, cr_euid
, cr_suid
, cr_fsuid
; /* Real, efftve, set, fs uid*/
228 u_int32_t cr_groupid
, cr_egid
, cr_sgid
, cr_fsgid
; /* same for groups */
238 static inline ino_t
coda_f2i(CodaFid
*fid
)
241 return (fid
->opaque
[1] + (fid
->opaque
[2]<<10) + (fid
->opaque
[3]<<20));
244 static inline char * coda_f2s(CodaFid
*fid
)
246 static char fid_str
[35];
247 snprintf (fid_str
, 35, "[%x.%x.%x.%x]", fid
->opaque
[0],
248 fid
->opaque
[1], fid
->opaque
[2], fid
->opaque
[3]);
252 static inline int coda_fid_eq (CodaFid
*fid1
, CodaFid
*fid2
)
254 return (fid1
->opaque
[0] == fid2
->opaque
[0] &&
255 fid1
->opaque
[1] == fid2
->opaque
[1] &&
256 fid1
->opaque
[2] == fid2
->opaque
[2] &&
257 fid1
->opaque
[3] == fid2
->opaque
[3]);
262 #ifndef _VENUS_VATTR_T_
263 #define _VENUS_VATTR_T_
265 * Vnode types. VNON means no type.
267 enum coda_vtype
{ C_VNON
, C_VREG
, C_VDIR
, C_VBLK
, C_VCHR
, C_VLNK
, C_VSOCK
, C_VFIFO
, C_VBAD
};
270 long va_type
; /* vnode type (for create) */
271 u_short va_mode
; /* files access mode and type */
272 short va_nlink
; /* number of references to file */
273 uid_t va_uid
; /* owner user id */
274 gid_t va_gid
; /* owner group id */
275 u_long va_fileid
; /* file id */
276 u_quad_t va_size
; /* file size in bytes */
277 long va_blocksize
; /* blocksize preferred for i/o */
278 struct timespec va_atime
; /* time of last access */
279 struct timespec va_mtime
; /* time of last modification */
280 struct timespec va_ctime
; /* time file changed */
281 u_long va_gen
; /* generation number of file */
282 u_long va_flags
; /* flags defined for file */
283 cdev_t va_rdev
; /* device special file represents */
284 u_quad_t va_bytes
; /* bytes of disk space held by file */
285 u_quad_t va_filerev
; /* file modification number */
290 /* structure used by CODA_STATFS for getting cache information from venus */
300 * Kernel <--> Venus communications.
304 #define CODA_OPEN_BY_FD 3
308 #define CODA_GETATTR 7
309 #define CODA_SETATTR 8
310 #define CODA_ACCESS 9
311 #define CODA_LOOKUP 10
312 #define CODA_CREATE 11
313 #define CODA_REMOVE 12
315 #define CODA_RENAME 14
316 #define CODA_MKDIR 15
317 #define CODA_RMDIR 16
318 #define CODA_READDIR 17
319 #define CODA_SYMLINK 18
320 #define CODA_READLINK 19
321 #define CODA_FSYNC 20
322 #define CODA_INACTIVE 21
324 #define CODA_SIGNAL 23
325 #define CODA_REPLACE 24 /* DOWNCALL */
326 #define CODA_FLUSH 25 /* DOWNCALL */
327 #define CODA_PURGEUSER 26 /* DOWNCALL */
328 #define CODA_ZAPFILE 27 /* DOWNCALL */
329 #define CODA_ZAPDIR 28 /* DOWNCALL */
330 #define CODA_PURGEFID 30 /* DOWNCALL */
331 #define CODA_OPEN_BY_PATH 31
332 #define CODA_RESOLVE 32
333 #define CODA_REINTEGRATE 33
334 #define CODA_STATFS 34
335 #define CODA_NCALLS 35
337 #define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
339 #define VC_MAXDATASIZE 8192
340 #define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
343 #define CIOC_KERNEL_VERSION _IOWR('c', 10, sizeof (int))
346 #define CODA_KERNEL_VERSION 0 /* don't care about kernel version number */
347 #define CODA_KERNEL_VERSION 1 /* The old venus 4.6 compatible interface */
350 #define CODA_KERNEL_VERSION 2 /* venus_lookup gets an extra parameter */
352 #define CODA_KERNEL_VERSION 3 /* 128-bit fids for realms */
356 * Venus <-> Coda RPC arguments
360 unsigned long opcode
;
361 unsigned long unique
; /* Keep multiple outstanding msgs distinct */
362 u_short pid
; /* Common to all */
363 u_short pgid
; /* Common to all */
364 u_short sid
; /* Common to all */
365 struct coda_cred cred
; /* Common to all */
370 u_int32_t unique
; /* Keep multiple outstanding msgs distinct */
371 pid_t pid
; /* Common to all */
372 pid_t pgid
; /* Common to all */
373 uid_t uid
; /* Common to all */
377 /* Really important that opcode and unique are 1st two fields! */
378 struct coda_out_hdr
{
384 /* coda_root: NO_IN */
385 struct coda_root_out
{
386 struct coda_out_hdr oh
;
390 struct coda_root_in
{
391 struct coda_in_hdr in
;
395 struct coda_open_in
{
396 struct coda_in_hdr ih
;
401 struct coda_open_out
{
402 struct coda_out_hdr oh
;
404 ino_t inode
; /* host inode of container file */
409 struct coda_close_in
{
410 struct coda_in_hdr ih
;
415 struct coda_close_out
{
416 struct coda_out_hdr out
;
420 struct coda_ioctl_in
{
421 struct coda_in_hdr ih
;
426 char *data
; /* Place holder for data. */
429 struct coda_ioctl_out
{
430 struct coda_out_hdr oh
;
432 void * data
; /* Place holder for data. */
437 struct coda_getattr_in
{
438 struct coda_in_hdr ih
;
442 struct coda_getattr_out
{
443 struct coda_out_hdr oh
;
444 struct coda_vattr attr
;
448 /* coda_setattr: NO_OUT */
449 struct coda_setattr_in
{
450 struct coda_in_hdr ih
;
452 struct coda_vattr attr
;
455 struct coda_setattr_out
{
456 struct coda_out_hdr out
;
459 /* coda_access: NO_OUT */
460 struct coda_access_in
{
461 struct coda_in_hdr ih
;
466 struct coda_access_out
{
467 struct coda_out_hdr out
;
472 #define CLU_CASE_SENSITIVE 0x01
473 #define CLU_CASE_INSENSITIVE 0x02
476 struct coda_lookup_in
{
477 struct coda_in_hdr ih
;
479 int name
; /* Place holder for data. */
483 struct coda_lookup_out
{
484 struct coda_out_hdr oh
;
491 struct coda_create_in
{
492 struct coda_in_hdr ih
;
494 struct coda_vattr attr
;
497 int name
; /* Place holder for data. */
500 struct coda_create_out
{
501 struct coda_out_hdr oh
;
503 struct coda_vattr attr
;
507 /* coda_remove: NO_OUT */
508 struct coda_remove_in
{
509 struct coda_in_hdr ih
;
511 int name
; /* Place holder for data. */
514 struct coda_remove_out
{
515 struct coda_out_hdr out
;
518 /* coda_link: NO_OUT */
519 struct coda_link_in
{
520 struct coda_in_hdr ih
;
521 CodaFid sourceFid
; /* cnode to link *to* */
522 CodaFid destFid
; /* Directory in which to place link */
523 int tname
; /* Place holder for data. */
526 struct coda_link_out
{
527 struct coda_out_hdr out
;
531 /* coda_rename: NO_OUT */
532 struct coda_rename_in
{
533 struct coda_in_hdr ih
;
540 struct coda_rename_out
{
541 struct coda_out_hdr out
;
545 struct coda_mkdir_in
{
546 struct coda_in_hdr ih
;
548 struct coda_vattr attr
;
549 int name
; /* Place holder for data. */
552 struct coda_mkdir_out
{
553 struct coda_out_hdr oh
;
555 struct coda_vattr attr
;
559 /* coda_rmdir: NO_OUT */
560 struct coda_rmdir_in
{
561 struct coda_in_hdr ih
;
563 int name
; /* Place holder for data. */
566 struct coda_rmdir_out
{
567 struct coda_out_hdr out
;
571 struct coda_readdir_in
{
572 struct coda_in_hdr ih
;
578 struct coda_readdir_out
{
579 struct coda_out_hdr oh
;
581 void * data
; /* Place holder for data. */
584 /* coda_symlink: NO_OUT */
585 struct coda_symlink_in
{
586 struct coda_in_hdr ih
;
587 CodaFid Fid
; /* Directory to put symlink in */
589 struct coda_vattr attr
;
593 struct coda_symlink_out
{
594 struct coda_out_hdr out
;
598 struct coda_readlink_in
{
599 struct coda_in_hdr ih
;
603 struct coda_readlink_out
{
604 struct coda_out_hdr oh
;
606 void * data
; /* Place holder for data. */
610 /* coda_fsync: NO_OUT */
611 struct coda_fsync_in
{
612 struct coda_in_hdr ih
;
616 struct coda_fsync_out
{
617 struct coda_out_hdr out
;
621 struct coda_vget_in
{
622 struct coda_in_hdr ih
;
626 struct coda_vget_out
{
627 struct coda_out_hdr oh
;
633 /* CODA_SIGNAL is out-of-band, doesn't need data. */
634 /* CODA_INVALIDATE is a venus->kernel call */
635 /* CODA_FLUSH is a venus->kernel call */
637 /* coda_purgeuser: */
638 /* CODA_PURGEUSER is a venus->kernel call */
639 struct coda_purgeuser_out
{
640 struct coda_out_hdr oh
;
642 struct coda_cred cred
;
649 /* CODA_ZAPFILE is a venus->kernel call */
650 struct coda_zapfile_out
{
651 struct coda_out_hdr oh
;
656 /* CODA_ZAPDIR is a venus->kernel call */
657 struct coda_zapdir_out
{
658 struct coda_out_hdr oh
;
663 /* CODA_ZAPVNODE is a venus->kernel call */
664 struct coda_zapvnode_out
{
665 struct coda_out_hdr oh
;
667 struct coda_cred cred
;
673 /* CODA_PURGEFID is a venus->kernel call */
674 struct coda_purgefid_out
{
675 struct coda_out_hdr oh
;
680 /* CODA_REPLACE is a venus->kernel call */
681 struct coda_replace_out
{ /* coda_replace is a venus->kernel call */
682 struct coda_out_hdr oh
;
687 /* coda_open_by_fd: */
688 struct coda_open_by_fd_in
{
689 struct coda_in_hdr ih
;
694 struct coda_open_by_fd_out
{
695 struct coda_out_hdr oh
;
700 /* coda_open_by_path: */
701 struct coda_open_by_path_in
{
702 struct coda_in_hdr ih
;
707 struct coda_open_by_path_out
{
708 struct coda_out_hdr oh
;
712 /* coda_statfs: NO_IN */
713 struct coda_statfs_in
{
714 struct coda_in_hdr ih
;
717 struct coda_statfs_out
{
718 struct coda_out_hdr oh
;
719 struct coda_statfs stat
;
723 * Occasionally, we don't cache the fid returned by CODA_LOOKUP.
724 * For instance, if the fid is inconsistent.
725 * This case is handled by setting the top bit of the type result parameter.
727 #define CODA_NOCACHE 0x80000000
730 struct coda_in_hdr ih
; /* NB: every struct below begins with an ih */
731 struct coda_open_in coda_open
;
732 struct coda_close_in coda_close
;
733 struct coda_ioctl_in coda_ioctl
;
734 struct coda_getattr_in coda_getattr
;
735 struct coda_setattr_in coda_setattr
;
736 struct coda_access_in coda_access
;
737 struct coda_lookup_in coda_lookup
;
738 struct coda_create_in coda_create
;
739 struct coda_remove_in coda_remove
;
740 struct coda_link_in coda_link
;
741 struct coda_rename_in coda_rename
;
742 struct coda_mkdir_in coda_mkdir
;
743 struct coda_rmdir_in coda_rmdir
;
744 struct coda_readdir_in coda_readdir
;
745 struct coda_symlink_in coda_symlink
;
746 struct coda_readlink_in coda_readlink
;
747 struct coda_fsync_in coda_fsync
;
748 struct coda_vget_in coda_vget
;
749 struct coda_open_by_fd_in coda_open_by_fd
;
750 struct coda_open_by_path_in coda_open_by_path
;
751 struct coda_statfs_in coda_statfs
;
755 struct coda_out_hdr oh
; /* NB: every struct below begins with an oh */
756 struct coda_root_out coda_root
;
757 struct coda_open_out coda_open
;
758 struct coda_ioctl_out coda_ioctl
;
759 struct coda_getattr_out coda_getattr
;
760 struct coda_lookup_out coda_lookup
;
761 struct coda_create_out coda_create
;
762 struct coda_mkdir_out coda_mkdir
;
763 struct coda_readdir_out coda_readdir
;
764 struct coda_readlink_out coda_readlink
;
765 struct coda_vget_out coda_vget
;
766 struct coda_purgeuser_out coda_purgeuser
;
767 struct coda_zapfile_out coda_zapfile
;
768 struct coda_zapdir_out coda_zapdir
;
769 struct coda_zapvnode_out coda_zapvnode
;
770 struct coda_purgefid_out coda_purgefid
;
771 struct coda_replace_out coda_replace
;
772 struct coda_open_by_fd_out coda_open_by_fd
;
773 struct coda_open_by_path_out coda_open_by_path
;
774 struct coda_statfs_out coda_statfs
;
777 union coda_downcalls
{
778 /* CODA_INVALIDATE is a venus->kernel call */
779 /* CODA_FLUSH is a venus->kernel call */
780 struct coda_purgeuser_out purgeuser
;
781 struct coda_zapfile_out zapfile
;
782 struct coda_zapdir_out zapdir
;
783 struct coda_zapvnode_out zapvnode
;
784 struct coda_purgefid_out purgefid
;
785 struct coda_replace_out replace
;
790 * Used for identifying usage of "Control" and pioctls
793 #define PIOCPARM_MASK 0x0000ffff
795 void *in
, *out
; /* Data to be transferred in, or out */
796 short in_size
; /* Size of input buffer <= 2K */
797 short out_size
; /* Maximum size of output buffer, <= 2K */
803 #if defined(__CYGWIN32__) || defined(__NT_CODA__)
809 #define CODA_CONTROL ".CONTROL"
810 #define CODA_CONTROLLEN 8
812 #define CTL_FILE "/coda/.CONTROL"
816 #define CTL_FID { -1, -1, -1 }
817 #define IS_CTL_FID(fidp) ((fidp)->Volume == -1 &&\
818 (fidp)->Vnode == -1 &&\
819 (fidp)->Unique == -1)
820 #define INVAL_FID { 0, 0, 0 }
822 #define CTL_FID { { -1, -1, -1, -1 } }
823 #define IS_CTL_FID(fidp) ((fidp)->opaque[0] == -1 &&\
824 (fidp)->opaque[1] == -1 &&\
825 (fidp)->opaque[2] == -1 &&\
826 (fidp)->opaque[3] == -1)
827 #define INVAL_FID { { 0, 0, 0, 0 } }
830 /* Data passed to mount */
832 #define CODA_MOUNT_VERSION 1
834 struct coda_mount_data
{
836 int fd
; /* Opened device */