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
44 #include "opt_coda.h" /* for CODA_COMPAT_5 option */
46 /* Avoid CODA_COMPAT_5 redefinition in coda5 module */
47 #if defined (CODA5_MODULE) && !defined(CODA_COMPAT_5)
51 /* Catch new _KERNEL defn for NetBSD */
53 #include <sys/types.h>
56 #ifndef CODA_MAXSYMLINKS
57 #define CODA_MAXSYMLINKS 10
60 #if defined(DJGPP) || defined(__CYGWIN32__)
62 typedef unsigned long u_long;
63 typedef unsigned int u_int;
64 typedef unsigned short u_short;
66 typedef u_long struct cdev *;
67 typedef void * caddr_t;
69 typedef unsigned __int64 u_quad_t;
71 typedef unsigned long long u_quad_t;
80 #else /* DJGPP but not _KERNEL */
81 #include <sys/types.h>
83 typedef unsigned long long u_quad_t;
88 #if defined(__linux__)
89 #define cdev_t u_quad_t
90 #if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
92 typedef unsigned long long u_quad_t;
99 typedef unsigned char u_int8_t;
101 time_t tv_sec; /* seconds */
102 long tv_nsec; /* nanoseconds */
106 typedef u_int32_t cuid_t;
107 typedef u_int32_t cgid_t;
112 #define CODA_MAXNAMLEN 255
113 #define CODA_MAXPATHLEN 1024
114 #define CODA_MAXSYMLINK 10
116 /* these are Coda's version of O_RDONLY etc combinations
117 * to deal with VFS open modes
119 #define C_O_READ 0x001
120 #define C_O_WRITE 0x002
121 #define C_O_TRUNC 0x010
122 #define C_O_EXCL 0x100
123 #define C_O_CREAT 0x200
125 /* these are to find mode bits in Venus */
126 #define C_M_READ 00400
127 #define C_M_WRITE 00200
129 /* for access Venus will use */
130 #define C_A_C_OK 8 /* Test for writing upon create. */
131 #define C_A_R_OK 4 /* Test for read permission. */
132 #define C_A_W_OK 2 /* Test for write permission. */
133 #define C_A_X_OK 1 /* Test for execute permission. */
134 #define C_A_F_OK 0 /* Test for existence. */
137 #ifndef _VENUS_DIRENT_T_
138 #define _VENUS_DIRENT_T_ 1
139 struct venus_dirent {
140 unsigned int d_fileno; /* file number of entry */
141 unsigned short d_reclen; /* length of this record */
142 unsigned char d_type; /* file type, see below */
143 unsigned char d_namlen; /* length of string in d_name */
144 char d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
147 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
148 (((dp)->d_namlen+1 + 3) &~ 3))
153 #define CDT_UNKNOWN 0
164 * Convert between stat structure types and directory types.
166 #define IFTOCDT(mode) (((mode) & 0170000) >> 12)
167 #define CDTTOIF(dirtype) ((dirtype) << 12)
179 static __inline__ ino_t coda_f2i(struct CodaFid *fid)
182 return (fid->Unique + (fid->Vnode<<10) + (fid->Volume<<20));
185 static __inline__ char * coda_f2s(struct CodaFid *fid)
187 static char fid_str [35];
188 snprintf (fid_str, 35, "[%lx.%lx.%lx]", fid->Volume,
189 fid->Vnode, fid->Unique);
193 static __inline__ int coda_fid_eq (struct CodaFid *fid1, struct CodaFid *fid2)
195 return (fid1->Volume == fid2->Volume &&
196 fid1->Vnode == fid2->Vnode &&
197 fid1->Unique == fid2->Unique);
201 u_int32_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
202 u_int32_t cr_groupid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
205 #else /* CODA_COMPAT_5 */
211 static __inline__ ino_t coda_f2i(struct CodaFid *fid)
215 return (fid->opaque[3] ^ (fid->opaque[2]<<10) ^ (fid->opaque[1]<<20) ^ fid->opaque[0]);
218 static __inline__ char * coda_f2s(struct CodaFid *fid)
220 static char fid_str [35];
221 snprintf (fid_str, 35, "[%x.%x.%x.%x]", fid->opaque[0],
222 fid->opaque[1], fid->opaque[2], fid->opaque[3]);
226 static __inline__ int coda_fid_eq (struct CodaFid *fid1, struct CodaFid *fid2)
228 return (fid1->opaque[0] == fid2->opaque[0] &&
229 fid1->opaque[1] == fid2->opaque[1] &&
230 fid1->opaque[2] == fid2->opaque[2] &&
231 fid1->opaque[3] == fid2->opaque[3]);
234 #endif /* CODA_COMPAT_5 */
236 #ifndef _VENUS_VATTR_T_
237 #define _VENUS_VATTR_T_
239 * Vnode types. VNON means no type.
241 enum coda_vtype { C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };
244 long va_type; /* vnode type (for create) */
245 u_short va_mode; /* files access mode and type */
246 short va_nlink; /* number of references to file */
247 cuid_t va_uid; /* owner user id */
248 cgid_t va_gid; /* owner group id */
249 long va_fileid; /* file id */
250 u_quad_t va_size; /* file size in bytes */
251 long va_blocksize; /* blocksize preferred for i/o */
252 struct timespec va_atime; /* time of last access */
253 struct timespec va_mtime; /* time of last modification */
254 struct timespec va_ctime; /* time file changed */
255 u_long va_gen; /* generation number of file */
256 u_long va_flags; /* flags defined for file */
257 cdev_t va_rdev; /* device special file represents */
258 u_quad_t va_bytes; /* bytes of disk space held by file */
259 u_quad_t va_filerev; /* file modification number */
264 /* structure used by CODA_STATFS for getting cache information from venus */
274 * Kernel <--> Venus communications.
278 #define CODA_OPEN_BY_FD 3
282 #define CODA_GETATTR 7
283 #define CODA_SETATTR 8
284 #define CODA_ACCESS 9
285 #define CODA_LOOKUP 10
286 #define CODA_CREATE 11
287 #define CODA_REMOVE 12
289 #define CODA_RENAME 14
290 #define CODA_MKDIR 15
291 #define CODA_RMDIR 16
292 #define CODA_READDIR 17
293 #define CODA_SYMLINK 18
294 #define CODA_READLINK 19
295 #define CODA_FSYNC 20
296 #define CODA_INACTIVE 21
298 #define CODA_SIGNAL 23
299 #define CODA_REPLACE 24
300 #define CODA_FLUSH 25
301 #define CODA_PURGEUSER 26
302 #define CODA_ZAPFILE 27
303 #define CODA_ZAPDIR 28
304 #define CODA_PURGEFID 30
305 #define CODA_OPEN_BY_PATH 31
306 #define CODA_RESOLVE 32
307 #define CODA_REINTEGRATE 33
308 #define CODA_STATFS 34
309 #define CODA_NCALLS 35
311 #define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
313 #define VC_MAXDATASIZE 8192
314 #define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
317 #define CIOC_KERNEL_VERSION _IOWR('c', 10, int)
319 /* don't care about kernel version number */
320 #define CODA_KERNEL_VERSION 0
321 /* The old venus 4.6 compatible interface */
322 #define CODA_KERNEL_VERSION 1
323 #endif /* realms/cells */
325 /* venus_lookup gets an extra parameter to aid windows.*/
326 #define CODA_KERNEL_VERSION 2
328 /* 128-bit fids for realms */
329 #define CODA_KERNEL_VERSION 3
333 * Venus <-> Coda RPC arguments
337 unsigned long opcode;
338 unsigned long unique; /* Keep multiple outstanding msgs distinct */
339 u_short pid; /* Common to all */
340 u_short pgid; /* Common to all */
341 u_short sid; /* Common to all */
342 struct coda_cred cred; /* Common to all */
347 u_int32_t unique; /* Keep multiple outstanding msgs distinct */
354 /* Really important that opcode and unique are 1st two fields! */
355 struct coda_out_hdr {
361 /* coda_root: NO_IN */
362 struct coda_root_out {
363 struct coda_out_hdr oh;
367 struct coda_root_in {
368 struct coda_in_hdr in;
372 /* Nothing needed for coda_sync */
375 struct coda_open_in {
376 struct coda_in_hdr ih;
381 struct coda_open_out {
382 struct coda_out_hdr oh;
389 struct coda_close_in {
390 struct coda_in_hdr ih;
395 struct coda_close_out {
396 struct coda_out_hdr out;
400 struct coda_ioctl_in {
401 struct coda_in_hdr ih;
406 char *data; /* Place holder for data. */
409 struct coda_ioctl_out {
410 struct coda_out_hdr oh;
412 caddr_t data; /* Place holder for data. */
417 struct coda_getattr_in {
418 struct coda_in_hdr ih;
422 struct coda_getattr_out {
423 struct coda_out_hdr oh;
424 struct coda_vattr attr;
428 /* coda_setattr: NO_OUT */
429 struct coda_setattr_in {
430 struct coda_in_hdr ih;
432 struct coda_vattr attr;
435 struct coda_setattr_out {
436 struct coda_out_hdr out;
439 /* coda_access: NO_OUT */
440 struct coda_access_in {
441 struct coda_in_hdr ih;
446 struct coda_access_out {
447 struct coda_out_hdr out;
452 #define CLU_CASE_SENSITIVE 0x01
453 #define CLU_CASE_INSENSITIVE 0x02
456 struct coda_lookup_in {
457 struct coda_in_hdr ih;
459 int name; /* Place holder for data. */
463 struct coda_lookup_out {
464 struct coda_out_hdr oh;
471 struct coda_create_in {
472 struct coda_in_hdr ih;
474 struct coda_vattr attr;
477 int name; /* Place holder for data. */
480 struct coda_create_out {
481 struct coda_out_hdr oh;
483 struct coda_vattr attr;
487 /* coda_remove: NO_OUT */
488 struct coda_remove_in {
489 struct coda_in_hdr ih;
491 int name; /* Place holder for data. */
494 struct coda_remove_out {
495 struct coda_out_hdr out;
498 /* coda_link: NO_OUT */
499 struct coda_link_in {
500 struct coda_in_hdr ih;
501 struct CodaFid sourceFid; /* cnode to link *to* */
502 struct CodaFid destFid; /* Directory in which to place link */
503 int tname; /* Place holder for data. */
506 struct coda_link_out {
507 struct coda_out_hdr out;
511 /* coda_rename: NO_OUT */
512 struct coda_rename_in {
513 struct coda_in_hdr ih;
514 struct CodaFid sourceFid;
516 struct CodaFid destFid;
520 struct coda_rename_out {
521 struct coda_out_hdr out;
525 struct coda_mkdir_in {
526 struct coda_in_hdr ih;
528 struct coda_vattr attr;
529 int name; /* Place holder for data. */
532 struct coda_mkdir_out {
533 struct coda_out_hdr oh;
535 struct coda_vattr attr;
539 /* coda_rmdir: NO_OUT */
540 struct coda_rmdir_in {
541 struct coda_in_hdr ih;
543 int name; /* Place holder for data. */
546 struct coda_rmdir_out {
547 struct coda_out_hdr out;
551 struct coda_readdir_in {
552 struct coda_in_hdr ih;
558 struct coda_readdir_out {
559 struct coda_out_hdr oh;
561 caddr_t data; /* Place holder for data. */
564 /* coda_symlink: NO_OUT */
565 struct coda_symlink_in {
566 struct coda_in_hdr ih;
567 struct CodaFid Fid; /* Directory to put symlink in */
569 struct coda_vattr attr;
573 struct coda_symlink_out {
574 struct coda_out_hdr out;
578 struct coda_readlink_in {
579 struct coda_in_hdr ih;
583 struct coda_readlink_out {
584 struct coda_out_hdr oh;
586 caddr_t data; /* Place holder for data. */
590 /* coda_fsync: NO_OUT */
591 struct coda_fsync_in {
592 struct coda_in_hdr ih;
596 struct coda_fsync_out {
597 struct coda_out_hdr out;
600 /* coda_inactive: NO_OUT */
601 struct coda_inactive_in {
602 struct coda_in_hdr ih;
607 struct coda_vget_in {
608 struct coda_in_hdr ih;
612 struct coda_vget_out {
613 struct coda_out_hdr oh;
619 /* CODA_SIGNAL is out-of-band, doesn't need data. */
620 /* CODA_INVALIDATE is a venus->kernel call */
621 /* CODA_FLUSH is a venus->kernel call */
623 /* coda_purgeuser: */
624 /* CODA_PURGEUSER is a venus->kernel call */
625 struct coda_purgeuser_out {
626 struct coda_out_hdr oh;
628 struct coda_cred cred;
635 /* CODA_ZAPFILE is a venus->kernel call */
636 struct coda_zapfile_out {
637 struct coda_out_hdr oh;
642 /* CODA_ZAPDIR is a venus->kernel call */
643 struct coda_zapdir_out {
644 struct coda_out_hdr oh;
649 /* CODA_ZAPVNODE is a venus->kernel call */
650 struct coda_zapvnode_out {
651 struct coda_out_hdr oh;
653 struct coda_cred cred;
659 /* CODA_PURGEFID is a venus->kernel call */
660 struct coda_purgefid_out {
661 struct coda_out_hdr oh;
666 /* CODA_REPLACE is a venus->kernel call */
667 struct coda_replace_out { /* coda_replace is a venus->kernel call */
668 struct coda_out_hdr oh;
669 struct CodaFid NewFid;
670 struct CodaFid OldFid;
673 /* coda_open_by_fd: */
674 struct coda_open_by_fd_in {
675 struct coda_in_hdr ih;
680 struct coda_open_by_fd_out {
681 struct coda_out_hdr oh;
684 /* not passed from userspace but used in-kernel only */
689 /* coda_open_by_path: */
690 struct coda_open_by_path_in {
691 struct coda_in_hdr ih;
696 struct coda_open_by_path_out {
697 struct coda_out_hdr oh;
701 /* coda_statfs: NO_IN */
702 struct coda_statfs_in {
703 struct coda_in_hdr ih;
706 struct coda_statfs_out {
707 struct coda_out_hdr oh;
708 struct coda_statfs stat;
712 * Occasionally, we don't cache the fid returned by CODA_LOOKUP.
713 * For instance, if the fid is inconsistent.
714 * This case is handled by setting the top bit of the type result parameter.
716 #define CODA_NOCACHE 0x80000000
719 struct coda_in_hdr ih; /* NB: every struct below begins with an ih */
720 struct coda_open_in coda_open;
721 struct coda_close_in coda_close;
722 struct coda_ioctl_in coda_ioctl;
723 struct coda_getattr_in coda_getattr;
724 struct coda_setattr_in coda_setattr;
725 struct coda_access_in coda_access;
726 struct coda_lookup_in coda_lookup;
727 struct coda_create_in coda_create;
728 struct coda_remove_in coda_remove;
729 struct coda_link_in coda_link;
730 struct coda_rename_in coda_rename;
731 struct coda_mkdir_in coda_mkdir;
732 struct coda_rmdir_in coda_rmdir;
733 struct coda_readdir_in coda_readdir;
734 struct coda_symlink_in coda_symlink;
735 struct coda_readlink_in coda_readlink;
736 struct coda_fsync_in coda_fsync;
737 struct coda_vget_in coda_vget;
738 struct coda_open_by_fd_in coda_open_by_fd;
739 struct coda_open_by_path_in coda_open_by_path;
740 struct coda_statfs_in coda_statfs;
744 struct coda_out_hdr oh; /* NB: every struct below begins with an oh */
745 struct coda_root_out coda_root;
746 struct coda_open_out coda_open;
747 struct coda_ioctl_out coda_ioctl;
748 struct coda_getattr_out coda_getattr;
749 struct coda_lookup_out coda_lookup;
750 struct coda_create_out coda_create;
751 struct coda_mkdir_out coda_mkdir;
752 struct coda_readdir_out coda_readdir;
753 struct coda_readlink_out coda_readlink;
754 struct coda_vget_out coda_vget;
755 struct coda_purgeuser_out coda_purgeuser;
756 struct coda_zapfile_out coda_zapfile;
757 struct coda_zapdir_out coda_zapdir;
758 struct coda_zapvnode_out coda_zapvnode;
759 struct coda_purgefid_out coda_purgefid;
760 struct coda_replace_out coda_replace;
761 struct coda_open_by_fd_out coda_open_by_fd;
762 struct coda_open_by_path_out coda_open_by_path;
763 struct coda_statfs_out coda_statfs;
766 union coda_downcalls {
767 /* CODA_INVALIDATE is a venus->kernel call */
768 /* CODA_FLUSH is a venus->kernel call */
769 struct coda_purgeuser_out purgeuser;
770 struct coda_zapfile_out zapfile;
771 struct coda_zapdir_out zapdir;
772 struct coda_zapvnode_out zapvnode;
773 struct coda_purgefid_out purgefid;
774 struct coda_replace_out replace;
779 * Used for identifying usage of "Control" and pioctls
782 #define PIOCPARM_MASK 0x0000ffff
784 caddr_t in, out; /* Data to be transferred in, or out */
785 short in_size; /* Size of input buffer <= 2K */
786 short out_size; /* Maximum size of output buffer, <= 2K */
789 #if defined(__CYGWIN32__) || defined(DJGPP)
804 #define CODA_CONTROL ".CONTROL"
805 #define CODA_CONTROLLEN 8
810 #define CTL_FILE "/coda/.CONTROL"
813 #define CTL_FID { -1, -1, -1 }
814 #define IS_CTL_FID(fidp) ((fidp)->Volume == -1 &&\
815 (fidp)->Vnode == -1 &&\
816 (fidp)->Unique == -1)
817 #define INVAL_FID { 0, 0, 0 }
819 #define CTL_FID { { -1, -1, -1, -1 } }
820 #define IS_CTL_FID(fidp) ((fidp)->opaque[1] == CTL_VOL && \
821 (fidp)->opaque[2] == CTL_VNO && \
822 (fidp)->opaque[3] == CTL_UNI)
823 #define INVAL_FID { { 0, 0, 0, 0 } }
826 /* Data passed to mount */
828 #define CODA_MOUNT_VERSION 1
830 struct coda_mount_data {
832 int fd; /* Opened device */