1 /* NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp */
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Rick Macklem at The University of Guelph.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95
42 * nfs definitions as per the Version 2 and 3 specs
46 * Constants as defined in the Sun NFS Version 2 and 3 specs.
47 * "NFS: Network File System Protocol Specification" RFC1094
48 * and in the "NFS: Network File System Version 3 Protocol
53 #define NFS_PROG 100003
56 #define NFS_V2MAXDATA 8192
57 #define NFS_MAXDGRAMDATA 16384
58 #define NFS_MAXDATA 32768
59 #define NFS_MAXPATHLEN 1024
60 #define NFS_MAXNAMLEN 255
61 #define NFS_MAXPKTHDR 404
62 #define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA)
63 #define NFS_MINPACKET 20
64 #define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */
66 /* Stat numbers for rpc returns (version 2 and 3) */
69 #define NFSERR_NOENT 2
72 #define NFSERR_ACCES 13
73 #define NFSERR_EXIST 17
74 #define NFSERR_XDEV 18 /* Version 3 only */
75 #define NFSERR_NODEV 19
76 #define NFSERR_NOTDIR 20
77 #define NFSERR_ISDIR 21
78 #define NFSERR_INVAL 22 /* Version 3 only */
79 #define NFSERR_FBIG 27
80 #define NFSERR_NOSPC 28
81 #define NFSERR_ROFS 30
82 #define NFSERR_MLINK 31 /* Version 3 only */
83 #define NFSERR_NAMETOL 63
84 #define NFSERR_NOTEMPTY 66
85 #define NFSERR_DQUOT 69
86 #define NFSERR_STALE 70
87 #define NFSERR_REMOTE 71 /* Version 3 only */
88 #define NFSERR_WFLUSH 99 /* Version 2 only */
89 #define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */
90 #define NFSERR_NOT_SYNC 10002
91 #define NFSERR_BAD_COOKIE 10003
92 #define NFSERR_NOTSUPP 10004
93 #define NFSERR_TOOSMALL 10005
94 #define NFSERR_SERVERFAULT 10006
95 #define NFSERR_BADTYPE 10007
96 #define NFSERR_JUKEBOX 10008
97 #define NFSERR_TRYLATER NFSERR_JUKEBOX
98 #define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */
100 #define NFSERR_RETVOID 0x20000000 /* Return void, not error */
101 #define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */
102 #define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */
104 /* Sizes in bytes of various nfs rpc components */
105 #define NFSX_UNSIGNED 4
107 /* specific to NFS Version 2 */
109 #define NFSX_V2FATTR 68
110 #define NFSX_V2SATTR 32
111 #define NFSX_V2COOKIE 4
112 #define NFSX_V2STATFS 20
114 /* specific to NFS Version 3 */
116 #define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */
118 #define NFSX_V3FHMAX 64 /* max. allowed by protocol */
119 #define NFSX_V3FATTR 84
120 #define NFSX_V3SATTR 60 /* max. all fields filled in */
121 #define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
122 #define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
123 #define NFSX_V3COOKIEVERF 8
124 #define NFSX_V3WRITEVERF 8
125 #define NFSX_V3CREATEVERF 8
126 #define NFSX_V3STATFS 52
127 #define NFSX_V3FSINFO 48
128 #define NFSX_V3PATHCONF 24
130 /* variants for both versions */
131 #define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \
133 #define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH)
134 #define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR)
135 #define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0)
136 #define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0)
137 #define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \
139 #define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
140 #define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
141 #define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
142 #define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
143 #define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
145 #define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS)
147 /* nfs rpc procedure numbers (before version mapping) */
148 #define NFSPROC_NULL 0
149 #define NFSPROC_GETATTR 1
150 #define NFSPROC_SETATTR 2
151 #define NFSPROC_LOOKUP 3
152 #define NFSPROC_ACCESS 4
153 #define NFSPROC_READLINK 5
154 #define NFSPROC_READ 6
155 #define NFSPROC_WRITE 7
156 #define NFSPROC_CREATE 8
157 #define NFSPROC_MKDIR 9
158 #define NFSPROC_SYMLINK 10
159 #define NFSPROC_MKNOD 11
160 #define NFSPROC_REMOVE 12
161 #define NFSPROC_RMDIR 13
162 #define NFSPROC_RENAME 14
163 #define NFSPROC_LINK 15
164 #define NFSPROC_READDIR 16
165 #define NFSPROC_READDIRPLUS 17
166 #define NFSPROC_FSSTAT 18
167 #define NFSPROC_FSINFO 19
168 #define NFSPROC_PATHCONF 20
169 #define NFSPROC_COMMIT 21
171 /* And leasing (nqnfs) procedure numbers (must be last) */
172 #define NQNFSPROC_GETLEASE 22
173 #define NQNFSPROC_VACATED 23
174 #define NQNFSPROC_EVICTED 24
176 #define NFSPROC_NOOP 25
177 #define NFS_NPROCS 26
179 /* Actual Version 2 procedure numbers */
180 #define NFSV2PROC_NULL 0
181 #define NFSV2PROC_GETATTR 1
182 #define NFSV2PROC_SETATTR 2
183 #define NFSV2PROC_NOOP 3
184 #define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */
185 #define NFSV2PROC_LOOKUP 4
186 #define NFSV2PROC_READLINK 5
187 #define NFSV2PROC_READ 6
188 #define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */
189 #define NFSV2PROC_WRITE 8
190 #define NFSV2PROC_CREATE 9
191 #define NFSV2PROC_REMOVE 10
192 #define NFSV2PROC_RENAME 11
193 #define NFSV2PROC_LINK 12
194 #define NFSV2PROC_SYMLINK 13
195 #define NFSV2PROC_MKDIR 14
196 #define NFSV2PROC_RMDIR 15
197 #define NFSV2PROC_READDIR 16
198 #define NFSV2PROC_STATFS 17
201 * Constants used by the Version 3 protocol for various RPCs
203 #define NFSV3SATTRTIME_DONTCHANGE 0
204 #define NFSV3SATTRTIME_TOSERVER 1
205 #define NFSV3SATTRTIME_TOCLIENT 2
207 #define NFSV3ATTRTIME_NMODES 3
209 #define NFSV3ACCESS_READ 0x01
210 #define NFSV3ACCESS_LOOKUP 0x02
211 #define NFSV3ACCESS_MODIFY 0x04
212 #define NFSV3ACCESS_EXTEND 0x08
213 #define NFSV3ACCESS_DELETE 0x10
214 #define NFSV3ACCESS_EXECUTE 0x20
215 #define NFSV3ACCESS_FULL 0x3f
217 #define NFSV3WRITE_UNSTABLE 0
218 #define NFSV3WRITE_DATASYNC 1
219 #define NFSV3WRITE_FILESYNC 2
221 #define NFSV3WRITE_NMODES 3
223 #define NFSV3CREATE_UNCHECKED 0
224 #define NFSV3CREATE_GUARDED 1
225 #define NFSV3CREATE_EXCLUSIVE 2
227 #define NFSV3CREATE_NMODES 3
229 #define NFSV3FSINFO_LINK 0x01
230 #define NFSV3FSINFO_SYMLINK 0x02
231 #define NFSV3FSINFO_HOMOGENEOUS 0x08
232 #define NFSV3FSINFO_CANSETTIME 0x10
234 /* Conversion macros */
235 #define vtonfsv2_mode(t,m) \
236 txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \
238 #define vtonfsv3_mode(m) txdr_unsigned((m) & 07777)
239 #define nfstov_mode(a) (fxdr_unsigned(uint16_t, (a))&07777)
240 #define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
241 #define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))])
242 #define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(uint32_t,(a))&0x7]
243 #define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(uint32_t,(a))&0x7]
246 typedef enum { NFNON
=0, NFREG
=1, NFDIR
=2, NFBLK
=3, NFCHR
=4, NFLNK
=5,
247 NFSOCK
=6, NFFIFO
=7 } nfs_type
;
250 * Structs for common parts of the rpc's
252 * NOTE: these structures are not always overlaid directly on the
253 * packet data - sometimes we declare a local variable of that type,
254 * and fill it up with fields extracted using byte pointers - so we
255 * don't use nd_ types for their members.
259 * File Handle (32 bytes for version 2), variable up to 64 for version 3.
260 * File Handles of up to NFS_SMALLFH in size are stored directly in the
261 * nfs node, whereas larger ones are malloc'd. (This never happens when
262 * NFS_SMALLFH is set to 64.)
263 * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4.
266 #define NFS_SMALLFH 64
269 /* fhandle_t fh_generic; */
270 u_char fh_bytes
[NFS_SMALLFH
];
272 typedef union nfsfh nfsfh_t
;
275 nd_uint32_t nfsv2_sec
;
276 nd_uint32_t nfsv2_usec
;
278 typedef struct nfsv2_time nfstime2
;
281 nd_uint32_t nfsv3_sec
;
282 nd_uint32_t nfsv3_nsec
;
284 typedef struct nfsv3_time nfstime3
;
287 * Quads are defined as arrays of 2 longs to ensure dense packing for the
288 * protocol and to facilitate xdr conversion.
291 nd_uint32_t nfsuquad
[2];
293 typedef struct nfs_uquad nfsuint64
;
296 * NFS Version 3 special file number.
299 nd_uint32_t specdata1
;
300 nd_uint32_t specdata2
;
302 typedef struct nfsv3_spec nfsv3spec
;
305 * File attributes and setable attributes. These structures cover both
306 * NFS version 2 and the version 3 protocol. Note that the union is only
307 * used so that one pointer can refer to both variants. These structures
308 * go out on the wire and must be densely packed, so no quad data types
309 * are used. (all fields are longs or u_longs or structures of same)
310 * NB: You can't do sizeof(struct nfs_fattr), you must use the
311 * NFSX_FATTR(v3) macro.
316 nd_uint32_t fa_nlink
;
321 nd_uint32_t nfsv2fa_size
;
322 nd_uint32_t nfsv2fa_blocksize
;
323 nd_uint32_t nfsv2fa_rdev
;
324 nd_uint32_t nfsv2fa_blocks
;
325 nd_uint32_t nfsv2fa_fsid
;
326 nd_uint32_t nfsv2fa_fileid
;
327 nfstime2 nfsv2fa_atime
;
328 nfstime2 nfsv2fa_mtime
;
329 nfstime2 nfsv2fa_ctime
;
332 nd_uint64_t nfsv3fa_size
;
333 nd_uint64_t nfsv3fa_used
;
334 nfsv3spec nfsv3fa_rdev
;
335 nd_uint64_t nfsv3fa_fsid
;
336 nd_uint64_t nfsv3fa_fileid
;
337 nfstime3 nfsv3fa_atime
;
338 nfstime3 nfsv3fa_mtime
;
339 nfstime3 nfsv3fa_ctime
;
344 /* and some ugly defines for accessing union components */
345 #define fa2_size fa_un.fa_nfsv2.nfsv2fa_size
346 #define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize
347 #define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev
348 #define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks
349 #define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid
350 #define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid
351 #define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime
352 #define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime
353 #define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime
354 #define fa3_size fa_un.fa_nfsv3.nfsv3fa_size
355 #define fa3_used fa_un.fa_nfsv3.nfsv3fa_used
356 #define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev
357 #define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid
358 #define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid
359 #define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime
360 #define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime
361 #define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
375 nd_uint32_t nfsv2sf_tsize
;
376 nd_uint32_t nfsv2sf_bsize
;
377 nd_uint32_t nfsv2sf_blocks
;
378 nd_uint32_t nfsv2sf_bfree
;
379 nd_uint32_t nfsv2sf_bavail
;
382 nd_uint64_t nfsv3sf_tbytes
;
383 nd_uint64_t nfsv3sf_fbytes
;
384 nd_uint64_t nfsv3sf_abytes
;
385 nd_uint64_t nfsv3sf_tfiles
;
386 nd_uint64_t nfsv3sf_ffiles
;
387 nd_uint64_t nfsv3sf_afiles
;
388 nd_uint32_t nfsv3sf_invarsec
;
393 #define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize
394 #define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize
395 #define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks
396 #define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree
397 #define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail
398 #define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes
399 #define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes
400 #define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes
401 #define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles
402 #define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles
403 #define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles
404 #define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
406 struct nfsv3_fsinfo
{
407 nd_uint32_t fs_rtmax
;
408 nd_uint32_t fs_rtpref
;
409 nd_uint32_t fs_rtmult
;
410 nd_uint32_t fs_wtmax
;
411 nd_uint32_t fs_wtpref
;
412 nd_uint32_t fs_wtmult
;
413 nd_uint32_t fs_dtpref
;
414 nd_uint64_t fs_maxfilesize
;
415 nfstime3 fs_timedelta
;
416 nd_uint32_t fs_properties
;
419 struct nfsv3_pathconf
{
420 nd_uint32_t pc_linkmax
;
421 nd_uint32_t pc_namemax
;
422 nd_uint32_t pc_notrunc
;
423 nd_uint32_t pc_chownrestricted
;
424 nd_uint32_t pc_caseinsensitive
;
425 nd_uint32_t pc_casepreserving
;