1 /* 2 * This document was extracted by hand from RFC 1094. Several errors 3 * and omissions were corrected. Additional sources for this protocol 4 * specification include: 5 * 6 * https://pubs.opengroup.org/onlinepubs/9629799/chap7.htm 7 * 8 * Note that RFC 1094's official date of publication (March 1989) is 9 * before the IETF required its RFCs to carry an explicit copyright 10 * or other IP ownership notice. 11 */ 12 13 pragma header nfs2; 14 15 const NFS_MAXDATA = 8192; 16 const NFS_MAXPATHLEN = 1024; 17 const NFS_MAXNAMLEN = 255; 18 const NFS_COOKIESIZE = 4; 19 const NFS_FHSIZE = 32; 20 21 /* 22 * RFC 1094 calls the following enum "stat". That name conflicts with 23 * the Linux kernel's "struct stat" because in C, struct, union, and 24 * enum tags all share a single tag namespace. Details are specified 25 * in the C11 standard, Section 6.2.3. 26 */ 27 enum nfsstat { 28 NFS_OK = 0, 29 NFSERR_PERM = 1, 30 NFSERR_NOENT = 2, 31 NFSERR_IO = 5, 32 NFSERR_NXIO = 6, 33 NFSERR_ACCES = 13, 34 NFSERR_EXIST = 17, 35 NFSERR_NODEV = 19, 36 NFSERR_NOTDIR = 20, 37 NFSERR_ISDIR = 21, 38 NFSERR_FBIG = 27, 39 NFSERR_NOSPC = 28, 40 NFSERR_ROFS = 30, 41 NFSERR_NAMETOOLONG = 63, 42 NFSERR_NOTEMPTY = 66, 43 NFSERR_DQUOT = 69, 44 NFSERR_STALE = 70, 45 NFSERR_WFLUSH = 99 46 }; 47 pragma big_endian nfsstat; 48 49 enum ftype { 50 NFNON = 0, 51 NFREG = 1, 52 NFDIR = 2, 53 NFBLK = 3, 54 NFCHR = 4, 55 NFLNK = 5 56 }; 57 58 typedef opaque fhandle[NFS_FHSIZE]; 59 typedef opaque nfscookie[NFS_COOKIESIZE]; 60 61 struct timeval { 62 unsigned int seconds; 63 unsigned int useconds; 64 }; 65 66 struct fattr { 67 ftype type; 68 unsigned int mode; 69 unsigned int nlink; 70 unsigned int uid; 71 unsigned int gid; 72 unsigned int size; 73 unsigned int blocksize; 74 unsigned int rdev; 75 unsigned int blocks; 76 unsigned int fsid; 77 unsigned int fileid; 78 timeval atime; 79 timeval mtime; 80 timeval ctime; 81 }; 82 83 struct sattr { 84 unsigned int mode; 85 unsigned int uid; 86 unsigned int gid; 87 unsigned int size; 88 timeval atime; 89 timeval mtime; 90 }; 91 92 typedef string filename<NFS_MAXNAMLEN>; 93 typedef string path<NFS_MAXPATHLEN>; 94 95 union attrstat switch (nfsstat status) { 96 case NFS_OK: 97 fattr attributes; 98 default: 99 void; 100 }; 101 102 struct diropargs { 103 fhandle dir; 104 filename name; 105 }; 106 107 struct diropok { 108 fhandle file; 109 fattr attributes; 110 }; 111 112 union diropres switch (nfsstat status) { 113 case NFS_OK: 114 diropok diropok; 115 default: 116 void; 117 }; 118 119 struct sattrargs { 120 fhandle file; 121 sattr attributes; 122 }; 123 124 union readlinkres switch (nfsstat status) { 125 case NFS_OK: 126 path data; 127 default: 128 void; 129 }; 130 pragma pages readlinkres data; 131 132 struct readargs { 133 fhandle file; 134 unsigned int offset; 135 unsigned int count; 136 unsigned int totalcount; 137 }; 138 139 struct readresok { 140 fattr attributes; 141 opaque data<NFS_MAXDATA>; 142 }; 143 pragma pages readresok data; 144 145 union readres switch (nfsstat status) { 146 case NFS_OK: 147 readresok readresok; 148 default: 149 void; 150 }; 151 152 struct writeargs { 153 fhandle file; 154 unsigned int beginoffset; 155 unsigned int offset; 156 unsigned int totalcount; 157 opaque data<NFS_MAXDATA>; 158 }; 159 pragma pages writeargs data; 160 161 struct createargs { 162 diropargs where; 163 sattr attributes; 164 }; 165 166 struct renameargs { 167 diropargs from; 168 diropargs to; 169 }; 170 171 struct linkargs { 172 fhandle from; 173 diropargs to; 174 }; 175 176 struct symlinkargs { 177 diropargs from; 178 path to; 179 sattr attributes; 180 }; 181 pragma pages symlinkargs to; 182 183 struct readdirargs { 184 fhandle dir; 185 nfscookie cookie; 186 unsigned int count; 187 }; 188 189 struct entry { 190 unsigned int fileid; 191 filename name; 192 nfscookie cookie; 193 entry *nextentry; 194 }; 195 196 struct readdirok { 197 entry *entries; 198 bool eof; 199 }; 200 201 /* 202 * A spike encoding the entry list through the aggregate codec. The 203 * list encodes as the value-follows form -- each entry prefixed by 204 * TRUE, the sequence closed by FALSE -- and the encode hooks stream it 205 * straight from the directory during reply encoding rather than from a 206 * materialized array. The struct definitions above are the verbatim 207 * RFC 1094 types; only this pragma selects the hook-driven codec. 208 */ 209 pragma aggregate readdirok entries; 210 211 union readdirres switch (nfsstat status) { 212 case NFS_OK: 213 readdirok readdirok; 214 default: 215 void; 216 }; 217 218 struct info { 219 unsigned int tsize; 220 unsigned int bsize; 221 unsigned int blocks; 222 unsigned int bfree; 223 unsigned int bavail; 224 }; 225 226 union statfsres switch (nfsstat status) { 227 case NFS_OK: 228 info info; 229 default: 230 void; 231 }; 232 233 program NFS_PROGRAM { 234 version NFS_VERSION { 235 void NFSPROC_NULL(void) = 0; 236 attrstat NFSPROC_GETATTR(fhandle) = 1; 237 attrstat NFSPROC_SETATTR(sattrargs) = 2; 238 void NFSPROC_ROOT(void) = 3; 239 diropres NFSPROC_LOOKUP(diropargs) = 4; 240 readlinkres NFSPROC_READLINK(fhandle) = 5; 241 readres NFSPROC_READ(readargs) = 6; 242 void NFSPROC_WRITECACHE(void) = 7; 243 attrstat NFSPROC_WRITE(writeargs) = 8; 244 diropres NFSPROC_CREATE(createargs) = 9; 245 nfsstat NFSPROC_REMOVE(diropargs) = 10; 246 nfsstat NFSPROC_RENAME(renameargs) = 11; 247 nfsstat NFSPROC_LINK(linkargs) = 12; 248 nfsstat NFSPROC_SYMLINK(symlinkargs) = 13; 249 diropres NFSPROC_MKDIR(createargs) = 14; 250 nfsstat NFSPROC_RMDIR(diropargs) = 15; 251 readdirres NFSPROC_READDIR(readdirargs) = 16; 252 statfsres NFSPROC_STATFS(fhandle) = 17; 253 } = 2; 254 } = 100003; 255