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