xref: /openbsd/usr.sbin/amd/rpcx/nfs_prot.x (revision 5dea098c)
1 /*	$OpenBSD: nfs_prot.x,v 1.2 2022/12/28 21:30:15 jmc Exp $	*/
2 
3 /*
4  * Copyright (c) 2010, Oracle America, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  *       copyright notice, this list of conditions and the following
14  *       disclaimer in the documentation and/or other materials
15  *       provided with the distribution.
16  *     * Neither the name of the "Oracle America, Inc." nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef RPC_HDR
35 #endif
36 
37 const NFS_PORT		= 2049;
38 const NFS_MAXDATA	= 8192;
39 const NFS_MAXPATHLEN	= 1024;
40 const NFS_MAXNAMLEN	= 255;
41 const NFS_FHSIZE	= 32;
42 const NFSX_V2FH		= 32;
43 const NFSX_V3FHMAX	= 64;
44 const NFS_COOKIESIZE	= 4;
45 const NFS_FIFO_DEV	= -1;	/* size kludge for named pipes */
46 
47 /*
48  * File types
49  */
50 const NFSMODE_FMT  = 0170000;	/* type of file */
51 const NFSMODE_DIR  = 0040000;	/* directory */
52 const NFSMODE_CHR  = 0020000;	/* character special */
53 const NFSMODE_BLK  = 0060000;	/* block special */
54 const NFSMODE_REG  = 0100000;	/* regular */
55 const NFSMODE_LNK  = 0120000;	/* symbolic link */
56 const NFSMODE_SOCK = 0140000;	/* socket */
57 const NFSMODE_FIFO = 0010000;	/* fifo */
58 
59 /*
60  * Error status
61  */
62 #ifdef RPC_HDR
63 %typedef int nfsstat;
64 %#define xdr_nfsstat xdr_int
65 #define nfsstat int
66 %enum {
67 %	NFS_OK= 0,		/* no error */
68 %	NFSERR_PERM=1,		/* Not owner */
69 %	NFSERR_NOENT=2,		/* No such file or directory */
70 %	NFSERR_IO=5,		/* I/O error */
71 %	NFSERR_NXIO=6,		/* No such device or address */
72 %	NFSERR_ACCES=13,	/* Permission denied */
73 %	NFSERR_EXIST=17,	/* File exists */
74 %	NFSERR_NODEV=19,	/* No such device */
75 %	NFSERR_NOTDIR=20,	/* Not a directory*/
76 %	NFSERR_ISDIR=21,	/* Is a directory */
77 %	NFSERR_FBIG=27,		/* File too large */
78 %	NFSERR_NOSPC=28,	/* No space left on device */
79 %	NFSERR_ROFS=30,		/* Read-only file system */
80 %	NFSERR_NAMETOOLONG=63,	/* File name too long */
81 %	NFSERR_NOTEMPTY=66,	/* Directory not empty */
82 %	NFSERR_DQUOT=69,	/* Disc quota exceeded */
83 %	NFSERR_STALE=70,	/* Stale NFS file handle */
84 %	NFSERR_WFLUSH=99	/* write cache flushed */
85 %};
86 #elif RPC_XDR
87 #define nfsstat int
88 #else
89 typedef int nfsstat;
90 #endif
91 
92 /*
93  * File types
94  */
95 #ifdef RPC_HDR
96 %typedef int ftype;
97 #define ftype int
98 %enum {
99 %	NFNON = 0,	/* non-file */
100 %	NFREG = 1,	/* regular file */
101 %	NFDIR = 2,	/* directory */
102 %	NFBLK = 3,	/* block special */
103 %	NFCHR = 4,	/* character special */
104 %	NFLNK = 5,	/* symbolic link */
105 %	NFSOCK = 6,	/* unix domain sockets */
106 %	NFBAD = 7,	/* unused */
107 %	NFFIFO = 8	/* named pipe */
108 %};
109 #elif RPC_XDR
110 #define ftype int
111 #else
112 typedef int ftype;
113 #endif
114 
115 /*
116  * File access handle
117  */
118 struct nfs_fh {
119 	opaque data[NFS_FHSIZE];
120 };
121 
122 /*
123  * Timeval
124  */
125 struct nfstime {
126 	unsigned seconds;
127 	unsigned useconds;
128 };
129 
130 
131 /*
132  * File attributes
133  */
134 struct fattr {
135 	ftype type;		/* file type */
136 	unsigned mode;		/* protection mode bits */
137 	unsigned nlink;		/* # hard links */
138 	unsigned uid;		/* owner user id */
139 	unsigned gid;		/* owner group id */
140 	unsigned size;		/* file size in bytes */
141 	unsigned blocksize;	/* preferred block size */
142 	unsigned rdev;		/* special device # */
143 	unsigned blocks;	/* Kb of disk used by file */
144 	unsigned fsid;		/* device # */
145 	unsigned fileid;	/* inode # */
146 	nfstime	atime;		/* time of last access */
147 	nfstime	mtime;		/* time of last modification */
148 	nfstime	ctime;		/* time of last change */
149 };
150 
151 /*
152  * File attributes which can be set
153  */
154 struct sattr {
155 	unsigned mode;	/* protection mode bits */
156 	unsigned uid;	/* owner user id */
157 	unsigned gid;	/* owner group id */
158 	unsigned size;	/* file size in bytes */
159 	nfstime	atime;	/* time of last access */
160 	nfstime	mtime;	/* time of last modification */
161 };
162 
163 
164 typedef string filename<NFS_MAXNAMLEN>;
165 typedef string nfspath<NFS_MAXPATHLEN>;
166 
167 /*
168  * Reply status with file attributes
169  */
170 union attrstat switch (nfsstat status) {
171 case NFS_OK:
172 	fattr attributes;
173 default:
174 	void;
175 };
176 
177 struct sattrargs {
178 	nfs_fh file;
179 	sattr attributes;
180 };
181 
182 /*
183  * Arguments for directory operations
184  */
185 struct diropargs {
186 	nfs_fh	dir;	/* directory file handle */
187 	filename name;		/* name (up to NFS_MAXNAMLEN bytes) */
188 };
189 
190 struct diropokres {
191 	nfs_fh file;
192 	fattr attributes;
193 };
194 
195 /*
196  * Results from directory operation
197  */
198 union diropres switch (nfsstat status) {
199 case NFS_OK:
200 	diropokres diropres;
201 default:
202 	void;
203 };
204 
205 union readlinkres switch (nfsstat status) {
206 case NFS_OK:
207 	nfspath data;
208 default:
209 	void;
210 };
211 
212 /*
213  * Arguments to remote read
214  */
215 struct readargs {
216 	nfs_fh file;		/* handle for file */
217 	unsigned offset;	/* byte offset in file */
218 	unsigned count;		/* immediate read count */
219 	unsigned totalcount;	/* total read count (from this offset)*/
220 };
221 
222 /*
223  * Status OK portion of remote read reply
224  */
225 struct readokres {
226 	fattr	attributes;	/* attributes, need for pagin*/
227 	opaque data<NFS_MAXDATA>;
228 };
229 
230 union readres switch (nfsstat status) {
231 case NFS_OK:
232 	readokres reply;
233 default:
234 	void;
235 };
236 
237 /*
238  * Arguments to remote write
239  */
240 struct writeargs {
241 	nfs_fh	file;		/* handle for file */
242 	unsigned beginoffset;	/* beginning byte offset in file */
243 	unsigned offset;	/* current byte offset in file */
244 	unsigned totalcount;	/* total write count (to this offset)*/
245 	opaque data<NFS_MAXDATA>;
246 };
247 
248 struct createargs {
249 	diropargs where;
250 	sattr attributes;
251 };
252 
253 struct renameargs {
254 	diropargs from;
255 	diropargs to;
256 };
257 
258 struct linkargs {
259 	nfs_fh from;
260 	diropargs to;
261 };
262 
263 struct symlinkargs {
264 	diropargs from;
265 	nfspath to;
266 	sattr attributes;
267 };
268 
269 
270 typedef opaque nfscookie[NFS_COOKIESIZE];
271 
272 /*
273  * Arguments to readdir
274  */
275 struct readdirargs {
276 	nfs_fh dir;		/* directory handle */
277 	nfscookie cookie;
278 	unsigned count;		/* number of directory bytes to read */
279 };
280 
281 struct entry {
282 	unsigned fileid;
283 	filename name;
284 	nfscookie cookie;
285 	entry *nextentry;
286 };
287 
288 struct dirlist {
289 	entry *entries;
290 	bool eof;
291 };
292 
293 union readdirres switch (nfsstat status) {
294 case NFS_OK:
295 	dirlist reply;
296 default:
297 	void;
298 };
299 
300 struct statfsokres {
301 	unsigned tsize;	/* preferred transfer size in bytes */
302 	unsigned bsize;	/* fundamental file system block size */
303 	unsigned blocks;	/* total blocks in file system */
304 	unsigned bfree;	/* free blocks in fs */
305 	unsigned bavail;	/* free blocks avail to non-superuser */
306 };
307 
308 union statfsres switch (nfsstat status) {
309 case NFS_OK:
310 	statfsokres reply;
311 default:
312 	void;
313 };
314 
315 /*
316  * Remote file service routines
317  */
318 program NFS_PROGRAM {
319 	version NFS_VERSION {
320 		void
321 		NFSPROC_NULL(void) = 0;
322 
323 		attrstat
324 		NFSPROC_GETATTR(nfs_fh) =	1;
325 
326 		attrstat
327 		NFSPROC_SETATTR(sattrargs) = 2;
328 
329 		void
330 		NFSPROC_ROOT(void) = 3;
331 
332 		diropres
333 		NFSPROC_LOOKUP(diropargs) = 4;
334 
335 		readlinkres
336 		NFSPROC_READLINK(nfs_fh) = 5;
337 
338 		readres
339 		NFSPROC_READ(readargs) = 6;
340 
341 		void
342 		NFSPROC_WRITECACHE(void) = 7;
343 
344 		attrstat
345 		NFSPROC_WRITE(writeargs) = 8;
346 
347 		diropres
348 		NFSPROC_CREATE(createargs) = 9;
349 
350 		nfsstat
351 		NFSPROC_REMOVE(diropargs) = 10;
352 
353 		nfsstat
354 		NFSPROC_RENAME(renameargs) = 11;
355 
356 		nfsstat
357 		NFSPROC_LINK(linkargs) = 12;
358 
359 		nfsstat
360 		NFSPROC_SYMLINK(symlinkargs) = 13;
361 
362 		diropres
363 		NFSPROC_MKDIR(createargs) = 14;
364 
365 		nfsstat
366 		NFSPROC_RMDIR(diropargs) = 15;
367 
368 		readdirres
369 		NFSPROC_READDIR(readdirargs) = 16;
370 
371 		statfsres
372 		NFSPROC_STATFS(nfs_fh) = 17;
373 	} = 2;
374 } = 100003;
375 
376