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