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 COMPAT_CODA_5 option */
46 /* Catch new _KERNEL defn for NetBSD */
48 #include <sys/types.h>
51 #ifndef CODA_MAXSYMLINKS
52 #define CODA_MAXSYMLINKS 10
55 #if defined(DJGPP) || defined(__CYGWIN32__)
57 typedef unsigned long u_long;
58 typedef unsigned int u_int;
59 typedef unsigned short u_short;
62 typedef void * caddr_t;
64 typedef unsigned __int64 u_quad_t;
66 typedef unsigned long long u_quad_t;
75 #else /* DJGPP but not _KERNEL */
76 #include <sys/types.h>
78 typedef unsigned long long u_quad_t;
83 #if defined(__linux__)
84 #define cdev_t u_quad_t
85 #if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
87 typedef unsigned long long u_quad_t;
94 typedef unsigned char u_int8_t;
96 time_t tv_sec; /* seconds */
97 long tv_nsec; /* nanoseconds */
105 #define CODA_MAXNAMLEN 255
106 #define CODA_MAXPATHLEN 1024
107 #define CODA_MAXSYMLINK 10
109 /* these are Coda's version of O_RDONLY etc combinations
110 * to deal with VFS open modes
112 #define C_O_READ 0x001
113 #define C_O_WRITE 0x002
114 #define C_O_TRUNC 0x010
115 #define C_O_EXCL 0x100
116 #define C_O_CREAT 0x200
118 /* these are to find mode bits in Venus */
119 #define C_M_READ 00400
120 #define C_M_WRITE 00200
122 /* for access Venus will use */
123 #define C_A_C_OK 8 /* Test for writing upon create. */
124 #define C_A_R_OK 4 /* Test for read permission. */
125 #define C_A_W_OK 2 /* Test for write permission. */
126 #define C_A_X_OK 1 /* Test for execute permission. */
127 #define C_A_F_OK 0 /* Test for existence. */
131 #ifndef _VENUS_DIRENT_T_
132 #define _VENUS_DIRENT_T_ 1
133 struct venus_dirent {
134 unsigned long d_fileno; /* file number of entry */
135 unsigned short d_reclen; /* length of this record */
136 char d_type; /* file type, see below */
137 char d_namlen; /* length of string in d_name */
138 char d_name[CODA_MAXNAMLEN + 1];/* name must be no longer than this */
141 #define DIRSIZ(dp) ((sizeof (struct venus_dirent) - (CODA_MAXNAMLEN+1)) + \
142 (((dp)->d_namlen+1 + 3) &~ 3))
147 #define CDT_UNKNOWN 0
158 * Convert between stat structure types and directory types.
160 #define IFTOCDT(mode) (((mode) & 0170000) >> 12)
161 #define CDTTOIF(dirtype) ((dirtype) << 12)
173 static __inline__ ino_t coda_f2i(CodaFid *fid)
176 return (fid->Unique + (fid->Vnode<<10) + (fid->Volume<<20));
179 static __inline__ char * coda_f2s(CodaFid *fid)
181 static char fid_str [35];
182 snprintf (fid_str, 35, "[%lx.%lx.%lx]", fid->Volume,
183 fid->Vnode, fid->Unique);
187 static __inline__ int coda_fid_eq (CodaFid *fid1, CodaFid *fid2)
189 return (fid1->Volume == fid2->Volume &&
190 fid1->Vnode == fid2->Vnode &&
191 fid1->Unique == fid2->Unique);
195 u_int32_t cr_uid, cr_euid, cr_suid, cr_fsuid; /* Real, efftve, set, fs uid*/
196 u_int32_t cr_groupid, cr_egid, cr_sgid, cr_fsgid; /* same for groups */
199 #else /* CODA_COMPAT_5 */
205 static __inline__ ino_t coda_f2i(CodaFid *fid)
209 return (fid->opaque[3] ^ (fid->opaque[2]<<10) ^ (fid->opaque[1]<<20) ^ fid->opaque[0]);
212 static __inline__ char * coda_f2s(CodaFid *fid)
214 static char fid_str [35];
215 snprintf (fid_str, 35, "[%x.%x.%x.%x]", fid->opaque[0],
216 fid->opaque[1], fid->opaque[2], fid->opaque[3]);
220 static __inline__ int coda_fid_eq (CodaFid *fid1, CodaFid *fid2)
222 return (fid1->opaque[0] == fid2->opaque[0] &&
223 fid1->opaque[1] == fid2->opaque[1] &&
224 fid1->opaque[2] == fid2->opaque[2] &&
225 fid1->opaque[3] == fid2->opaque[3]);
228 #endif /* CODA_COMPAT_5 */
230 #ifndef _VENUS_VATTR_T_
231 #define _VENUS_VATTR_T_
233 * Vnode types. VNON means no type.
235 enum coda_vtype { C_VNON, C_VREG, C_VDIR, C_VBLK, C_VCHR, C_VLNK, C_VSOCK, C_VFIFO, C_VBAD };
238 int va_type; /* vnode type (for create) */
239 u_short va_mode; /* files access mode and type */
240 short va_nlink; /* number of references to file */
241 uid_t va_uid; /* owner user id */
242 gid_t va_gid; /* owner group id */
243 long va_fileid; /* file id */
244 u_quad_t va_size; /* file size in bytes */
245 long va_blocksize; /* blocksize preferred for i/o */
246 struct timespec va_atime; /* time of last access */
247 struct timespec va_mtime; /* time of last modification */
248 struct timespec va_ctime; /* time file changed */
249 u_long va_gen; /* generation number of file */
250 u_long va_flags; /* flags defined for file */
251 cdev_t va_rdev; /* device special file represents */
252 u_quad_t va_bytes; /* bytes of disk space held by file */
253 u_quad_t va_filerev; /* file modification number */
258 /* structure used by CODA_STATFS for getting cache information from venus */
268 * Kernel <--> Venus communications.
272 #define CODA_OPEN_BY_FD 3
276 #define CODA_GETATTR 7
277 #define CODA_SETATTR 8
278 #define CODA_ACCESS 9
279 #define CODA_LOOKUP 10
280 #define CODA_CREATE 11
281 #define CODA_REMOVE 12
283 #define CODA_RENAME 14
284 #define CODA_MKDIR 15
285 #define CODA_RMDIR 16
286 #define CODA_READDIR 17
287 #define CODA_SYMLINK 18
288 #define CODA_READLINK 19
289 #define CODA_FSYNC 20
290 #define CODA_INACTIVE 21
292 #define CODA_SIGNAL 23
293 #define CODA_REPLACE 24
294 #define CODA_FLUSH 25
295 #define CODA_PURGEUSER 26
296 #define CODA_ZAPFILE 27
297 #define CODA_ZAPDIR 28
298 #define CODA_PURGEFID 30
299 #define CODA_OPEN_BY_PATH 31
300 #define CODA_RESOLVE 32
301 #define CODA_REINTEGRATE 33
302 #define CODA_STATFS 34
303 #define CODA_NCALLS 35
305 #define DOWNCALL(opcode) (opcode >= CODA_REPLACE && opcode <= CODA_PURGEFID)
307 #define VC_MAXDATASIZE 8192
308 #define VC_MAXMSGSIZE sizeof(union inputArgs)+sizeof(union outputArgs) +\
311 #define CIOC_KERNEL_VERSION _IOWR('c', 10, sizeof (int))
313 /* don't care about kernel version number */
314 #define CODA_KERNEL_VERSION 0
315 /* The old venus 4.6 compatible interface */
316 #define CODA_KERNEL_VERSION 1
317 #endif /* realms/cells */
319 /* venus_lookup gets an extra parameter to aid windows.*/
320 #define CODA_KERNEL_VERSION 2
322 /* 128-bit fids for realms */
323 #define CODA_KERNEL_VERSION 3
327 * Venus <-> Coda RPC arguments
331 unsigned long opcode;
332 unsigned long unique; /* Keep multiple outstanding msgs distinct */
333 u_short pid; /* Common to all */
334 u_short pgid; /* Common to all */
335 u_short sid; /* Common to all */
336 struct coda_cred cred; /* Common to all */
341 u_int32_t unique; /* Keep multiple outstanding msgs distinct */
342 pid_t pid; /* Common to all */
343 pid_t pgid; /* Common to all */
344 uid_t uid; /* Common to all */
348 /* Really important that opcode and unique are 1st two fields! */
349 struct coda_out_hdr {
350 unsigned long opcode;
351 unsigned long unique;
352 unsigned long result;
355 /* coda_root: NO_IN */
356 struct coda_root_out {
357 struct coda_out_hdr oh;
361 struct coda_root_in {
362 struct coda_in_hdr in;
366 /* Nothing needed for coda_sync */
369 struct coda_open_in {
370 struct coda_in_hdr ih;
375 struct coda_open_out {
376 struct coda_out_hdr oh;
383 struct coda_close_in {
384 struct coda_in_hdr ih;
389 struct coda_close_out {
390 struct coda_out_hdr out;
394 struct coda_ioctl_in {
395 struct coda_in_hdr ih;
400 char *data; /* Place holder for data. */
403 struct coda_ioctl_out {
404 struct coda_out_hdr oh;
406 caddr_t data; /* Place holder for data. */
411 struct coda_getattr_in {
412 struct coda_in_hdr ih;
416 struct coda_getattr_out {
417 struct coda_out_hdr oh;
418 struct coda_vattr attr;
422 /* coda_setattr: NO_OUT */
423 struct coda_setattr_in {
424 struct coda_in_hdr ih;
426 struct coda_vattr attr;
429 struct coda_setattr_out {
430 struct coda_out_hdr out;
433 /* coda_access: NO_OUT */
434 struct coda_access_in {
435 struct coda_in_hdr ih;
440 struct coda_access_out {
441 struct coda_out_hdr out;
446 #define CLU_CASE_SENSITIVE 0x01
447 #define CLU_CASE_INSENSITIVE 0x02
450 struct coda_lookup_in {
451 struct coda_in_hdr ih;
453 int name; /* Place holder for data. */
457 struct coda_lookup_out {
458 struct coda_out_hdr oh;
465 struct coda_create_in {
466 struct coda_in_hdr ih;
468 struct coda_vattr attr;
471 int name; /* Place holder for data. */
474 struct coda_create_out {
475 struct coda_out_hdr oh;
477 struct coda_vattr attr;
481 /* coda_remove: NO_OUT */
482 struct coda_remove_in {
483 struct coda_in_hdr ih;
485 int name; /* Place holder for data. */
488 struct coda_remove_out {
489 struct coda_out_hdr out;
492 /* coda_link: NO_OUT */
493 struct coda_link_in {
494 struct coda_in_hdr ih;
495 CodaFid sourceFid; /* cnode to link *to* */
496 CodaFid destFid; /* Directory in which to place link */
497 int tname; /* Place holder for data. */
500 struct coda_link_out {
501 struct coda_out_hdr out;
505 /* coda_rename: NO_OUT */
506 struct coda_rename_in {
507 struct coda_in_hdr ih;
514 struct coda_rename_out {
515 struct coda_out_hdr out;
519 struct coda_mkdir_in {
520 struct coda_in_hdr ih;
522 struct coda_vattr attr;
523 int name; /* Place holder for data. */
526 struct coda_mkdir_out {
527 struct coda_out_hdr oh;
529 struct coda_vattr attr;
533 /* coda_rmdir: NO_OUT */
534 struct coda_rmdir_in {
535 struct coda_in_hdr ih;
537 int name; /* Place holder for data. */
540 struct coda_rmdir_out {
541 struct coda_out_hdr out;
545 struct coda_readdir_in {
546 struct coda_in_hdr ih;
552 struct coda_readdir_out {
553 struct coda_out_hdr oh;
555 caddr_t data; /* Place holder for data. */
558 /* coda_symlink: NO_OUT */
559 struct coda_symlink_in {
560 struct coda_in_hdr ih;
561 CodaFid Fid; /* Directory to put symlink in */
563 struct coda_vattr attr;
567 struct coda_symlink_out {
568 struct coda_out_hdr out;
572 struct coda_readlink_in {
573 struct coda_in_hdr ih;
577 struct coda_readlink_out {
578 struct coda_out_hdr oh;
580 caddr_t data; /* Place holder for data. */
584 /* coda_fsync: NO_OUT */
585 struct coda_fsync_in {
586 struct coda_in_hdr ih;
590 struct coda_fsync_out {
591 struct coda_out_hdr out;
594 /* coda_inactive: NO_OUT */
595 struct coda_inactive_in {
596 struct coda_in_hdr ih;
601 struct coda_vget_in {
602 struct coda_in_hdr ih;
606 struct coda_vget_out {
607 struct coda_out_hdr oh;
613 /* CODA_SIGNAL is out-of-band, doesn't need data. */
614 /* CODA_INVALIDATE is a venus->kernel call */
615 /* CODA_FLUSH is a venus->kernel call */
617 /* coda_purgeuser: */
618 /* CODA_PURGEUSER is a venus->kernel call */
619 struct coda_purgeuser_out {
620 struct coda_out_hdr oh;
622 struct coda_cred cred;
629 /* CODA_ZAPFILE is a venus->kernel call */
630 struct coda_zapfile_out {
631 struct coda_out_hdr oh;
636 /* CODA_ZAPDIR is a venus->kernel call */
637 struct coda_zapdir_out {
638 struct coda_out_hdr oh;
643 /* CODA_ZAPVNODE is a venus->kernel call */
644 struct coda_zapvnode_out {
645 struct coda_out_hdr oh;
647 struct coda_cred cred;
653 /* CODA_PURGEFID is a venus->kernel call */
654 struct coda_purgefid_out {
655 struct coda_out_hdr oh;
660 /* CODA_REPLACE is a venus->kernel call */
661 struct coda_replace_out { /* coda_replace is a venus->kernel call */
662 struct coda_out_hdr oh;
667 /* coda_open_by_fd: */
668 struct coda_open_by_fd_in {
669 struct coda_in_hdr ih;
674 struct coda_open_by_fd_out {
675 struct coda_out_hdr oh;
680 /* coda_open_by_path: */
681 struct coda_open_by_path_in {
682 struct coda_in_hdr ih;
687 struct coda_open_by_path_out {
688 struct coda_out_hdr oh;
692 /* coda_statfs: NO_IN */
693 struct coda_statfs_in {
694 struct coda_in_hdr ih;
697 struct coda_statfs_out {
698 struct coda_out_hdr oh;
699 struct coda_statfs stat;
703 * Occasionally, we don't cache the fid returned by CODA_LOOKUP.
704 * For instance, if the fid is inconsistent.
705 * This case is handled by setting the top bit of the type result parameter.
707 #define CODA_NOCACHE 0x80000000
710 struct coda_in_hdr ih; /* NB: every struct below begins with an ih */
711 struct coda_open_in coda_open;
712 struct coda_close_in coda_close;
713 struct coda_ioctl_in coda_ioctl;
714 struct coda_getattr_in coda_getattr;
715 struct coda_setattr_in coda_setattr;
716 struct coda_access_in coda_access;
717 struct coda_lookup_in coda_lookup;
718 struct coda_create_in coda_create;
719 struct coda_remove_in coda_remove;
720 struct coda_link_in coda_link;
721 struct coda_rename_in coda_rename;
722 struct coda_mkdir_in coda_mkdir;
723 struct coda_rmdir_in coda_rmdir;
724 struct coda_readdir_in coda_readdir;
725 struct coda_symlink_in coda_symlink;
726 struct coda_readlink_in coda_readlink;
727 struct coda_fsync_in coda_fsync;
728 struct coda_vget_in coda_vget;
729 struct coda_open_by_fd_in coda_open_by_fd;
730 struct coda_open_by_path_in coda_open_by_path;
731 struct coda_statfs_in coda_statfs;
735 struct coda_out_hdr oh; /* NB: every struct below begins with an oh */
736 struct coda_root_out coda_root;
737 struct coda_open_out coda_open;
738 struct coda_ioctl_out coda_ioctl;
739 struct coda_getattr_out coda_getattr;
740 struct coda_lookup_out coda_lookup;
741 struct coda_create_out coda_create;
742 struct coda_mkdir_out coda_mkdir;
743 struct coda_readdir_out coda_readdir;
744 struct coda_readlink_out coda_readlink;
745 struct coda_vget_out coda_vget;
746 struct coda_purgeuser_out coda_purgeuser;
747 struct coda_zapfile_out coda_zapfile;
748 struct coda_zapdir_out coda_zapdir;
749 struct coda_zapvnode_out coda_zapvnode;
750 struct coda_purgefid_out coda_purgefid;
751 struct coda_replace_out coda_replace;
752 struct coda_open_by_fd_out coda_open_by_fd;
753 struct coda_open_by_path_out coda_open_by_path;
754 struct coda_statfs_out coda_statfs;
757 union coda_downcalls {
758 /* CODA_INVALIDATE is a venus->kernel call */
759 /* CODA_FLUSH is a venus->kernel call */
760 struct coda_purgeuser_out purgeuser;
761 struct coda_zapfile_out zapfile;
762 struct coda_zapdir_out zapdir;
763 struct coda_zapvnode_out zapvnode;
764 struct coda_purgefid_out purgefid;
765 struct coda_replace_out replace;
770 * Used for identifying usage of "Control" and pioctls
773 #define PIOCPARM_MASK 0x0000ffff
775 caddr_t in, out; /* Data to be transferred in, or out */
776 short in_size; /* Size of input buffer <= 2K */
777 short out_size; /* Maximum size of output buffer, <= 2K */
780 #if defined(__CYGWIN32__) || defined(DJGPP)
795 #define CODA_CONTROL ".CONTROL"
796 #define CODA_CONTROLLEN 8
798 #define CTL_FILE "/coda/.CONTROL"
801 #define CTL_FID { -1, -1, -1 }
802 #define IS_CTL_FID(fidp) ((fidp)->Volume == -1 &&\
803 (fidp)->Vnode == -1 &&\
804 (fidp)->Unique == -1)
805 #define INVAL_FID { 0, 0, 0 }
807 #define CTL_FID { { -1, -1, -1, -1 } }
808 #define IS_CTL_FID(fidp) ((fidp)->opaque[0] == -1 &&\
809 (fidp)->opaque[1] == -1 &&\
810 (fidp)->opaque[2] == -1 &&\
811 (fidp)->opaque[3] == -1)
812 #define INVAL_FID { { 0, 0, 0, 0 } }
815 /* Data passed to mount */
817 #define CODA_MOUNT_VERSION 1
819 struct coda_mount_data {
821 int fd; /* Opened device */