1*29295d1cSmillert /* $OpenBSD: nfsv2.h,v 1.7 2003/06/02 23:36:54 millert Exp $ */ 2cf4e9b47Sho 3137356d6Setheisen /* 4dc709136Sbitblt * Copyright (c) 1994, 1995, 1996 5137356d6Setheisen * The Regents of the University of California. All rights reserved. 6137356d6Setheisen * 7137356d6Setheisen * This code is derived from software contributed to Berkeley by 8137356d6Setheisen * Rick Macklem at The University of Guelph. 9137356d6Setheisen * 10137356d6Setheisen * Redistribution and use in source and binary forms, with or without 11137356d6Setheisen * modification, are permitted provided that the following conditions 12137356d6Setheisen * are met: 13137356d6Setheisen * 1. Redistributions of source code must retain the above copyright 14137356d6Setheisen * notice, this list of conditions and the following disclaimer. 15137356d6Setheisen * 2. Redistributions in binary form must reproduce the above copyright 16137356d6Setheisen * notice, this list of conditions and the following disclaimer in the 17137356d6Setheisen * documentation and/or other materials provided with the distribution. 18*29295d1cSmillert * 3. Neither the name of the University nor the names of its contributors 19137356d6Setheisen * may be used to endorse or promote products derived from this software 20137356d6Setheisen * without specific prior written permission. 21137356d6Setheisen * 22137356d6Setheisen * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23137356d6Setheisen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24137356d6Setheisen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25137356d6Setheisen * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26137356d6Setheisen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27137356d6Setheisen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28137356d6Setheisen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29137356d6Setheisen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30137356d6Setheisen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31137356d6Setheisen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32137356d6Setheisen * SUCH DAMAGE. 33137356d6Setheisen * 34137356d6Setheisen * @(#)nfsv2.h 7.11 (Berkeley) 9/30/92 35137356d6Setheisen */ 36137356d6Setheisen 37137356d6Setheisen /* 38137356d6Setheisen * nfs definitions as per the version 2 specs 39137356d6Setheisen */ 40137356d6Setheisen 41137356d6Setheisen /* 42137356d6Setheisen * Constants as defined in the Sun NFS Version 2 spec. 43137356d6Setheisen * "NFS: Network File System Protocol Specification" RFC1094 44137356d6Setheisen */ 45137356d6Setheisen 46137356d6Setheisen #define NFS_PORT 2049 47137356d6Setheisen #define NFS_PROG 100003 48137356d6Setheisen #define NFS_VER2 2 49137356d6Setheisen #define NFS_MAXDGRAMDATA 8192 50137356d6Setheisen #define NFS_MAXDATA 32768 51137356d6Setheisen #define NFS_MAXPATHLEN 1024 52137356d6Setheisen #define NFS_MAXNAMLEN 255 53137356d6Setheisen #define NFS_FHSIZE 32 54137356d6Setheisen #define NFS_MAXPKTHDR 404 55137356d6Setheisen #define NFS_MAXPACKET (NFS_MAXPKTHDR+NFS_MAXDATA) 56137356d6Setheisen #define NFS_MINPACKET 20 57137356d6Setheisen #define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ 58137356d6Setheisen 59137356d6Setheisen /* Stat numbers for rpc returns */ 60137356d6Setheisen #define NFS_OK 0 61137356d6Setheisen #define NFSERR_PERM 1 62137356d6Setheisen #define NFSERR_NOENT 2 63137356d6Setheisen #define NFSERR_IO 5 64137356d6Setheisen #define NFSERR_NXIO 6 65137356d6Setheisen #define NFSERR_ACCES 13 66137356d6Setheisen #define NFSERR_EXIST 17 67137356d6Setheisen #define NFSERR_NODEV 19 68137356d6Setheisen #define NFSERR_NOTDIR 20 69137356d6Setheisen #define NFSERR_ISDIR 21 70137356d6Setheisen #define NFSERR_FBIG 27 71137356d6Setheisen #define NFSERR_NOSPC 28 72137356d6Setheisen #define NFSERR_ROFS 30 73137356d6Setheisen #define NFSERR_NAMETOL 63 74137356d6Setheisen #define NFSERR_NOTEMPTY 66 75137356d6Setheisen #define NFSERR_DQUOT 69 76137356d6Setheisen #define NFSERR_STALE 70 77137356d6Setheisen #define NFSERR_WFLUSH 99 78137356d6Setheisen 79137356d6Setheisen /* Sizes in bytes of various nfs rpc components */ 80137356d6Setheisen #define NFSX_FH 32 81137356d6Setheisen #define NFSX_UNSIGNED 4 82137356d6Setheisen #define NFSX_NFSFATTR 68 83137356d6Setheisen #define NFSX_NQFATTR 92 84137356d6Setheisen #define NFSX_NFSSATTR 32 85137356d6Setheisen #define NFSX_NQSATTR 44 86137356d6Setheisen #define NFSX_COOKIE 4 87137356d6Setheisen #define NFSX_NFSSTATFS 20 88137356d6Setheisen #define NFSX_NQSTATFS 28 89137356d6Setheisen #define NFSX_FATTR(isnq) ((isnq) ? NFSX_NQFATTR : NFSX_NFSFATTR) 90137356d6Setheisen #define NFSX_SATTR(isnq) ((isnq) ? NFSX_NQSATTR : NFSX_NFSSATTR) 91137356d6Setheisen #define NFSX_STATFS(isnq) ((isnq) ? NFSX_NQSTATFS : NFSX_NFSSTATFS) 92137356d6Setheisen 93137356d6Setheisen /* nfs rpc procedure numbers */ 94137356d6Setheisen #define NFSPROC_NULL 0 95137356d6Setheisen #define NFSPROC_GETATTR 1 96137356d6Setheisen #define NFSPROC_SETATTR 2 97137356d6Setheisen #define NFSPROC_NOOP 3 98137356d6Setheisen #define NFSPROC_ROOT NFSPROC_NOOP /* Obsolete */ 99137356d6Setheisen #define NFSPROC_LOOKUP 4 100137356d6Setheisen #define NFSPROC_READLINK 5 101137356d6Setheisen #define NFSPROC_READ 6 102137356d6Setheisen #define NFSPROC_WRITECACHE NFSPROC_NOOP /* Obsolete */ 103137356d6Setheisen #define NFSPROC_WRITE 8 104137356d6Setheisen #define NFSPROC_CREATE 9 105137356d6Setheisen #define NFSPROC_REMOVE 10 106137356d6Setheisen #define NFSPROC_RENAME 11 107137356d6Setheisen #define NFSPROC_LINK 12 108137356d6Setheisen #define NFSPROC_SYMLINK 13 109137356d6Setheisen #define NFSPROC_MKDIR 14 110137356d6Setheisen #define NFSPROC_RMDIR 15 111137356d6Setheisen #define NFSPROC_READDIR 16 112137356d6Setheisen #define NFSPROC_STATFS 17 113137356d6Setheisen 114137356d6Setheisen /* NQ nfs numbers */ 115137356d6Setheisen #define NQNFSPROC_READDIRLOOK 18 116137356d6Setheisen #define NQNFSPROC_GETLEASE 19 117137356d6Setheisen #define NQNFSPROC_VACATED 20 118137356d6Setheisen #define NQNFSPROC_EVICTED 21 119137356d6Setheisen #define NQNFSPROC_ACCESS 22 120137356d6Setheisen 121137356d6Setheisen #define NFS_NPROCS 23 122137356d6Setheisen /* Conversion macros */ 123137356d6Setheisen extern int vttoif_tab[]; 124137356d6Setheisen #define vtonfs_mode(t,m) \ 125137356d6Setheisen txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ 126137356d6Setheisen MAKEIMODE((t), (m))) 127137356d6Setheisen #define nfstov_mode(a) (fxdr_unsigned(u_short, (a))&07777) 128137356d6Setheisen #define vtonfs_type(a) txdr_unsigned(nfs_type[((int32_t)(a))]) 129137356d6Setheisen #define nfstov_type(a) ntov_type[fxdr_unsigned(u_int32_t,(a))&0x7] 130137356d6Setheisen 131137356d6Setheisen /* File types */ 132dc709136Sbitblt typedef enum { 133dc709136Sbitblt NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 134dc709136Sbitblt } tcpdump_nfstype; 135137356d6Setheisen 136137356d6Setheisen /* Structs for common parts of the rpc's */ 137137356d6Setheisen struct nfsv2_time { 138137356d6Setheisen u_int32_t nfs_sec; 139137356d6Setheisen u_int32_t nfs_usec; 140137356d6Setheisen }; 141137356d6Setheisen 142137356d6Setheisen struct nqnfs_time { 143137356d6Setheisen u_int32_t nq_sec; 144137356d6Setheisen u_int32_t nq_nsec; 145137356d6Setheisen }; 146137356d6Setheisen 147137356d6Setheisen /* 148137356d6Setheisen * File attributes and setable attributes. These structures cover both 149137356d6Setheisen * NFS version 2 and the NQNFS protocol. Note that the union is only 150137356d6Setheisen * used to that one pointer can refer to both variants. These structures 151137356d6Setheisen * go out on the wire and must be densely packed, so no quad data types 152137356d6Setheisen * are used. (all fields are int32_t or u_int32_t's or structures of same) 153137356d6Setheisen * NB: You can't do sizeof(struct nfsv2_fattr), you must use the 154137356d6Setheisen * NFSX_FATTR(isnq) macro. 155137356d6Setheisen */ 156137356d6Setheisen struct nfsv2_fattr { 157137356d6Setheisen u_int32_t fa_type; 158137356d6Setheisen u_int32_t fa_mode; 159137356d6Setheisen u_int32_t fa_nlink; 160137356d6Setheisen u_int32_t fa_uid; 161137356d6Setheisen u_int32_t fa_gid; 162137356d6Setheisen union { 163137356d6Setheisen struct { 164137356d6Setheisen u_int32_t nfsfa_size; 165137356d6Setheisen u_int32_t nfsfa_blocksize; 166137356d6Setheisen u_int32_t nfsfa_rdev; 167137356d6Setheisen u_int32_t nfsfa_blocks; 168137356d6Setheisen u_int32_t nfsfa_fsid; 169137356d6Setheisen u_int32_t nfsfa_fileid; 170137356d6Setheisen struct nfsv2_time nfsfa_atime; 171137356d6Setheisen struct nfsv2_time nfsfa_mtime; 172137356d6Setheisen struct nfsv2_time nfsfa_ctime; 173137356d6Setheisen } fa_nfsv2; 174137356d6Setheisen struct { 175137356d6Setheisen struct { 176137356d6Setheisen u_int32_t nqfa_qsize[2]; 177137356d6Setheisen } nqfa_size; 178137356d6Setheisen u_int32_t nqfa_blocksize; 179137356d6Setheisen u_int32_t nqfa_rdev; 180137356d6Setheisen struct { 181137356d6Setheisen u_int32_t nqfa_qbytes[2]; 182137356d6Setheisen } nqfa_bytes; 183137356d6Setheisen u_int32_t nqfa_fsid; 184137356d6Setheisen u_int32_t nqfa_fileid; 185137356d6Setheisen struct nqnfs_time nqfa_atime; 186137356d6Setheisen struct nqnfs_time nqfa_mtime; 187137356d6Setheisen struct nqnfs_time nqfa_ctime; 188137356d6Setheisen u_int32_t nqfa_flags; 189137356d6Setheisen u_int32_t nqfa_gen; 190137356d6Setheisen struct { 191137356d6Setheisen u_int32_t nqfa_qfilerev[2]; 192137356d6Setheisen } nqfa_filerev; 193137356d6Setheisen } fa_nqnfs; 194137356d6Setheisen } fa_un; 195137356d6Setheisen }; 196137356d6Setheisen 197137356d6Setheisen /* and some ugly defines for accessing union components */ 198137356d6Setheisen #define fa_nfssize fa_un.fa_nfsv2.nfsfa_size 199137356d6Setheisen #define fa_nfsblocksize fa_un.fa_nfsv2.nfsfa_blocksize 200137356d6Setheisen #define fa_nfsrdev fa_un.fa_nfsv2.nfsfa_rdev 201137356d6Setheisen #define fa_nfsblocks fa_un.fa_nfsv2.nfsfa_blocks 202137356d6Setheisen #define fa_nfsfsid fa_un.fa_nfsv2.nfsfa_fsid 203137356d6Setheisen #define fa_nfsfileid fa_un.fa_nfsv2.nfsfa_fileid 204137356d6Setheisen #define fa_nfsatime fa_un.fa_nfsv2.nfsfa_atime 205137356d6Setheisen #define fa_nfsmtime fa_un.fa_nfsv2.nfsfa_mtime 206137356d6Setheisen #define fa_nfsctime fa_un.fa_nfsv2.nfsfa_ctime 207137356d6Setheisen #define fa_nqsize fa_un.fa_nqnfs.nqfa_size 208137356d6Setheisen #define fa_nqblocksize fa_un.fa_nqnfs.nqfa_blocksize 209137356d6Setheisen #define fa_nqrdev fa_un.fa_nqnfs.nqfa_rdev 210137356d6Setheisen #define fa_nqbytes fa_un.fa_nqnfs.nqfa_bytes 211137356d6Setheisen #define fa_nqfsid fa_un.fa_nqnfs.nqfa_fsid 212137356d6Setheisen #define fa_nqfileid fa_un.fa_nqnfs.nqfa_fileid 213137356d6Setheisen #define fa_nqatime fa_un.fa_nqnfs.nqfa_atime 214137356d6Setheisen #define fa_nqmtime fa_un.fa_nqnfs.nqfa_mtime 215137356d6Setheisen #define fa_nqctime fa_un.fa_nqnfs.nqfa_ctime 216137356d6Setheisen #define fa_nqflags fa_un.fa_nqnfs.nqfa_flags 217137356d6Setheisen #define fa_nqgen fa_un.fa_nqnfs.nqfa_gen 218137356d6Setheisen #define fa_nqfilerev fa_un.fa_nqnfs.nqfa_filerev 219137356d6Setheisen 220137356d6Setheisen struct nfsv2_sattr { 221137356d6Setheisen u_int32_t sa_mode; 222137356d6Setheisen u_int32_t sa_uid; 223137356d6Setheisen u_int32_t sa_gid; 224137356d6Setheisen union { 225137356d6Setheisen struct { 226137356d6Setheisen u_int32_t nfssa_size; 227137356d6Setheisen struct nfsv2_time nfssa_atime; 228137356d6Setheisen struct nfsv2_time nfssa_mtime; 229137356d6Setheisen } sa_nfsv2; 230137356d6Setheisen struct { 231137356d6Setheisen struct { 232137356d6Setheisen u_int32_t nqsa_qsize[2]; 233137356d6Setheisen } nqsa_size; 234137356d6Setheisen struct nqnfs_time nqsa_atime; 235137356d6Setheisen struct nqnfs_time nqsa_mtime; 236137356d6Setheisen u_int32_t nqsa_flags; 237137356d6Setheisen u_int32_t nqsa_rdev; 238137356d6Setheisen } sa_nqnfs; 239137356d6Setheisen } sa_un; 240137356d6Setheisen }; 241137356d6Setheisen 242137356d6Setheisen /* and some ugly defines for accessing the unions */ 243137356d6Setheisen #define sa_nfssize sa_un.sa_nfsv2.nfssa_size 244137356d6Setheisen #define sa_nfsatime sa_un.sa_nfsv2.nfssa_atime 245137356d6Setheisen #define sa_nfsmtime sa_un.sa_nfsv2.nfssa_mtime 246137356d6Setheisen #define sa_nqsize sa_un.sa_nqnfs.nqsa_size 247137356d6Setheisen #define sa_nqatime sa_un.sa_nqnfs.nqsa_atime 248137356d6Setheisen #define sa_nqmtime sa_un.sa_nqnfs.nqsa_mtime 249137356d6Setheisen #define sa_nqflags sa_un.sa_nqnfs.nqsa_flags 250137356d6Setheisen #define sa_nqrdev sa_un.sa_nqnfs.nqsa_rdev 251137356d6Setheisen 252137356d6Setheisen struct nfsv2_statfs { 253137356d6Setheisen u_int32_t sf_tsize; 254137356d6Setheisen u_int32_t sf_bsize; 255137356d6Setheisen u_int32_t sf_blocks; 256137356d6Setheisen u_int32_t sf_bfree; 257137356d6Setheisen u_int32_t sf_bavail; 258137356d6Setheisen u_int32_t sf_files; /* Nqnfs only */ 259137356d6Setheisen u_int32_t sf_ffree; /* ditto */ 260137356d6Setheisen }; 261