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