4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 %#pragma ident "%Z%%M% %I% %E% SMI"
32 % * Definitions for uint64, int64, uint32, and int32
34 %#include <rpc/rpc_sztypes.h>
38 const NFS_PORT = 2049;
39 const NFS_MAXDATA = 8192;
40 const NFS_MAXPATHLEN = 1024;
41 const NFS_MAXNAMLEN = 255;
42 const NFS_FHSIZE = 32;
43 const NFS_COOKIESIZE = 4;
44 const NFS_FIFO_DEV = -1; /* size kludge for named pipes */
49 const NFSMODE_FMT = 0170000; /* type of file */
50 const NFSMODE_DIR = 0040000; /* directory */
51 const NFSMODE_CHR = 0020000; /* character special */
52 const NFSMODE_BLK = 0060000; /* block special */
53 const NFSMODE_REG = 0100000; /* regular */
54 const NFSMODE_LNK = 0120000; /* symbolic link */
55 const NFSMODE_SOCK = 0140000; /* socket */
56 const NFSMODE_FIFO = 0010000; /* fifo */
62 NFS_OK= 0, /* no error */
63 NFSERR_PERM=1, /* Not owner */
64 NFSERR_NOENT=2, /* No such file or directory */
65 NFSERR_IO=5, /* I/O error */
66 NFSERR_NXIO=6, /* No such device or address */
67 NFSERR_ACCES=13, /* Permission denied */
68 NFSERR_EXIST=17, /* File exists */
69 NFSERR_XDEV=18, /* Cross-device link */
70 NFSERR_NODEV=19, /* No such device */
71 NFSERR_NOTDIR=20, /* Not a directory*/
72 NFSERR_ISDIR=21, /* Is a directory */
73 NFSERR_INVAL=22, /* Invalid argument */
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_OPNOTSUPP=45, /* Operation not supported */
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_REMOTE=71, /* Object is remote */
83 NFSERR_WFLUSH=72 /* write cache flushed */
90 NFNON = 0, /* non-file */
91 NFREG = 1, /* regular file */
92 NFDIR = 2, /* directory */
93 NFBLK = 3, /* block special */
94 NFCHR = 4, /* character special */
95 NFLNK = 5, /* symbolic link */
96 NFSOCK = 6, /* unix domain sockets */
97 NFBAD = 7, /* unused */
98 NFFIFO = 8 /* named pipe */
105 opaque data[NFS_FHSIZE];
121 ftype type; /* file type */
122 unsigned mode; /* protection mode bits */
123 unsigned nlink; /* # hard links */
124 unsigned uid; /* owner user id */
125 unsigned gid; /* owner group id */
126 unsigned size; /* file size in bytes */
127 unsigned blocksize; /* prefered block size */
128 unsigned rdev; /* special device # */
129 unsigned blocks; /* Kb of disk used by file */
130 unsigned fsid; /* device # */
131 unsigned fileid; /* inode # */
132 nfstime atime; /* time of last access */
133 nfstime mtime; /* time of last modification */
134 nfstime ctime; /* time of last change */
138 * File attributes which can be set
141 unsigned mode; /* protection mode bits */
142 unsigned uid; /* owner user id */
143 unsigned gid; /* owner group id */
144 unsigned size; /* file size in bytes */
145 nfstime atime; /* time of last access */
146 nfstime mtime; /* time of last modification */
150 typedef string filename<NFS_MAXNAMLEN>;
151 typedef string nfspath<NFS_MAXPATHLEN>;
154 * Reply status with file attributes
156 union attrstat switch (nfsstat status) {
169 * Arguments for directory operations
172 nfs_fh dir; /* directory file handle */
173 filename name; /* name (up to NFS_MAXNAMLEN bytes) */
182 * Results from directory operation
184 union diropres switch (nfsstat status) {
191 union readlinkres switch (nfsstat status) {
199 * Arguments to remote read
202 nfs_fh file; /* handle for file */
203 unsigned offset; /* byte offset in file */
204 unsigned count; /* immediate read count */
205 unsigned totalcount; /* total read count (from this offset)*/
209 * Status OK portion of remote read reply
212 fattr attributes; /* attributes, need for pagin*/
213 opaque data<NFS_MAXDATA>;
216 union readres switch (nfsstat status) {
224 * Arguments to remote write
227 nfs_fh file; /* handle for file */
228 unsigned beginoffset; /* beginning byte offset in file */
229 unsigned offset; /* current byte offset in file */
230 unsigned totalcount; /* total write count (to this offset)*/
231 opaque data<NFS_MAXDATA>;
256 typedef opaque nfscookie[NFS_COOKIESIZE];
259 * Arguments to readdir
262 nfs_fh dir; /* directory handle */
264 unsigned count; /* number of directory bytes to read */
279 union readdirres switch (nfsstat status) {
287 unsigned tsize; /* preferred transfer size in bytes */
288 unsigned bsize; /* fundamental file system block size */
289 unsigned blocks; /* total blocks in file system */
290 unsigned bfree; /* free blocks in fs */
291 unsigned bavail; /* free blocks avail to non-superuser */
294 union statfsres switch (nfsstat status) {
302 * Remote file service routines
304 program NFS_PROGRAM {
305 version NFS_VERSION {
307 NFSPROC_NULL(void) = 0;
310 NFSPROC_GETATTR(nfs_fh) = 1;
313 NFSPROC_SETATTR(sattrargs) = 2;
316 NFSPROC_ROOT(void) = 3;
319 NFSPROC_LOOKUP(diropargs) = 4;
322 NFSPROC_READLINK(nfs_fh) = 5;
325 NFSPROC_READ(readargs) = 6;
328 NFSPROC_WRITECACHE(void) = 7;
331 NFSPROC_WRITE(writeargs) = 8;
334 NFSPROC_CREATE(createargs) = 9;
337 NFSPROC_REMOVE(diropargs) = 10;
340 NFSPROC_RENAME(renameargs) = 11;
343 NFSPROC_LINK(linkargs) = 12;
346 NFSPROC_SYMLINK(symlinkargs) = 13;
349 NFSPROC_MKDIR(createargs) = 14;
352 NFSPROC_RMDIR(diropargs) = 15;
355 NFSPROC_READDIR(readdirargs) = 16;
358 NFSPROC_STATFS(nfs_fh) = 17;
363 * Version 3 declarations and definitions.
369 const NFS3_FHSIZE = 64;
370 const NFS3_COOKIEVERFSIZE = 8;
371 const NFS3_CREATEVERFSIZE = 8;
372 const NFS3_WRITEVERFSIZE = 8;
377 typedef string filename3<>;
378 typedef string nfspath3<>;
379 typedef uint64 fileid3;
380 typedef uint64 cookie3;
381 typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
382 typedef opaque createverf3[NFS3_CREATEVERFSIZE];
383 typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
386 typedef uint64 size3;
387 typedef uint64 offset3;
388 typedef uint32 mode3;
389 typedef uint32 count3;
411 NFS3ERR_NAMETOOLONG = 63,
412 NFS3ERR_NOTEMPTY = 66,
416 NFS3ERR_BADHANDLE = 10001,
417 NFS3ERR_NOT_SYNC = 10002,
418 NFS3ERR_BAD_COOKIE = 10003,
419 NFS3ERR_NOTSUPP = 10004,
420 NFS3ERR_TOOSMALL = 10005,
421 NFS3ERR_SERVERFAULT = 10006,
422 NFS3ERR_BADTYPE = 10007,
423 NFS3ERR_JUKEBOX = 10008
448 opaque data<NFS3_FHSIZE>;
481 union post_op_attr switch (bool attributes_follow) {
494 union pre_op_attr switch (bool attributes_follow) {
506 union post_op_fh3 switch (bool handle_follows) {
515 SET_TO_SERVER_TIME = 1,
516 SET_TO_CLIENT_TIME = 2
519 union set_mode3 switch (bool set_it) {
526 union set_uid3 switch (bool set_it) {
533 union set_gid3 switch (bool set_it) {
540 union set_size3 switch (bool set_it) {
547 union set_atime switch (time_how set_it) {
548 case SET_TO_CLIENT_TIME:
554 union set_mtime switch (time_how set_it) {
555 case SET_TO_CLIENT_TIME:
576 * GETATTR: Get file attributes
578 struct GETATTR3args {
582 struct GETATTR3resok {
583 fattr3 obj_attributes;
586 union GETATTR3res switch (nfsstat3 status) {
594 * SETATTR: Set file attributes
596 union sattrguard3 switch (bool check) {
603 struct SETATTR3args {
605 sattr3 new_attributes;
609 struct SETATTR3resok {
613 struct SETATTR3resfail {
617 union SETATTR3res switch (nfsstat3 status) {
621 SETATTR3resfail resfail;
625 * LOOKUP: Lookup filename
631 struct LOOKUP3resok {
633 post_op_attr obj_attributes;
634 post_op_attr dir_attributes;
637 struct LOOKUP3resfail {
638 post_op_attr dir_attributes;
641 union LOOKUP3res switch (nfsstat3 status) {
645 LOOKUP3resfail resfail;
649 * ACCESS: Check access permission
651 const ACCESS3_READ = 0x0001;
652 const ACCESS3_LOOKUP = 0x0002;
653 const ACCESS3_MODIFY = 0x0004;
654 const ACCESS3_EXTEND = 0x0008;
655 const ACCESS3_DELETE = 0x0010;
656 const ACCESS3_EXECUTE = 0x0020;
663 struct ACCESS3resok {
664 post_op_attr obj_attributes;
668 struct ACCESS3resfail {
669 post_op_attr obj_attributes;
672 union ACCESS3res switch (nfsstat3 status) {
676 ACCESS3resfail resfail;
680 * READLINK: Read from symbolic link
682 struct READLINK3args {
686 struct READLINK3resok {
687 post_op_attr symlink_attributes;
691 struct READLINK3resfail {
692 post_op_attr symlink_attributes;
695 union READLINK3res switch (nfsstat3 status) {
697 READLINK3resok resok;
699 READLINK3resfail resfail;
703 * READ: Read from file
712 post_op_attr file_attributes;
718 struct READ3resfail {
719 post_op_attr file_attributes;
722 union READ3res switch (nfsstat3 status) {
726 READ3resfail resfail;
730 * WRITE: Write to file
749 stable_how committed;
753 struct WRITE3resfail {
757 union WRITE3res switch (nfsstat3 status) {
761 WRITE3resfail resfail;
765 * CREATE: Create a file
773 union createhow3 switch (createmode3 mode) {
776 sattr3 obj_attributes;
786 struct CREATE3resok {
788 post_op_attr obj_attributes;
792 struct CREATE3resfail {
796 union CREATE3res switch (nfsstat3 status) {
800 CREATE3resfail resfail;
804 * MKDIR: Create a directory
813 post_op_attr obj_attributes;
817 struct MKDIR3resfail {
821 union MKDIR3res switch (nfsstat3 status) {
825 MKDIR3resfail resfail;
829 * SYMLINK: Create a symbolic link
831 struct symlinkdata3 {
832 sattr3 symlink_attributes;
833 nfspath3 symlink_data;
836 struct SYMLINK3args {
838 symlinkdata3 symlink;
841 struct SYMLINK3resok {
843 post_op_attr obj_attributes;
847 struct SYMLINK3resfail {
851 union SYMLINK3res switch (nfsstat3 status) {
855 SYMLINK3resfail resfail;
859 * MKNOD: Create a special file
862 sattr3 dev_attributes;
866 union mknoddata3 switch (ftype3 type) {
872 sattr3 pipe_attributes;
884 post_op_attr obj_attributes;
888 struct MKNOD3resfail {
892 union MKNOD3res switch (nfsstat3 status) {
896 MKNOD3resfail resfail;
900 * REMOVE: Remove a file
906 struct REMOVE3resok {
910 struct REMOVE3resfail {
914 union REMOVE3res switch (nfsstat3 status) {
918 REMOVE3resfail resfail;
922 * RMDIR: Remove a directory
932 struct RMDIR3resfail {
936 union RMDIR3res switch (nfsstat3 status) {
940 RMDIR3resfail resfail;
944 * RENAME: Rename a file or directory
951 struct RENAME3resok {
952 wcc_data fromdir_wcc;
956 struct RENAME3resfail {
957 wcc_data fromdir_wcc;
961 union RENAME3res switch (nfsstat3 status) {
965 RENAME3resfail resfail;
969 * LINK: Create link to an object
977 post_op_attr file_attributes;
978 wcc_data linkdir_wcc;
981 struct LINK3resfail {
982 post_op_attr file_attributes;
983 wcc_data linkdir_wcc;
986 union LINK3res switch (nfsstat3 status) {
990 LINK3resfail resfail;
994 * READDIR: Read from directory
996 struct READDIR3args {
999 cookieverf3 cookieverf;
1015 struct READDIR3resok {
1016 post_op_attr dir_attributes;
1017 cookieverf3 cookieverf;
1021 struct READDIR3resfail {
1022 post_op_attr dir_attributes;
1025 union READDIR3res switch (nfsstat3 status) {
1027 READDIR3resok resok;
1029 READDIR3resfail resfail;
1033 * READDIRPLUS: Extended read from a directory
1035 struct READDIRPLUS3args {
1038 cookieverf3 cookieverf;
1047 post_op_attr name_attributes;
1048 post_op_fh3 name_handle;
1049 entryplus3 *nextentry;
1052 struct dirlistplus3 {
1053 entryplus3 *entries;
1057 struct READDIRPLUS3resok {
1058 post_op_attr dir_attributes;
1059 cookieverf3 cookieverf;
1063 struct READDIRPLUS3resfail {
1064 post_op_attr dir_attributes;
1067 union READDIRPLUS3res switch (nfsstat3 status) {
1069 READDIRPLUS3resok resok;
1071 READDIRPLUS3resfail resfail;
1075 * FSSTAT: Get dynamic file system information
1077 struct FSSTAT3args {
1081 struct FSSTAT3resok {
1082 post_op_attr obj_attributes;
1092 struct FSSTAT3resfail {
1093 post_op_attr obj_attributes;
1096 union FSSTAT3res switch (nfsstat3 status) {
1100 FSSTAT3resfail resfail;
1104 * FSINFO: Get static file system information
1107 const FSF3_LINK = 0x0001;
1108 const FSF3_SYMLINK = 0x0002;
1109 const FSF3_HOMOGENEOUS = 0x0008;
1110 const FSF3_CANSETTIME = 0x0010;
1112 struct FSINFO3args {
1116 struct FSINFO3resok {
1117 post_op_attr obj_attributes;
1126 nfstime3 time_delta;
1130 struct FSINFO3resfail {
1131 post_op_attr obj_attributes;
1134 union FSINFO3res switch (nfsstat3 status) {
1138 FSINFO3resfail resfail;
1142 * PATHCONF: Retrieve POSIX information
1144 struct PATHCONF3args {
1148 struct PATHCONF3resok {
1149 post_op_attr obj_attributes;
1153 bool chown_restricted;
1154 bool case_insensitive;
1155 bool case_preserving;
1158 struct PATHCONF3resfail {
1159 post_op_attr obj_attributes;
1162 union PATHCONF3res switch (nfsstat3 status) {
1164 PATHCONF3resok resok;
1166 PATHCONF3resfail resfail;
1170 * COMMIT: Commit cached data on a server to stable storage
1172 struct COMMIT3args {
1178 struct COMMIT3resok {
1183 struct COMMIT3resfail {
1187 union COMMIT3res switch (nfsstat3 status) {
1191 COMMIT3resfail resfail;
1195 * Remote file service routines
1197 program NFS3_PROGRAM {
1200 NFSPROC3_NULL(void) = 0;
1203 NFSPROC3_GETATTR(GETATTR3args) = 1;
1206 NFSPROC3_SETATTR(SETATTR3args) = 2;
1209 NFSPROC3_LOOKUP(LOOKUP3args) = 3;
1212 NFSPROC3_ACCESS(ACCESS3args) = 4;
1215 NFSPROC3_READLINK(READLINK3args) = 5;
1218 NFSPROC3_READ(READ3args) = 6;
1221 NFSPROC3_WRITE(WRITE3args) = 7;
1224 NFSPROC3_CREATE(CREATE3args) = 8;
1227 NFSPROC3_MKDIR(MKDIR3args) = 9;
1230 NFSPROC3_SYMLINK(SYMLINK3args) = 10;
1233 NFSPROC3_MKNOD(MKNOD3args) = 11;
1236 NFSPROC3_REMOVE(REMOVE3args) = 12;
1239 NFSPROC3_RMDIR(RMDIR3args) = 13;
1242 NFSPROC3_RENAME(RENAME3args) = 14;
1245 NFSPROC3_LINK(LINK3args) = 15;
1248 NFSPROC3_READDIR(READDIR3args) = 16;
1251 NFSPROC3_READDIRPLUS(READDIRPLUS3args) = 17;
1254 NFSPROC3_FSSTAT(FSSTAT3args) = 18;
1257 NFSPROC3_FSINFO(FSINFO3args) = 19;
1260 NFSPROC3_PATHCONF(PATHCONF3args) = 20;
1263 NFSPROC3_COMMIT(COMMIT3args) = 21;