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