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