2 * Copyright (c) 2010, Oracle America, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of the "Oracle America, Inc." nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 %#endif /* not lint */
37 %#include <sys/cdefs.h>
38 %__FBSDID("$FreeBSD$");
41 const NFS_PORT = 2049;
42 const NFS_MAXDATA = 8192;
43 const NFS_MAXPATHLEN = 1024;
44 const NFS_MAXNAMLEN = 255;
45 const NFS_FHSIZE = 32;
46 const NFS_COOKIESIZE = 4;
47 const NFS_FIFO_DEV = -1; /* size kludge for named pipes */
52 const NFSMODE_FMT = 0170000; /* type of file */
53 const NFSMODE_DIR = 0040000; /* directory */
54 const NFSMODE_CHR = 0020000; /* character special */
55 const NFSMODE_BLK = 0060000; /* block special */
56 const NFSMODE_REG = 0100000; /* regular */
57 const NFSMODE_LNK = 0120000; /* symbolic link */
58 const NFSMODE_SOCK = 0140000; /* socket */
59 const NFSMODE_FIFO = 0010000; /* fifo */
65 NFS_OK= 0, /* no error */
66 NFSERR_PERM=1, /* Not owner */
67 NFSERR_NOENT=2, /* No such file or directory */
68 NFSERR_IO=5, /* I/O error */
69 NFSERR_NXIO=6, /* No such device or address */
70 NFSERR_ACCES=13, /* Permission denied */
71 NFSERR_EXIST=17, /* File exists */
72 NFSERR_NODEV=19, /* No such device */
73 NFSERR_NOTDIR=20, /* Not a directory*/
74 NFSERR_ISDIR=21, /* Is a directory */
75 NFSERR_FBIG=27, /* File too large */
76 NFSERR_NOSPC=28, /* No space left on device */
77 NFSERR_ROFS=30, /* Read-only file system */
78 NFSERR_NAMETOOLONG=63, /* File name too long */
79 NFSERR_NOTEMPTY=66, /* Directory not empty */
80 NFSERR_DQUOT=69, /* Disc quota exceeded */
81 NFSERR_STALE=70, /* Stale NFS file handle */
82 NFSERR_WFLUSH=99 /* write cache flushed */
89 NFNON = 0, /* non-file */
90 NFREG = 1, /* regular file */
91 NFDIR = 2, /* directory */
92 NFBLK = 3, /* block special */
93 NFCHR = 4, /* character special */
94 NFLNK = 5, /* symbolic link */
95 NFSOCK = 6, /* unix domain sockets */
96 NFBAD = 7, /* unused */
97 NFFIFO = 8 /* named pipe */
104 opaque data[NFS_FHSIZE];
120 ftype type; /* file type */
121 unsigned mode; /* protection mode bits */
122 unsigned nlink; /* # hard links */
123 unsigned uid; /* owner user id */
124 unsigned gid; /* owner group id */
125 unsigned size; /* file size in bytes */
126 unsigned blocksize; /* preferred block size */
127 unsigned rdev; /* special device # */
128 unsigned blocks; /* Kb of disk used by file */
129 unsigned fsid; /* device # */
130 unsigned fileid; /* inode # */
131 nfstime atime; /* time of last access */
132 nfstime mtime; /* time of last modification */
133 nfstime ctime; /* time of last change */
137 * File attributes which can be set
140 unsigned mode; /* protection mode bits */
141 unsigned uid; /* owner user id */
142 unsigned gid; /* owner group id */
143 unsigned size; /* file size in bytes */
144 nfstime atime; /* time of last access */
145 nfstime mtime; /* time of last modification */
149 typedef string filename<NFS_MAXNAMLEN>;
150 typedef string nfspath<NFS_MAXPATHLEN>;
153 * Reply status with file attributes
155 union attrstat switch (nfsstat status) {
168 * Arguments for directory operations
171 nfs_fh dir; /* directory file handle */
172 filename name; /* name (up to NFS_MAXNAMLEN bytes) */
181 * Results from directory operation
183 union diropres switch (nfsstat status) {
190 union readlinkres switch (nfsstat status) {
198 * Arguments to remote read
201 nfs_fh file; /* handle for file */
202 unsigned offset; /* byte offset in file */
203 unsigned count; /* immediate read count */
204 unsigned totalcount; /* total read count (from this offset)*/
208 * Status OK portion of remote read reply
211 fattr attributes; /* attributes, need for pagin*/
212 opaque data<NFS_MAXDATA>;
215 union readres switch (nfsstat status) {
223 * Arguments to remote write
226 nfs_fh file; /* handle for file */
227 unsigned beginoffset; /* beginning byte offset in file */
228 unsigned offset; /* current byte offset in file */
229 unsigned totalcount; /* total write count (to this offset)*/
230 opaque data<NFS_MAXDATA>;
255 typedef opaque nfscookie[NFS_COOKIESIZE];
258 * Arguments to readdir
261 nfs_fh dir; /* directory handle */
263 unsigned count; /* number of directory bytes to read */
278 union readdirres switch (nfsstat status) {
286 unsigned tsize; /* preferred transfer size in bytes */
287 unsigned bsize; /* fundamental file system block size */
288 unsigned blocks; /* total blocks in file system */
289 unsigned bfree; /* free blocks in fs */
290 unsigned bavail; /* free blocks avail to non-superuser */
293 union statfsres switch (nfsstat status) {
303 * NFSv3 constants and types
305 const NFS3_FHSIZE = 64; /* maximum size in bytes of a file handle */
306 const NFS3_COOKIEVERFSIZE = 8; /* size of a cookie verifier for READDIR */
307 const NFS3_CREATEVERFSIZE = 8; /* size of the verifier used for CREATE */
308 const NFS3_WRITEVERFSIZE = 8; /* size of the verifier used for WRITE */
310 typedef unsigned hyper uint64;
312 typedef unsigned long uint32;
314 typedef string filename3<>;
315 typedef string nfspath3<>;
316 typedef uint64 fileid3;
317 typedef uint64 cookie3;
318 typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
319 typedef opaque createverf3[NFS3_CREATEVERFSIZE];
320 typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
323 typedef uint64 size3;
324 typedef uint64 offset3;
325 typedef uint32 mode3;
326 typedef uint32 count3;
348 NFS3ERR_NAMETOOLONG = 63,
349 NFS3ERR_NOTEMPTY = 66,
353 NFS3ERR_BADHANDLE = 10001,
354 NFS3ERR_NOT_SYNC = 10002,
355 NFS3ERR_BAD_COOKIE = 10003,
356 NFS3ERR_NOTSUPP = 10004,
357 NFS3ERR_TOOSMALL = 10005,
358 NFS3ERR_SERVERFAULT = 10006,
359 NFS3ERR_BADTYPE = 10007,
360 NFS3ERR_JUKEBOX = 10008
367 NF3REG = 1, /* regular file */
368 NF3DIR = 2, /* directory */
369 NF3BLK = 3, /* block special */
370 NF3CHR = 4, /* character special */
371 NF3LNK = 5, /* symbolic link */
372 NF3SOCK = 6, /* unix domain sockets */
373 NF3FIFO = 7 /* named pipe */
382 * File access handle (v3)
385 opaque data<NFS3_FHSIZE>;
398 * File attributes (v3)
401 ftype3 type; /* file type */
402 mode3 mode; /* protection mode bits */
403 uint32 nlink; /* # hard links */
404 uid3 uid; /* owner user id */
405 gid3 gid; /* owner group id */
406 size3 size; /* file size in bytes */
407 size3 used; /* preferred block size */
408 specdata3 rdev; /* special device # */
409 uint64 fsid; /* device # */
410 fileid3 fileid; /* inode # */
411 nfstime3 atime; /* time of last access */
412 nfstime3 mtime; /* time of last modification */
413 nfstime3 ctime; /* time of last change */
416 union post_op_attr switch (bool attributes_follow) {
429 union pre_op_attr switch (bool attributes_follow) {
441 union post_op_fh3 switch (bool handle_follows) {
449 * File attributes which can be set (v3)
453 SET_TO_SERVER_TIME = 1,
454 SET_TO_CLIENT_TIME = 2
457 union set_mode3 switch (bool set_it) {
464 union set_uid3 switch (bool set_it) {
471 union set_gid3 switch (bool set_it) {
478 union set_size3 switch (bool set_it) {
485 union set_atime switch (time_how set_it) {
486 case SET_TO_CLIENT_TIME:
492 union set_mtime switch (time_how set_it) {
493 case SET_TO_CLIENT_TIME:
509 * Arguments for directory operations (v3)
512 nfs_fh3 dir; /* directory file handle */
513 filename3 name; /* name (up to NFS_MAXNAMLEN bytes) */
517 * Arguments to getattr (v3).
519 struct GETATTR3args {
523 struct GETATTR3resok {
524 fattr3 obj_attributes;
527 union GETATTR3res switch (nfsstat3 status) {
535 * Arguments to setattr (v3).
537 union sattrguard3 switch (bool check) {
544 struct SETATTR3args {
546 sattr3 new_attributes;
550 struct SETATTR3resok {
554 struct SETATTR3resfail {
558 union SETATTR3res switch (nfsstat3 status) {
562 SETATTR3resfail resfail;
566 * Arguments to lookup (v3).
572 struct LOOKUP3resok {
574 post_op_attr obj_attributes;
575 post_op_attr dir_attributes;
578 struct LOOKUP3resfail {
579 post_op_attr dir_attributes;
582 union LOOKUP3res switch (nfsstat3 status) {
586 LOOKUP3resfail resfail;
590 * Arguments to access (v3).
592 const ACCESS3_READ = 0x0001;
593 const ACCESS3_LOOKUP = 0x0002;
594 const ACCESS3_MODIFY = 0x0004;
595 const ACCESS3_EXTEND = 0x0008;
596 const ACCESS3_DELETE = 0x0010;
597 const ACCESS3_EXECUTE = 0x0020;
604 struct ACCESS3resok {
605 post_op_attr obj_attributes;
609 struct ACCESS3resfail {
610 post_op_attr obj_attributes;
613 union ACCESS3res switch (nfsstat3 status) {
617 ACCESS3resfail resfail;
621 * Arguments to readlink (v3).
623 struct READLINK3args {
627 struct READLINK3resok {
628 post_op_attr symlink_attributes;
632 struct READLINK3resfail {
633 post_op_attr symlink_attributes;
636 union READLINK3res switch (nfsstat3 status) {
638 READLINK3resok resok;
640 READLINK3resfail resfail;
644 * Arguments to read (v3).
653 post_op_attr file_attributes;
659 struct READ3resfail {
660 post_op_attr file_attributes;
663 /* XXX: solaris 2.6 uses ``nfsstat'' here */
664 union READ3res switch (nfsstat3 status) {
668 READ3resfail resfail;
672 * Arguments to write (v3).
691 stable_how committed;
695 struct WRITE3resfail {
699 union WRITE3res switch (nfsstat3 status) {
703 WRITE3resfail resfail;
707 * Arguments to create (v3).
715 union createhow3 switch (createmode3 mode) {
718 sattr3 obj_attributes;
728 struct CREATE3resok {
730 post_op_attr obj_attributes;
734 struct CREATE3resfail {
738 union CREATE3res switch (nfsstat3 status) {
742 CREATE3resfail resfail;
746 * Arguments to mkdir (v3).
755 post_op_attr obj_attributes;
759 struct MKDIR3resfail {
763 union MKDIR3res switch (nfsstat3 status) {
767 MKDIR3resfail resfail;
771 * Arguments to symlink (v3).
773 struct symlinkdata3 {
774 sattr3 symlink_attributes;
775 nfspath3 symlink_data;
778 struct SYMLINK3args {
780 symlinkdata3 symlink;
783 struct SYMLINK3resok {
785 post_op_attr obj_attributes;
789 struct SYMLINK3resfail {
793 union SYMLINK3res switch (nfsstat3 status) {
797 SYMLINK3resfail resfail;
801 * Arguments to mknod (v3).
804 sattr3 dev_attributes;
808 union mknoddata3 switch (ftype3 type) {
814 sattr3 pipe_attributes;
826 post_op_attr obj_attributes;
830 struct MKNOD3resfail {
834 union MKNOD3res switch (nfsstat3 status) {
838 MKNOD3resfail resfail;
842 * Arguments to remove (v3).
848 struct REMOVE3resok {
852 struct REMOVE3resfail {
856 union REMOVE3res switch (nfsstat3 status) {
860 REMOVE3resfail resfail;
864 * Arguments to rmdir (v3).
874 struct RMDIR3resfail {
878 union RMDIR3res switch (nfsstat3 status) {
882 RMDIR3resfail resfail;
886 * Arguments to rename (v3).
893 struct RENAME3resok {
894 wcc_data fromdir_wcc;
898 struct RENAME3resfail {
899 wcc_data fromdir_wcc;
903 union RENAME3res switch (nfsstat3 status) {
907 RENAME3resfail resfail;
911 * Arguments to link (v3).
919 post_op_attr file_attributes;
920 wcc_data linkdir_wcc;
923 struct LINK3resfail {
924 post_op_attr file_attributes;
925 wcc_data linkdir_wcc;
928 union LINK3res switch (nfsstat3 status) {
932 LINK3resfail resfail;
936 * Arguments to readdir (v3).
938 struct READDIR3args {
941 cookieverf3 cookieverf;
957 struct READDIR3resok {
958 post_op_attr dir_attributes;
959 cookieverf3 cookieverf;
963 struct READDIR3resfail {
964 post_op_attr dir_attributes;
967 union READDIR3res switch (nfsstat3 status) {
971 READDIR3resfail resfail;
975 * Arguments to readdirplus (v3).
977 struct READDIRPLUS3args {
980 cookieverf3 cookieverf;
989 post_op_attr name_attributes;
990 post_op_fh3 name_handle;
991 entryplus3 *nextentry;
994 struct dirlistplus3 {
999 struct READDIRPLUS3resok {
1000 post_op_attr dir_attributes;
1001 cookieverf3 cookieverf;
1005 struct READDIRPLUS3resfail {
1006 post_op_attr dir_attributes;
1009 union READDIRPLUS3res switch (nfsstat3 status) {
1011 READDIRPLUS3resok resok;
1013 READDIRPLUS3resfail resfail;
1017 * Arguments to fsstat (v3).
1019 struct FSSTAT3args {
1023 struct FSSTAT3resok {
1024 post_op_attr obj_attributes;
1034 struct FSSTAT3resfail {
1035 post_op_attr obj_attributes;
1038 union FSSTAT3res switch (nfsstat3 status) {
1042 FSSTAT3resfail resfail;
1046 * Arguments to fsinfo (v3).
1048 const FSF3_LINK = 0x0001;
1049 const FSF3_SYMLINK = 0x0002;
1050 const FSF3_HOMOGENEOUS = 0x0008;
1051 const FSF3_CANSETTIME = 0x0010;
1053 struct FSINFO3args {
1057 struct FSINFO3resok {
1058 post_op_attr obj_attributes;
1067 nfstime3 time_delta;
1071 struct FSINFO3resfail {
1072 post_op_attr obj_attributes;
1075 union FSINFO3res switch (nfsstat3 status) {
1079 FSINFO3resfail resfail;
1083 * Arguments to pathconf (v3).
1085 struct PATHCONF3args {
1089 struct PATHCONF3resok {
1090 post_op_attr obj_attributes;
1094 bool chown_restricted;
1095 bool case_insensitive;
1096 bool case_preserving;
1099 struct PATHCONF3resfail {
1100 post_op_attr obj_attributes;
1103 union PATHCONF3res switch (nfsstat3 status) {
1105 PATHCONF3resok resok;
1107 PATHCONF3resfail resfail;
1111 * Arguments to commit (v3).
1113 struct COMMIT3args {
1119 struct COMMIT3resok {
1124 struct COMMIT3resfail {
1128 union COMMIT3res switch (nfsstat3 status) {
1132 COMMIT3resfail resfail;
1135 #endif /* WANT_NFS3 */
1138 * Remote file service routines
1140 program NFS_PROGRAM {
1141 version NFS_VERSION {
1143 NFSPROC_NULL(void) = 0;
1146 NFSPROC_GETATTR(nfs_fh) = 1;
1149 NFSPROC_SETATTR(sattrargs) = 2;
1152 NFSPROC_ROOT(void) = 3;
1155 NFSPROC_LOOKUP(diropargs) = 4;
1158 NFSPROC_READLINK(nfs_fh) = 5;
1161 NFSPROC_READ(readargs) = 6;
1164 NFSPROC_WRITECACHE(void) = 7;
1167 NFSPROC_WRITE(writeargs) = 8;
1170 NFSPROC_CREATE(createargs) = 9;
1173 NFSPROC_REMOVE(diropargs) = 10;
1176 NFSPROC_RENAME(renameargs) = 11;
1179 NFSPROC_LINK(linkargs) = 12;
1182 NFSPROC_SYMLINK(symlinkargs) = 13;
1185 NFSPROC_MKDIR(createargs) = 14;
1188 NFSPROC_RMDIR(diropargs) = 15;
1191 NFSPROC_READDIR(readdirargs) = 16;
1194 NFSPROC_STATFS(nfs_fh) = 17;
1198 program NFS3_PROGRAM {
1201 NFSPROC3_NULL(void) = 0;
1204 NFSPROC3_GETATTR(GETATTR3args) = 1;
1207 NFSPROC3_SETATTR(SETATTR3args) = 2;
1210 NFSPROC3_LOOKUP(LOOKUP3args) = 3;
1213 NFSPROC3_ACCESS(ACCESS3args) = 4;
1216 NFSPROC3_READLINK(READLINK3args) = 5;
1219 NFSPROC3_READ(READ3args) = 6;
1222 NFSPROC3_WRITE(WRITE3args) = 7;
1225 NFSPROC3_CREATE(CREATE3args) = 8;
1228 NFSPROC3_MKDIR(MKDIR3args) = 9;
1231 NFSPROC3_SYMLINK(SYMLINK3args) = 10;
1234 NFSPROC3_MKNOD(MKNOD3args) = 11;
1237 NFSPROC3_REMOVE(REMOVE3args) = 12;
1240 NFSPROC3_RMDIR(RMDIR3args) = 13;
1243 NFSPROC3_RENAME(RENAME3args) = 14;
1246 NFSPROC3_LINK(LINK3args) = 15;
1249 NFSPROC3_READDIR(READDIR3args) = 16;
1252 NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17;
1255 NFSPROC3_FSSTAT(FSSTAT3args) = 18;
1258 NFSPROC3_FSINFO(FSINFO3args) = 19;
1261 NFSPROC3_PATHCONF(PATHCONF3args) = 20;
1264 NFSPROC3_COMMIT(COMMIT3args) = 21;