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