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