1 /* 2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3 * unrestricted use provided that this legend is included on all tape 4 * media and as a part of the software program in whole or part. Users 5 * may copy or modify Sun RPC without charge, but are not authorized 6 * to license or distribute it to anyone else except as part of a product or 7 * program developed by the user. 8 * 9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12 * 13 * Sun RPC is provided with no support and without any obligation on the 14 * part of Sun Microsystems, Inc. to assist in its use, correction, 15 * modification or enhancement. 16 * 17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19 * OR ANY PART THEREOF. 20 * 21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22 * or profits or other special, indirect and consequential damages, even if 23 * Sun has been advised of the possibility of such damages. 24 * 25 * Sun Microsystems, Inc. 26 * 2550 Garcia Avenue 27 * Mountain View, California 94043 28 */ 29 30 #ifndef RPC_HDR 31 %#include <sys/cdefs.h> 32 %#ifndef lint 33 %/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/ 34 %/*static char sccsid[] = "from: @(#)nfs_prot.x 2.1 88/08/01 4.0 RPCSRC";*/ 35 %__RCSID("$NetBSD: nfs_prot.x,v 1.4 1999/07/02 15:44:13 simonb Exp $"); 36 %#endif /* not lint */ 37 #endif 38 39 const NFS_PORT = 2049; 40 const NFS_MAXDATA = 8192; 41 const NFS_MAXPATHLEN = 1024; 42 const NFS_MAXNAMLEN = 255; 43 const NFS_FHSIZE = 32; 44 const NFS_COOKIESIZE = 4; 45 const NFS_FIFO_DEV = -1; /* size kludge for named pipes */ 46 47 /* 48 * File types 49 */ 50 const NFSMODE_FMT = 0170000; /* type of file */ 51 const NFSMODE_DIR = 0040000; /* directory */ 52 const NFSMODE_CHR = 0020000; /* character special */ 53 const NFSMODE_BLK = 0060000; /* block special */ 54 const NFSMODE_REG = 0100000; /* regular */ 55 const NFSMODE_LNK = 0120000; /* symbolic link */ 56 const NFSMODE_SOCK = 0140000; /* socket */ 57 const NFSMODE_FIFO = 0010000; /* fifo */ 58 59 /* 60 * Error status 61 */ 62 enum nfsstat { 63 NFS_OK= 0, /* no error */ 64 NFSERR_PERM=1, /* Not owner */ 65 NFSERR_NOENT=2, /* No such file or directory */ 66 NFSERR_IO=5, /* I/O error */ 67 NFSERR_NXIO=6, /* No such device or address */ 68 NFSERR_ACCES=13, /* Permission denied */ 69 NFSERR_EXIST=17, /* File exists */ 70 NFSERR_NODEV=19, /* No such device */ 71 NFSERR_NOTDIR=20, /* Not a directory*/ 72 NFSERR_ISDIR=21, /* Is a directory */ 73 NFSERR_FBIG=27, /* File too large */ 74 NFSERR_NOSPC=28, /* No space left on device */ 75 NFSERR_ROFS=30, /* Read-only file system */ 76 NFSERR_NAMETOOLONG=63, /* File name too long */ 77 NFSERR_NOTEMPTY=66, /* Directory not empty */ 78 NFSERR_DQUOT=69, /* Disc quota exceeded */ 79 NFSERR_STALE=70, /* Stale NFS file handle */ 80 NFSERR_WFLUSH=99 /* write cache flushed */ 81 }; 82 83 /* 84 * File types 85 */ 86 enum ftype { 87 NFNON = 0, /* non-file */ 88 NFREG = 1, /* regular file */ 89 NFDIR = 2, /* directory */ 90 NFBLK = 3, /* block special */ 91 NFCHR = 4, /* character special */ 92 NFLNK = 5, /* symbolic link */ 93 NFSOCK = 6, /* unix domain sockets */ 94 NFBAD = 7, /* unused */ 95 NFFIFO = 8 /* named pipe */ 96 }; 97 98 /* 99 * File access handle 100 */ 101 struct nfs_fh { 102 opaque data[NFS_FHSIZE]; 103 }; 104 105 /* 106 * Timeval 107 */ 108 struct nfstime { 109 unsigned seconds; 110 unsigned useconds; 111 }; 112 113 114 /* 115 * File attributes 116 */ 117 struct fattr { 118 ftype type; /* file type */ 119 unsigned mode; /* protection mode bits */ 120 unsigned nlink; /* # hard links */ 121 unsigned uid; /* owner user id */ 122 unsigned gid; /* owner group id */ 123 unsigned size; /* file size in bytes */ 124 unsigned blocksize; /* prefered block size */ 125 unsigned rdev; /* special device # */ 126 unsigned blocks; /* Kb of disk used by file */ 127 unsigned fsid; /* device # */ 128 unsigned fileid; /* inode # */ 129 nfstime atime; /* time of last access */ 130 nfstime mtime; /* time of last modification */ 131 nfstime ctime; /* time of last change */ 132 }; 133 134 /* 135 * File attributes which can be set 136 */ 137 struct sattr { 138 unsigned mode; /* protection mode bits */ 139 unsigned uid; /* owner user id */ 140 unsigned gid; /* owner group id */ 141 unsigned size; /* file size in bytes */ 142 nfstime atime; /* time of last access */ 143 nfstime mtime; /* time of last modification */ 144 }; 145 146 147 typedef string filename<NFS_MAXNAMLEN>; 148 typedef string nfspath<NFS_MAXPATHLEN>; 149 150 /* 151 * Reply status with file attributes 152 */ 153 union attrstat switch (nfsstat status) { 154 case NFS_OK: 155 fattr attributes; 156 default: 157 void; 158 }; 159 160 struct sattrargs { 161 nfs_fh file; 162 sattr attributes; 163 }; 164 165 /* 166 * Arguments for directory operations 167 */ 168 struct diropargs { 169 nfs_fh dir; /* directory file handle */ 170 filename name; /* name (up to NFS_MAXNAMLEN bytes) */ 171 }; 172 173 struct diropokres { 174 nfs_fh file; 175 fattr attributes; 176 }; 177 178 /* 179 * Results from directory operation 180 */ 181 union diropres switch (nfsstat status) { 182 case NFS_OK: 183 diropokres diropres; 184 default: 185 void; 186 }; 187 188 union readlinkres switch (nfsstat status) { 189 case NFS_OK: 190 nfspath data; 191 default: 192 void; 193 }; 194 195 /* 196 * Arguments to remote read 197 */ 198 struct readargs { 199 nfs_fh file; /* handle for file */ 200 unsigned offset; /* byte offset in file */ 201 unsigned count; /* immediate read count */ 202 unsigned totalcount; /* total read count (from this offset)*/ 203 }; 204 205 /* 206 * Status OK portion of remote read reply 207 */ 208 struct readokres { 209 fattr attributes; /* attributes, need for pagin*/ 210 opaque data<NFS_MAXDATA>; 211 }; 212 213 union readres switch (nfsstat status) { 214 case NFS_OK: 215 readokres reply; 216 default: 217 void; 218 }; 219 220 /* 221 * Arguments to remote write 222 */ 223 struct writeargs { 224 nfs_fh file; /* handle for file */ 225 unsigned beginoffset; /* beginning byte offset in file */ 226 unsigned offset; /* current byte offset in file */ 227 unsigned totalcount; /* total write count (to this offset)*/ 228 opaque data<NFS_MAXDATA>; 229 }; 230 231 struct createargs { 232 diropargs where; 233 sattr attributes; 234 }; 235 236 struct renameargs { 237 diropargs from; 238 diropargs to; 239 }; 240 241 struct linkargs { 242 nfs_fh from; 243 diropargs to; 244 }; 245 246 struct symlinkargs { 247 diropargs from; 248 nfspath to; 249 sattr attributes; 250 }; 251 252 253 typedef opaque nfscookie[NFS_COOKIESIZE]; 254 255 /* 256 * Arguments to readdir 257 */ 258 struct readdirargs { 259 nfs_fh dir; /* directory handle */ 260 nfscookie cookie; 261 unsigned count; /* number of directory bytes to read */ 262 }; 263 264 struct entry { 265 unsigned fileid; 266 filename name; 267 nfscookie cookie; 268 entry *nextentry; 269 }; 270 271 struct dirlist { 272 entry *entries; 273 bool eof; 274 }; 275 276 union readdirres switch (nfsstat status) { 277 case NFS_OK: 278 dirlist reply; 279 default: 280 void; 281 }; 282 283 struct statfsokres { 284 unsigned tsize; /* preferred transfer size in bytes */ 285 unsigned bsize; /* fundamental file system block size */ 286 unsigned blocks; /* total blocks in file system */ 287 unsigned bfree; /* free blocks in fs */ 288 unsigned bavail; /* free blocks avail to non-superuser */ 289 }; 290 291 union statfsres switch (nfsstat status) { 292 case NFS_OK: 293 statfsokres reply; 294 default: 295 void; 296 }; 297 298 /* 299 * Remote file service routines 300 */ 301 program NFS_PROGRAM { 302 version NFS_VERSION { 303 void 304 NFSPROC_NULL(void) = 0; 305 306 attrstat 307 NFSPROC_GETATTR(nfs_fh) = 1; 308 309 attrstat 310 NFSPROC_SETATTR(sattrargs) = 2; 311 312 void 313 NFSPROC_ROOT(void) = 3; 314 315 diropres 316 NFSPROC_LOOKUP(diropargs) = 4; 317 318 readlinkres 319 NFSPROC_READLINK(nfs_fh) = 5; 320 321 readres 322 NFSPROC_READ(readargs) = 6; 323 324 void 325 NFSPROC_WRITECACHE(void) = 7; 326 327 attrstat 328 NFSPROC_WRITE(writeargs) = 8; 329 330 diropres 331 NFSPROC_CREATE(createargs) = 9; 332 333 nfsstat 334 NFSPROC_REMOVE(diropargs) = 10; 335 336 nfsstat 337 NFSPROC_RENAME(renameargs) = 11; 338 339 nfsstat 340 NFSPROC_LINK(linkargs) = 12; 341 342 nfsstat 343 NFSPROC_SYMLINK(symlinkargs) = 13; 344 345 diropres 346 NFSPROC_MKDIR(createargs) = 14; 347 348 nfsstat 349 NFSPROC_RMDIR(diropargs) = 15; 350 351 readdirres 352 NFSPROC_READDIR(readdirargs) = 16; 353 354 statfsres 355 NFSPROC_STATFS(nfs_fh) = 17; 356 } = 2; 357 } = 100003; 358 359