2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1989, 1993
33 * The Regents of the University of California. All rights reserved.
35 * This code is derived from software contributed to Berkeley by
36 * Rick Macklem at The University of Guelph.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95
67 * FreeBSD-Id: nfsproto.h,v 1.3 1997/02/22 09:42:50 peter Exp $
70 #ifndef _NFS_NFSPROTO_H_
71 #define _NFS_NFSPROTO_H_
73 #include <sys/appleapiopts.h>
75 #ifdef __APPLE_API_PRIVATE
77 * nfs definitions as per the Version 2 and 3 specs
81 * Constants as defined in the Sun NFS Version 2 and 3 specs.
82 * "NFS: Network File System Protocol Specification" RFC1094
83 * and in the "NFS: Network File System Version 3 Protocol
87 /* Only define these if nfs_prot.h hasn't been included */
91 #define NFS_PROG 100003
94 #define NFS_V2MAXDATA 8192
95 #define NFS_MAXDGRAMDATA 16384
96 #define NFS_PREFDGRAMDATA 8192
97 #define NFS_MAXDATA (60*1024) // XXX not ready for 64K-128K
98 #define NFS_MAXPATHLEN 1024
99 #define NFS_MAXNAMLEN 255
100 #define NFS_MAXPKTHDR 404
101 #define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA)
102 #define NFS_MINPACKET 20
103 #define NFS_MAXSOCKBUF (224*1024)
104 #define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */
106 /* Stat numbers for rpc returns (version 2 and 3) */
108 #define NFSERR_PERM 1
109 #define NFSERR_NOENT 2
111 #define NFSERR_NXIO 6
112 #define NFSERR_ACCES 13
113 #define NFSERR_EXIST 17
114 #define NFSERR_XDEV 18 /* Version 3 only */
115 #define NFSERR_NODEV 19
116 #define NFSERR_NOTDIR 20
117 #define NFSERR_ISDIR 21
118 #define NFSERR_INVAL 22 /* Version 3 only */
119 #define NFSERR_FBIG 27
120 #define NFSERR_NOSPC 28
121 #define NFSERR_ROFS 30
122 #define NFSERR_MLINK 31 /* Version 3 only */
123 #define NFSERR_NAMETOL 63
124 #define NFSERR_NOTEMPTY 66
125 #define NFSERR_DQUOT 69
126 #define NFSERR_STALE 70
127 #define NFSERR_REMOTE 71 /* Version 3 only */
128 #define NFSERR_WFLUSH 99 /* Version 2 only */
129 #define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */
130 #define NFSERR_NOT_SYNC 10002
131 #define NFSERR_BAD_COOKIE 10003
132 #define NFSERR_NOTSUPP 10004
133 #define NFSERR_TOOSMALL 10005
134 #define NFSERR_SERVERFAULT 10006
135 #define NFSERR_BADTYPE 10007
136 #define NFSERR_JUKEBOX 10008
137 #define NFSERR_TRYLATER NFSERR_JUKEBOX
138 #define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */
140 #define NFSERR_RETVOID 0x20000000 /* Return void, not error */
141 #define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */
142 #define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */
144 #endif /* !NFS_PROGRAM */
146 /* Sizes in bytes of various nfs rpc components */
147 #define NFSX_UNSIGNED 4
149 /* specific to NFS Version 2 */
151 #define NFSX_V2FATTR 68
152 #define NFSX_V2SATTR 32
153 #define NFSX_V2COOKIE 4
154 #define NFSX_V2STATFS 20
156 /* specific to NFS Version 3 */
157 #define NFSX_V3FHMAX 64 /* max. allowed by protocol */
158 #define NFSX_V3FATTR 84
159 #define NFSX_V3SATTR 60 /* max. all fields filled in */
160 #define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED)
161 #define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED)
162 #define NFSX_V3COOKIEVERF 8
163 #define NFSX_V3WRITEVERF 8
164 #define NFSX_V3CREATEVERF 8
165 #define NFSX_V3STATFS 52
166 #define NFSX_V3FSINFO 48
167 #define NFSX_V3PATHCONF 24
169 /* variants for both versions */
170 #define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \
172 #define NFSX_SRVFH(v3,FH) ((v3) ? (FH)->nfh_len : NFSX_V2FH)
173 #define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR)
174 #define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0)
175 #define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0)
176 #define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \
178 #define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0)
179 #define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR)
180 #define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR)
181 #define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0)
182 #define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0)
183 #define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \
185 #define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS)
187 /* Only define these if nfs_prot.h hasn't been included */
190 /* nfs rpc procedure numbers (before version mapping) */
191 #define NFSPROC_NULL 0
192 #define NFSPROC_GETATTR 1
193 #define NFSPROC_SETATTR 2
194 #define NFSPROC_LOOKUP 3
195 #define NFSPROC_ACCESS 4
196 #define NFSPROC_READLINK 5
197 #define NFSPROC_READ 6
198 #define NFSPROC_WRITE 7
199 #define NFSPROC_CREATE 8
200 #define NFSPROC_MKDIR 9
201 #define NFSPROC_SYMLINK 10
202 #define NFSPROC_MKNOD 11
203 #define NFSPROC_REMOVE 12
204 #define NFSPROC_RMDIR 13
205 #define NFSPROC_RENAME 14
206 #define NFSPROC_LINK 15
207 #define NFSPROC_READDIR 16
208 #define NFSPROC_READDIRPLUS 17
209 #define NFSPROC_FSSTAT 18
210 #define NFSPROC_FSINFO 19
211 #define NFSPROC_PATHCONF 20
212 #define NFSPROC_COMMIT 21
214 #endif /* !NFS_PROGRAM */
216 #define NFSPROC_NOOP 22
217 #define NFS_NPROCS 23
219 /* Actual Version 2 procedure numbers */
220 #define NFSV2PROC_NULL 0
221 #define NFSV2PROC_GETATTR 1
222 #define NFSV2PROC_SETATTR 2
223 #define NFSV2PROC_NOOP 3
224 #define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */
225 #define NFSV2PROC_LOOKUP 4
226 #define NFSV2PROC_READLINK 5
227 #define NFSV2PROC_READ 6
228 #define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */
229 #define NFSV2PROC_WRITE 8
230 #define NFSV2PROC_CREATE 9
231 #define NFSV2PROC_REMOVE 10
232 #define NFSV2PROC_RENAME 11
233 #define NFSV2PROC_LINK 12
234 #define NFSV2PROC_SYMLINK 13
235 #define NFSV2PROC_MKDIR 14
236 #define NFSV2PROC_RMDIR 15
237 #define NFSV2PROC_READDIR 16
238 #define NFSV2PROC_STATFS 17
241 * Constants used by the Version 3 protocol for various RPCs
243 #define NFSV3SATTRTIME_DONTCHANGE 0
244 #define NFSV3SATTRTIME_TOSERVER 1
245 #define NFSV3SATTRTIME_TOCLIENT 2
247 #define NFSV3ACCESS_READ 0x01
248 #define NFSV3ACCESS_LOOKUP 0x02
249 #define NFSV3ACCESS_MODIFY 0x04
250 #define NFSV3ACCESS_EXTEND 0x08
251 #define NFSV3ACCESS_DELETE 0x10
252 #define NFSV3ACCESS_EXECUTE 0x20
254 #define NFSV3WRITE_UNSTABLE 0
255 #define NFSV3WRITE_DATASYNC 1
256 #define NFSV3WRITE_FILESYNC 2
258 #define NFSV3CREATE_UNCHECKED 0
259 #define NFSV3CREATE_GUARDED 1
260 #define NFSV3CREATE_EXCLUSIVE 2
262 #define NFSV3FSINFO_LINK 0x01
263 #define NFSV3FSINFO_SYMLINK 0x02
264 #define NFSV3FSINFO_HOMOGENEOUS 0x08
265 #define NFSV3FSINFO_CANSETTIME 0x10
267 /* Conversion macros */
268 #define vtonfsv2_mode(t,m) \
269 txdr_unsigned(((t) == VFIFO) ? vnode_makeimode(VCHR, (m)) : \
270 vnode_makeimode((t), (m)))
271 #define vtonfsv3_mode(m) txdr_unsigned((m) & 07777)
272 #define nfstov_mode(a) (fxdr_unsigned(u_short, (a))&07777)
273 #define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((long)(a))])
274 #define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((long)(a))])
275 #define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_long,(a))&0x7]
276 #define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_long,(a))&0x7]
278 /* Only define these if nfs_prot.h hasn't been included */
282 typedef enum { NFNON
=0, NFREG
=1, NFDIR
=2, NFBLK
=3, NFCHR
=4, NFLNK
=5,
283 NFSOCK
=6, NFFIFO
=7 } nfstype
;
284 #endif /* !NFS_PROGRAM */
286 /* Structs for common parts of the rpc's */
288 * File Handle (32 bytes for version 2), variable up to 64 for version 3.
289 * File Handles of up to NFS_SMALLFH in size are stored directly in the
290 * nfs node, whereas larger ones are malloc'd. (This never happens when
291 * NFS_SMALLFH is set to 64.)
292 * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4.
295 #define NFS_SMALLFH 64
302 typedef struct nfsv2_time nfstime2
;
308 typedef struct nfsv3_time nfstime3
;
311 * Quads are defined as arrays of 2 longs to ensure dense packing for the
312 * protocol and to facilitate xdr conversion.
317 typedef struct nfs_uquad nfsuint64
;
320 * Used to convert between two u_longs and a u_quad_t.
322 union nfs_quadconvert
{
326 typedef union nfs_quadconvert nfsquad_t
;
329 * NFS Version 3 special file number.
335 typedef struct nfsv3_spec nfsv3spec
;
338 * File attributes and setable attributes. These structures cover both
339 * NFS version 2 and the version 3 protocol. Note that the union is only
340 * used so that one pointer can refer to both variants. These structures
341 * go out on the wire and must be densely packed, so no quad data types
342 * are used. (all fields are longs or u_longs or structures of same)
343 * NB: You can't do sizeof(struct nfs_fattr), you must use the
344 * NFSX_FATTR(v3) macro.
355 u_long nfsv2fa_blocksize
;
357 u_long nfsv2fa_blocks
;
359 u_long nfsv2fa_fileid
;
360 nfstime2 nfsv2fa_atime
;
361 nfstime2 nfsv2fa_mtime
;
362 nfstime2 nfsv2fa_ctime
;
365 nfsuint64 nfsv3fa_size
;
366 nfsuint64 nfsv3fa_used
;
367 nfsv3spec nfsv3fa_rdev
;
368 nfsuint64 nfsv3fa_fsid
;
369 nfsuint64 nfsv3fa_fileid
;
370 nfstime3 nfsv3fa_atime
;
371 nfstime3 nfsv3fa_mtime
;
372 nfstime3 nfsv3fa_ctime
;
377 /* and some ugly defines for accessing union components */
378 #define fa2_size fa_un.fa_nfsv2.nfsv2fa_size
379 #define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize
380 #define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev
381 #define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks
382 #define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid
383 #define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid
384 #define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime
385 #define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime
386 #define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime
387 #define fa3_size fa_un.fa_nfsv3.nfsv3fa_size
388 #define fa3_used fa_un.fa_nfsv3.nfsv3fa_used
389 #define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev
390 #define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid
391 #define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid
392 #define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime
393 #define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime
394 #define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime
408 u_long nfsv2sf_tsize
;
409 u_long nfsv2sf_bsize
;
410 u_long nfsv2sf_blocks
;
411 u_long nfsv2sf_bfree
;
412 u_long nfsv2sf_bavail
;
415 nfsuint64 nfsv3sf_tbytes
;
416 nfsuint64 nfsv3sf_fbytes
;
417 nfsuint64 nfsv3sf_abytes
;
418 nfsuint64 nfsv3sf_tfiles
;
419 nfsuint64 nfsv3sf_ffiles
;
420 nfsuint64 nfsv3sf_afiles
;
421 u_long nfsv3sf_invarsec
;
426 #define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize
427 #define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize
428 #define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks
429 #define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree
430 #define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail
431 #define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes
432 #define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes
433 #define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes
434 #define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles
435 #define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles
436 #define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles
437 #define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec
439 struct nfsv3_fsinfo
{
447 nfsuint64 fs_maxfilesize
;
448 nfstime3 fs_timedelta
;
449 u_long fs_properties
;
452 struct nfsv3_pathconf
{
456 u_long pc_chownrestricted
;
457 u_long pc_caseinsensitive
;
458 u_long pc_casepreserving
;
461 #endif /* __APPLE_API_PRIVATE */
462 #endif /* _NFS_NFSPROTO_H_ */