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