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