3 * Coda: an Experimental Distributed File System
6 * Copyright (c) 1987-1998 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation, and
14 * that credit is given to Carnegie Mellon University in all documents
15 * and publicity pertaining to direct or indirect use of this code or its
18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
23 * ANY DERIVATIVE WORK.
25 * Carnegie Mellon encourages users of this software to return any
26 * improvements or extensions that they make, and to grant Carnegie
27 * Mellon the rights to redistribute these changes without encumbrance.
29 * @(#) src/sys/coda/coda.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
37 * Based on cfs.h from Mach, but revamped for increased simplicity.
38 * Linux modifications by Peter Braam, Aug 1996
45 #include "opt_coda.h" /* for CODA_COMPAT_5 option */
48 /* Avoid CODA_COMPAT_5 redefinition in coda5 module */
49 #if defined (CODA5_MODULE) && !defined(CODA_COMPAT_5)
53 /* Catch new _KERNEL defn for NetBSD */
55 #include <sys/types.h>
58 #ifndef CODA_MAXSYMLINKS
59 #define CODA_MAXSYMLINKS 10
62 #if defined(DJGPP) || defined(__CYGWIN32__)
64 typedef unsigned long u_long;
65 typedef unsigned int u_int;
66 typedef unsigned short u_short;
68 typedef u_long struct cdev *;
69 typedef void * caddr_t;
71 typedef unsigned __int64 u_quad_t;
73 typedef unsigned long long u_quad_t;
82 #else /* DJGPP but not _KERNEL */
83 #include <sys/types.h>
85 typedef unsigned long long u_quad_t;
90 #if defined(__linux__)
91 #define cdev_t u_quad_t
92 #if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
94 typedef unsigned long long u_quad_t;
101 typedef unsigned char u_int8_t;
103 time_t tv_sec; /* seconds */
104 long tv_nsec; /* nanoseconds */
108 typedef u_int32_t cuid_t;
109 typedef u_int32_t cgid_t;
114 #define CODA_MAXNAMLEN 255
115 #define CODA_MAXPATHLEN 1024
116 #define CODA_MAXSYMLINK 10
118 /* these are Coda's version of O_RDONLY etc combinations
119 * to deal with VFS open modes
121 #define C_O_READ 0x001
122 #define C_O_WRITE 0x002
123 #define C_O_TRUNC 0x010
124 #define C_O_EXCL 0x100
125 #define C_O_CREAT 0x200
127 /* these are to find mode bits in Venus */
128 #define C_M_READ 00400
129 #define C_M_WRITE 00200
131 /* for access Venus will use */
132 #define C_A_C_OK 8 /* Test for writing upon create. */
133 #define C_A_R_OK 4 /* Test for read permission. */
134 #define C_A_W_OK 2 /* Test for write permission. */
135 #define C_A_X_OK 1 /* Test for execute permission. */
136 #define C_A_F_OK 0 /* Test for existence. */
139 #ifndef _VENUS_DIRENT_T_
140 #define _VENUS_DIRENT_T_ 1
141 struct venus_dirent {
142 unsigned int d_fileno; /* file number of entry */
143 unsigned short d_reclen; /* length of this record */
144 unsigned char d_type; /* file type, see below */
145 unsigned char d_namlen; /* length of string in d_name */
146 char d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
149 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
150 (((dp)->d_namlen+1 + 3) &~ 3))
155 #define CDT_UNKNOWN 0
166 * Convert between stat structure types and directory types.
168 #define IFTOCDT(mode) (((mode) & 0170000) >> 12)
169 #define CDTTOIF(dirtype) ((dirtype) << 12)
181 static __inline__ ino_t coda_f2i(struct CodaFid *fid)
184 return (fid->Unique + (fid->Vnode<<10) + (fid->Volume<<20));
187 static __inline__ char * coda_f2s(struct CodaFid *fid)
189 static char fid_str [35];
190 snprintf (fid_str, 35, "[%lx.%lx.%lx]", fid->Volume,
191 fid->Vnode, fid->Unique);
195 static __inline__ int coda_fid_eq (struct CodaFid *fid1, struct CodaFid *fid2)
197 return (fid1->Volume == fid2->Volume &&
198 fid1->Vnode == fid2->Vnode &&
199 fid1->Unique == fid2->Unique);
203 u_int32_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
204 u_int32_t cr_groupid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
207 #else /* CODA_COMPAT_5 */
213 static __inline__ ino_t coda_f2i(struct CodaFid *fid)
217 return (fid->opaque[3] ^ (fid->opaque[2]<<10) ^ (fid->opaque[1]<<20) ^ fid->opaque[0]);
220 static __inline__ char * coda_f2s(struct CodaFid *fid)
222 static char fid_str [35];
223 snprintf (fid_str, 35, "[%x.%x.%x.%x]", fid->opaque[0],
224 fid->opaque[1], fid->opaque[2], fid->opaque[3]);
228 static __inline__ int coda_fid_eq (struct CodaFid *fid1, struct CodaFid *fid2)
230 return (fid1->opaque[0] == fid2->opaque[0] &&
231 fid1->opaque[1] == fid2->opaque[1] &&
232 fid1->opaque[2] == fid2->opaque[2] &&
233 fid1->opaque[3] == fid2->opaque[3]);
236 #endif /* CODA_COMPAT_5 */
238 #ifndef _VENUS_VATTR_T_
239 #define _VENUS_VATTR_T_
241 * Vnode types. VNON means no type.
243 enum coda_vtype { C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };
246 long va_type; /* vnode type (for create) */
247 u_short va_mode; /* files access mode and type */
248 short va_nlink; /* number of references to file */
249 cuid_t va_uid; /* owner user id */
250 cgid_t va_gid; /* owner group id */
251 long va_fileid; /* file id */
252 u_quad_t va_size; /* file size in bytes */
253 long va_blocksize; /* blocksize preferred for i/o */
254 struct timespec va_atime; /* time of last access */
255 struct timespec va_mtime; /* time of last modification */
256 struct timespec va_ctime; /* time file changed */
257 u_long va_gen; /* generation number of file */
258 u_long va_flags; /* flags defined for file */
259 cdev_t va_rdev; /* device special file represents */
260 u_quad_t va_bytes; /* bytes of disk space held by file */
261 u_quad_t va_filerev; /* file modification number */
266 /* structure used by CODA_STATFS for getting cache information from venus */
276 * Kernel <--> Venus communications.
280 #define CODA_OPEN_BY_FD 3
284 #define CODA_GETATTR 7
285 #define CODA_SETATTR 8
286 #define CODA_ACCESS 9
287 #define CODA_LOOKUP 10
288 #define CODA_CREATE 11
289 #define CODA_REMOVE 12
291 #define CODA_RENAME 14
292 #define CODA_MKDIR 15
293 #define CODA_RMDIR 16
294 #define CODA_READDIR 17
295 #define CODA_SYMLINK 18
296 #define CODA_READLINK 19
297 #define CODA_FSYNC 20
298 #define CODA_INACTIVE 21
300 #define CODA_SIGNAL 23
301 #define CODA_REPLACE 24
302 #define CODA_FLUSH 25
303 #define CODA_PURGEUSER 26
304 #define CODA_ZAPFILE 27
305 #define CODA_ZAPDIR 28
306 #define CODA_PURGEFID 30
307 #define CODA_OPEN_BY_PATH 31
308 #define CODA_RESOLVE 32
309 #define CODA_REINTEGRATE 33
310 #define CODA_STATFS 34
311 #define CODA_NCALLS 35
313 #define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
315 #define VC_MAXDATASIZE 8192
316 #define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
319 #define CIOC_KERNEL_VERSION _IOWR('c', 10, int)
321 /* don't care about kernel version number */
322 #define CODA_KERNEL_VERSION 0
323 /* The old venus 4.6 compatible interface */
324 #define CODA_KERNEL_VERSION 1
325 #endif /* realms/cells */
327 /* venus_lookup gets an extra parameter to aid windows.*/
328 #define CODA_KERNEL_VERSION 2
330 /* 128-bit fids for realms */
331 #define CODA_KERNEL_VERSION 3
335 * Venus <-> Coda RPC arguments
339 unsigned long opcode;
340 unsigned long unique; /* Keep multiple outstanding msgs distinct */
341 u_short pid; /* Common to all */
342 u_short pgid; /* Common to all */
343 u_short sid; /* Common to all */
344 struct coda_cred cred; /* Common to all */
349 u_int32_t unique; /* Keep multiple outstanding msgs distinct */
356 /* Really important that opcode and unique are 1st two fields! */
357 struct coda_out_hdr {
363 /* coda_root: NO_IN */
364 struct coda_root_out {
365 struct coda_out_hdr oh;
369 struct coda_root_in {
370 struct coda_in_hdr in;
374 /* Nothing needed for coda_sync */
377 struct coda_open_in {
378 struct coda_in_hdr ih;
383 struct coda_open_out {
384 struct coda_out_hdr oh;
391 struct coda_close_in {
392 struct coda_in_hdr ih;
397 struct coda_close_out {
398 struct coda_out_hdr out;
402 struct coda_ioctl_in {
403 struct coda_in_hdr ih;
408 char *data; /* Place holder for data. */
411 struct coda_ioctl_out {
412 struct coda_out_hdr oh;
414 caddr_t data; /* Place holder for data. */
419 struct coda_getattr_in {
420 struct coda_in_hdr ih;
424 struct coda_getattr_out {
425 struct coda_out_hdr oh;
426 struct coda_vattr attr;
430 /* coda_setattr: NO_OUT */
431 struct coda_setattr_in {
432 struct coda_in_hdr ih;
434 struct coda_vattr attr;
437 struct coda_setattr_out {
438 struct coda_out_hdr out;
441 /* coda_access: NO_OUT */
442 struct coda_access_in {
443 struct coda_in_hdr ih;
448 struct coda_access_out {
449 struct coda_out_hdr out;
454 #define CLU_CASE_SENSITIVE 0x01
455 #define CLU_CASE_INSENSITIVE 0x02
458 struct coda_lookup_in {
459 struct coda_in_hdr ih;
461 int name; /* Place holder for data. */
465 struct coda_lookup_out {
466 struct coda_out_hdr oh;
473 struct coda_create_in {
474 struct coda_in_hdr ih;
476 struct coda_vattr attr;
479 int name; /* Place holder for data. */
482 struct coda_create_out {
483 struct coda_out_hdr oh;
485 struct coda_vattr attr;
489 /* coda_remove: NO_OUT */
490 struct coda_remove_in {
491 struct coda_in_hdr ih;
493 int name; /* Place holder for data. */
496 struct coda_remove_out {
497 struct coda_out_hdr out;
500 /* coda_link: NO_OUT */
501 struct coda_link_in {
502 struct coda_in_hdr ih;
503 struct CodaFid sourceFid; /* cnode to link *to* */
504 struct CodaFid destFid; /* Directory in which to place link */
505 int tname; /* Place holder for data. */
508 struct coda_link_out {
509 struct coda_out_hdr out;
513 /* coda_rename: NO_OUT */
514 struct coda_rename_in {
515 struct coda_in_hdr ih;
516 struct CodaFid sourceFid;
518 struct CodaFid destFid;
522 struct coda_rename_out {
523 struct coda_out_hdr out;
527 struct coda_mkdir_in {
528 struct coda_in_hdr ih;
530 struct coda_vattr attr;
531 int name; /* Place holder for data. */
534 struct coda_mkdir_out {
535 struct coda_out_hdr oh;
537 struct coda_vattr attr;
541 /* coda_rmdir: NO_OUT */
542 struct coda_rmdir_in {
543 struct coda_in_hdr ih;
545 int name; /* Place holder for data. */
548 struct coda_rmdir_out {
549 struct coda_out_hdr out;
553 struct coda_readdir_in {
554 struct coda_in_hdr ih;
560 struct coda_readdir_out {
561 struct coda_out_hdr oh;
563 caddr_t data; /* Place holder for data. */
566 /* coda_symlink: NO_OUT */
567 struct coda_symlink_in {
568 struct coda_in_hdr ih;
569 struct CodaFid Fid; /* Directory to put symlink in */
571 struct coda_vattr attr;
575 struct coda_symlink_out {
576 struct coda_out_hdr out;
580 struct coda_readlink_in {
581 struct coda_in_hdr ih;
585 struct coda_readlink_out {
586 struct coda_out_hdr oh;
588 caddr_t data; /* Place holder for data. */
592 /* coda_fsync: NO_OUT */
593 struct coda_fsync_in {
594 struct coda_in_hdr ih;
598 struct coda_fsync_out {
599 struct coda_out_hdr out;
602 /* coda_inactive: NO_OUT */
603 struct coda_inactive_in {
604 struct coda_in_hdr ih;
609 struct coda_vget_in {
610 struct coda_in_hdr ih;
614 struct coda_vget_out {
615 struct coda_out_hdr oh;
621 /* CODA_SIGNAL is out-of-band, doesn't need data. */
622 /* CODA_INVALIDATE is a venus->kernel call */
623 /* CODA_FLUSH is a venus->kernel call */
625 /* coda_purgeuser: */
626 /* CODA_PURGEUSER is a venus->kernel call */
627 struct coda_purgeuser_out {
628 struct coda_out_hdr oh;
630 struct coda_cred cred;
637 /* CODA_ZAPFILE is a venus->kernel call */
638 struct coda_zapfile_out {
639 struct coda_out_hdr oh;
644 /* CODA_ZAPDIR is a venus->kernel call */
645 struct coda_zapdir_out {
646 struct coda_out_hdr oh;
651 /* CODA_ZAPVNODE is a venus->kernel call */
652 struct coda_zapvnode_out {
653 struct coda_out_hdr oh;
655 struct coda_cred cred;
661 /* CODA_PURGEFID is a venus->kernel call */
662 struct coda_purgefid_out {
663 struct coda_out_hdr oh;
668 /* CODA_REPLACE is a venus->kernel call */
669 struct coda_replace_out { /* coda_replace is a venus->kernel call */
670 struct coda_out_hdr oh;
671 struct CodaFid NewFid;
672 struct CodaFid OldFid;
675 /* coda_open_by_fd: */
676 struct coda_open_by_fd_in {
677 struct coda_in_hdr ih;
682 struct coda_open_by_fd_out {
683 struct coda_out_hdr oh;
686 /* not passed from userspace but used in-kernel only */
691 /* coda_open_by_path: */
692 struct coda_open_by_path_in {
693 struct coda_in_hdr ih;
698 struct coda_open_by_path_out {
699 struct coda_out_hdr oh;
703 /* coda_statfs: NO_IN */
704 struct coda_statfs_in {
705 struct coda_in_hdr ih;
708 struct coda_statfs_out {
709 struct coda_out_hdr oh;
710 struct coda_statfs stat;
714 * Occasionally, we don't cache the fid returned by CODA_LOOKUP.
715 * For instance, if the fid is inconsistent.
716 * This case is handled by setting the top bit of the type result parameter.
718 #define CODA_NOCACHE 0x80000000
721 struct coda_in_hdr ih; /* NB: every struct below begins with an ih */
722 struct coda_open_in coda_open;
723 struct coda_close_in coda_close;
724 struct coda_ioctl_in coda_ioctl;
725 struct coda_getattr_in coda_getattr;
726 struct coda_setattr_in coda_setattr;
727 struct coda_access_in coda_access;
728 struct coda_lookup_in coda_lookup;
729 struct coda_create_in coda_create;
730 struct coda_remove_in coda_remove;
731 struct coda_link_in coda_link;
732 struct coda_rename_in coda_rename;
733 struct coda_mkdir_in coda_mkdir;
734 struct coda_rmdir_in coda_rmdir;
735 struct coda_readdir_in coda_readdir;
736 struct coda_symlink_in coda_symlink;
737 struct coda_readlink_in coda_readlink;
738 struct coda_fsync_in coda_fsync;
739 struct coda_vget_in coda_vget;
740 struct coda_open_by_fd_in coda_open_by_fd;
741 struct coda_open_by_path_in coda_open_by_path;
742 struct coda_statfs_in coda_statfs;
746 struct coda_out_hdr oh; /* NB: every struct below begins with an oh */
747 struct coda_root_out coda_root;
748 struct coda_open_out coda_open;
749 struct coda_ioctl_out coda_ioctl;
750 struct coda_getattr_out coda_getattr;
751 struct coda_lookup_out coda_lookup;
752 struct coda_create_out coda_create;
753 struct coda_mkdir_out coda_mkdir;
754 struct coda_readdir_out coda_readdir;
755 struct coda_readlink_out coda_readlink;
756 struct coda_vget_out coda_vget;
757 struct coda_purgeuser_out coda_purgeuser;
758 struct coda_zapfile_out coda_zapfile;
759 struct coda_zapdir_out coda_zapdir;
760 struct coda_zapvnode_out coda_zapvnode;
761 struct coda_purgefid_out coda_purgefid;
762 struct coda_replace_out coda_replace;
763 struct coda_open_by_fd_out coda_open_by_fd;
764 struct coda_open_by_path_out coda_open_by_path;
765 struct coda_statfs_out coda_statfs;
768 union coda_downcalls {
769 /* CODA_INVALIDATE is a venus->kernel call */
770 /* CODA_FLUSH is a venus->kernel call */
771 struct coda_purgeuser_out purgeuser;
772 struct coda_zapfile_out zapfile;
773 struct coda_zapdir_out zapdir;
774 struct coda_zapvnode_out zapvnode;
775 struct coda_purgefid_out purgefid;
776 struct coda_replace_out replace;
781 * Used for identifying usage of "Control" and pioctls
784 #define PIOCPARM_MASK 0x0000ffff
786 caddr_t in, out; /* Data to be transferred in, or out */
787 unsigned short in_size; /* Size of input buffer <= 8K */
788 unsigned short out_size; /* Maximum size of output buffer, <= 8K */
791 #if defined(__CYGWIN32__) || defined(DJGPP)
806 #define CODA_CONTROL ".CONTROL"
807 #define CODA_CONTROLLEN 8
812 #define CTL_FILE "/coda/.CONTROL"
815 #define CTL_FID { -1, -1, -1 }
816 #define IS_CTL_FID(fidp) ((fidp)->Volume == -1 &&\
817 (fidp)->Vnode == -1 &&\
818 (fidp)->Unique == -1)
819 #define INVAL_FID { 0, 0, 0 }
821 #define CTL_FID { { -1, -1, -1, -1 } }
822 #define IS_CTL_FID(fidp) ((fidp)->opaque[1] == CTL_VOL && \
823 (fidp)->opaque[2] == CTL_VNO && \
824 (fidp)->opaque[3] == CTL_UNI)
825 #define INVAL_FID { { 0, 0, 0, 0 } }
828 /* Data passed to mount */
830 #define CODA_MOUNT_VERSION 1
832 struct coda_mount_data {
834 int fd; /* Opened device */