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