xref: /openbsd-src/lib/librpcsvc/nfs_prot.x (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: nfs_prot.x,v 1.3 2004/01/17 12:32:11 deraadt Exp $	*/
2 
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31 
32 #ifndef RPC_HDR
33 %#ifndef lint
34 %/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/
35 %/*static char sccsid[] = "from: @(#)nfs_prot.x	2.1 88/08/01 4.0 RPCSRC";*/
36 %static char rcsid[] = "$OpenBSD: nfs_prot.x,v 1.3 2004/01/17 12:32:11 deraadt Exp $";
37 %#endif /* not lint */
38 #endif
39 
40 const NFS_PORT		= 2049;
41 const NFS_MAXDATA	= 8192;
42 const NFS_MAXPATHLEN	= 1024;
43 const NFS_MAXNAMLEN	= 255;
44 const NFS_FHSIZE	= 32;
45 const NFS_COOKIESIZE	= 4;
46 const NFS_FIFO_DEV	= -1;	/* size kludge for named pipes */
47 
48 /*
49  * File types
50  */
51 const NFSMODE_FMT  = 0170000;	/* type of file */
52 const NFSMODE_DIR  = 0040000;	/* directory */
53 const NFSMODE_CHR  = 0020000;	/* character special */
54 const NFSMODE_BLK  = 0060000;	/* block special */
55 const NFSMODE_REG  = 0100000;	/* regular */
56 const NFSMODE_LNK  = 0120000;	/* symbolic link */
57 const NFSMODE_SOCK = 0140000;	/* socket */
58 const NFSMODE_FIFO = 0010000;	/* fifo */
59 
60 /*
61  * Error status
62  */
63 enum nfsstat {
64 	NFS_OK= 0,		/* no error */
65 	NFSERR_PERM=1,		/* Not owner */
66 	NFSERR_NOENT=2,		/* No such file or directory */
67 	NFSERR_IO=5,		/* I/O error */
68 	NFSERR_NXIO=6,		/* No such device or address */
69 	NFSERR_ACCES=13,	/* Permission denied */
70 	NFSERR_EXIST=17,	/* File exists */
71 	NFSERR_NODEV=19,	/* No such device */
72 	NFSERR_NOTDIR=20,	/* Not a directory*/
73 	NFSERR_ISDIR=21,	/* Is a directory */
74 	NFSERR_FBIG=27,		/* File too large */
75 	NFSERR_NOSPC=28,	/* No space left on device */
76 	NFSERR_ROFS=30,		/* Read-only file system */
77 	NFSERR_NAMETOOLONG=63,	/* File name too long */
78 	NFSERR_NOTEMPTY=66,	/* Directory not empty */
79 	NFSERR_DQUOT=69,	/* Disc quota exceeded */
80 	NFSERR_STALE=70,	/* Stale NFS file handle */
81 	NFSERR_WFLUSH=99	/* write cache flushed */
82 };
83 
84 /*
85  * File types
86  */
87 enum ftype {
88 	NFNON = 0,	/* non-file */
89 	NFREG = 1,	/* regular file */
90 	NFDIR = 2,	/* directory */
91 	NFBLK = 3,	/* block special */
92 	NFCHR = 4,	/* character special */
93 	NFLNK = 5,	/* symbolic link */
94 	NFSOCK = 6,	/* unix domain sockets */
95 	NFBAD = 7,	/* unused */
96 	NFFIFO = 8	/* named pipe */
97 };
98 
99 /*
100  * File access handle
101  */
102 struct nfs_fh {
103 	opaque data[NFS_FHSIZE];
104 };
105 
106 /*
107  * Timeval
108  */
109 struct nfstime {
110 	unsigned seconds;
111 	unsigned useconds;
112 };
113 
114 
115 /*
116  * File attributes
117  */
118 struct fattr {
119 	ftype type;		/* file type */
120 	unsigned mode;		/* protection mode bits */
121 	unsigned nlink;		/* # hard links */
122 	unsigned uid;		/* owner user id */
123 	unsigned gid;		/* owner group id */
124 	unsigned size;		/* file size in bytes */
125 	unsigned blocksize;	/* prefered block size */
126 	unsigned rdev;		/* special device # */
127 	unsigned blocks;	/* Kb of disk used by file */
128 	unsigned fsid;		/* device # */
129 	unsigned fileid;	/* inode # */
130 	nfstime	atime;		/* time of last access */
131 	nfstime	mtime;		/* time of last modification */
132 	nfstime	ctime;		/* time of last change */
133 };
134 
135 /*
136  * File attributes which can be set
137  */
138 struct sattr {
139 	unsigned mode;	/* protection mode bits */
140 	unsigned uid;	/* owner user id */
141 	unsigned gid;	/* owner group id */
142 	unsigned size;	/* file size in bytes */
143 	nfstime	atime;	/* time of last access */
144 	nfstime	mtime;	/* time of last modification */
145 };
146 
147 
148 typedef string filename<NFS_MAXNAMLEN>;
149 typedef string nfspath<NFS_MAXPATHLEN>;
150 
151 /*
152  * Reply status with file attributes
153  */
154 union attrstat switch (nfsstat status) {
155 case NFS_OK:
156 	fattr attributes;
157 default:
158 	void;
159 };
160 
161 struct sattrargs {
162 	nfs_fh file;
163 	sattr attributes;
164 };
165 
166 /*
167  * Arguments for directory operations
168  */
169 struct diropargs {
170 	nfs_fh	dir;	/* directory file handle */
171 	filename name;		/* name (up to NFS_MAXNAMLEN bytes) */
172 };
173 
174 struct diropokres {
175 	nfs_fh file;
176 	fattr attributes;
177 };
178 
179 /*
180  * Results from directory operation
181  */
182 union diropres switch (nfsstat status) {
183 case NFS_OK:
184 	diropokres diropres;
185 default:
186 	void;
187 };
188 
189 union readlinkres switch (nfsstat status) {
190 case NFS_OK:
191 	nfspath data;
192 default:
193 	void;
194 };
195 
196 /*
197  * Arguments to remote read
198  */
199 struct readargs {
200 	nfs_fh file;		/* handle for file */
201 	unsigned offset;	/* byte offset in file */
202 	unsigned count;		/* immediate read count */
203 	unsigned totalcount;	/* total read count (from this offset)*/
204 };
205 
206 /*
207  * Status OK portion of remote read reply
208  */
209 struct readokres {
210 	fattr	attributes;	/* attributes, need for pagin*/
211 	opaque data<NFS_MAXDATA>;
212 };
213 
214 union readres switch (nfsstat status) {
215 case NFS_OK:
216 	readokres reply;
217 default:
218 	void;
219 };
220 
221 /*
222  * Arguments to remote write
223  */
224 struct writeargs {
225 	nfs_fh	file;		/* handle for file */
226 	unsigned beginoffset;	/* beginning byte offset in file */
227 	unsigned offset;	/* current byte offset in file */
228 	unsigned totalcount;	/* total write count (to this offset)*/
229 	opaque data<NFS_MAXDATA>;
230 };
231 
232 struct createargs {
233 	diropargs where;
234 	sattr attributes;
235 };
236 
237 struct renameargs {
238 	diropargs from;
239 	diropargs to;
240 };
241 
242 struct linkargs {
243 	nfs_fh from;
244 	diropargs to;
245 };
246 
247 struct symlinkargs {
248 	diropargs from;
249 	nfspath to;
250 	sattr attributes;
251 };
252 
253 
254 typedef opaque nfscookie[NFS_COOKIESIZE];
255 
256 /*
257  * Arguments to readdir
258  */
259 struct readdirargs {
260 	nfs_fh dir;		/* directory handle */
261 	nfscookie cookie;
262 	unsigned count;		/* number of directory bytes to read */
263 };
264 
265 struct entry {
266 	unsigned fileid;
267 	filename name;
268 	nfscookie cookie;
269 	entry *nextentry;
270 };
271 
272 struct dirlist {
273 	entry *entries;
274 	bool eof;
275 };
276 
277 union readdirres switch (nfsstat status) {
278 case NFS_OK:
279 	dirlist reply;
280 default:
281 	void;
282 };
283 
284 struct statfsokres {
285 	unsigned tsize;	/* preferred transfer size in bytes */
286 	unsigned bsize;	/* fundamental file system block size */
287 	unsigned blocks;	/* total blocks in file system */
288 	unsigned bfree;	/* free blocks in fs */
289 	unsigned bavail;	/* free blocks avail to non-superuser */
290 };
291 
292 union statfsres switch (nfsstat status) {
293 case NFS_OK:
294 	statfsokres reply;
295 default:
296 	void;
297 };
298 
299 /*
300  * Remote file service routines
301  */
302 program NFS_PROGRAM {
303 	version NFS_VERSION {
304 		void
305 		NFSPROC_NULL(void) = 0;
306 
307 		attrstat
308 		NFSPROC_GETATTR(nfs_fh) =	1;
309 
310 		attrstat
311 		NFSPROC_SETATTR(sattrargs) = 2;
312 
313 		void
314 		NFSPROC_ROOT(void) = 3;
315 
316 		diropres
317 		NFSPROC_LOOKUP(diropargs) = 4;
318 
319 		readlinkres
320 		NFSPROC_READLINK(nfs_fh) = 5;
321 
322 		readres
323 		NFSPROC_READ(readargs) = 6;
324 
325 		void
326 		NFSPROC_WRITECACHE(void) = 7;
327 
328 		attrstat
329 		NFSPROC_WRITE(writeargs) = 8;
330 
331 		diropres
332 		NFSPROC_CREATE(createargs) = 9;
333 
334 		nfsstat
335 		NFSPROC_REMOVE(diropargs) = 10;
336 
337 		nfsstat
338 		NFSPROC_RENAME(renameargs) = 11;
339 
340 		nfsstat
341 		NFSPROC_LINK(linkargs) = 12;
342 
343 		nfsstat
344 		NFSPROC_SYMLINK(symlinkargs) = 13;
345 
346 		diropres
347 		NFSPROC_MKDIR(createargs) = 14;
348 
349 		nfsstat
350 		NFSPROC_RMDIR(diropargs) = 15;
351 
352 		readdirres
353 		NFSPROC_READDIR(readdirargs) = 16;
354 
355 		statfsres
356 		NFSPROC_STATFS(nfs_fh) = 17;
357 	} = 2;
358 } = 100003;
359 
360