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