Home | History | Annotate | Line # | Download | only in librpcsvc
nfs_prot.x revision 1.1
      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 %#ifndef lint
     32 %/*static char sccsid[] = "from: @(#)nfs_prot.x 1.2 87/10/12 Copyr 1987 Sun Micro";*/
     33 %/*static char sccsid[] = "from: @(#)nfs_prot.x	2.1 88/08/01 4.0 RPCSRC";*/
     34 %static char rcsid[] = "$Id: nfs_prot.x,v 1.1 1995/01/12 19:39:48 jtc Exp $";
     35 %#endif /* not lint */
     36 #endif
     37 
     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 */
     45 
     46 /*
     47  * File types
     48  */
     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 */
     57 
     58 /*
     59  * Error status
     60  */
     61 enum nfsstat {
     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_NODEV=19,	/* No such device */
     70 	NFSERR_NOTDIR=20,	/* Not a directory*/
     71 	NFSERR_ISDIR=21,	/* Is a directory */
     72 	NFSERR_FBIG=27,		/* File too large */
     73 	NFSERR_NOSPC=28,	/* No space left on device */
     74 	NFSERR_ROFS=30,		/* Read-only file system */
     75 	NFSERR_NAMETOOLONG=63,	/* File name too long */
     76 	NFSERR_NOTEMPTY=66,	/* Directory not empty */
     77 	NFSERR_DQUOT=69,	/* Disc quota exceeded */
     78 	NFSERR_STALE=70,	/* Stale NFS file handle */
     79 	NFSERR_WFLUSH=99	/* write cache flushed */
     80 };
     81 
     82 /*
     83  * File types
     84  */
     85 enum ftype {
     86 	NFNON = 0,	/* non-file */
     87 	NFREG = 1,	/* regular file */
     88 	NFDIR = 2,	/* directory */
     89 	NFBLK = 3,	/* block special */
     90 	NFCHR = 4,	/* character special */
     91 	NFLNK = 5,	/* symbolic link */
     92 	NFSOCK = 6,	/* unix domain sockets */
     93 	NFBAD = 7,	/* unused */
     94 	NFFIFO = 8 	/* named pipe */
     95 };
     96 
     97 /*
     98  * File access handle
     99  */
    100 struct nfs_fh {
    101 	opaque data[NFS_FHSIZE];
    102 };
    103 
    104 /*
    105  * Timeval
    106  */
    107 struct nfstime {
    108 	unsigned seconds;
    109 	unsigned useconds;
    110 };
    111 
    112 
    113 /*
    114  * File attributes
    115  */
    116 struct fattr {
    117 	ftype type;		/* file type */
    118 	unsigned mode;		/* protection mode bits */
    119 	unsigned nlink;		/* # hard links */
    120 	unsigned uid;		/* owner user id */
    121 	unsigned gid;		/* owner group id */
    122 	unsigned size;		/* file size in bytes */
    123 	unsigned blocksize;	/* prefered block size */
    124 	unsigned rdev;		/* special device # */
    125 	unsigned blocks;	/* Kb of disk used by file */
    126 	unsigned fsid;		/* device # */
    127 	unsigned fileid;	/* inode # */
    128 	nfstime	atime;		/* time of last access */
    129 	nfstime	mtime;		/* time of last modification */
    130 	nfstime	ctime;		/* time of last change */
    131 };
    132 
    133 /*
    134  * File attributes which can be set
    135  */
    136 struct sattr {
    137 	unsigned mode;	/* protection mode bits */
    138 	unsigned uid;	/* owner user id */
    139 	unsigned gid;	/* owner group id */
    140 	unsigned size;	/* file size in bytes */
    141 	nfstime	atime;	/* time of last access */
    142 	nfstime	mtime;	/* time of last modification */
    143 };
    144 
    145 
    146 typedef string filename<NFS_MAXNAMLEN>;
    147 typedef string nfspath<NFS_MAXPATHLEN>;
    148 
    149 /*
    150  * Reply status with file attributes
    151  */
    152 union attrstat switch (nfsstat status) {
    153 case NFS_OK:
    154 	fattr attributes;
    155 default:
    156 	void;
    157 };
    158 
    159 struct sattrargs {
    160 	nfs_fh file;
    161 	sattr attributes;
    162 };
    163 
    164 /*
    165  * Arguments for directory operations
    166  */
    167 struct diropargs {
    168 	nfs_fh	dir;	/* directory file handle */
    169 	filename name;		/* name (up to NFS_MAXNAMLEN bytes) */
    170 };
    171 
    172 struct diropokres {
    173 	nfs_fh file;
    174 	fattr attributes;
    175 };
    176 
    177 /*
    178  * Results from directory operation
    179  */
    180 union diropres switch (nfsstat status) {
    181 case NFS_OK:
    182 	diropokres diropres;
    183 default:
    184 	void;
    185 };
    186 
    187 union readlinkres switch (nfsstat status) {
    188 case NFS_OK:
    189 	nfspath data;
    190 default:
    191 	void;
    192 };
    193 
    194 /*
    195  * Arguments to remote read
    196  */
    197 struct readargs {
    198 	nfs_fh file;		/* handle for file */
    199 	unsigned offset;	/* byte offset in file */
    200 	unsigned count;		/* immediate read count */
    201 	unsigned totalcount;	/* total read count (from this offset)*/
    202 };
    203 
    204 /*
    205  * Status OK portion of remote read reply
    206  */
    207 struct readokres {
    208 	fattr	attributes;	/* attributes, need for pagin*/
    209 	opaque data<NFS_MAXDATA>;
    210 };
    211 
    212 union readres switch (nfsstat status) {
    213 case NFS_OK:
    214 	readokres reply;
    215 default:
    216 	void;
    217 };
    218 
    219 /*
    220  * Arguments to remote write
    221  */
    222 struct writeargs {
    223 	nfs_fh	file;		/* handle for file */
    224 	unsigned beginoffset;	/* beginning byte offset in file */
    225 	unsigned offset;	/* current byte offset in file */
    226 	unsigned totalcount;	/* total write count (to this offset)*/
    227 	opaque data<NFS_MAXDATA>;
    228 };
    229 
    230 struct createargs {
    231 	diropargs where;
    232 	sattr attributes;
    233 };
    234 
    235 struct renameargs {
    236 	diropargs from;
    237 	diropargs to;
    238 };
    239 
    240 struct linkargs {
    241 	nfs_fh from;
    242 	diropargs to;
    243 };
    244 
    245 struct symlinkargs {
    246 	diropargs from;
    247 	nfspath to;
    248 	sattr attributes;
    249 };
    250 
    251 
    252 typedef opaque nfscookie[NFS_COOKIESIZE];
    253 
    254 /*
    255  * Arguments to readdir
    256  */
    257 struct readdirargs {
    258 	nfs_fh dir;		/* directory handle */
    259 	nfscookie cookie;
    260 	unsigned count;		/* number of directory bytes to read */
    261 };
    262 
    263 struct entry {
    264 	unsigned fileid;
    265 	filename name;
    266 	nfscookie cookie;
    267 	entry *nextentry;
    268 };
    269 
    270 struct dirlist {
    271 	entry *entries;
    272 	bool eof;
    273 };
    274 
    275 union readdirres switch (nfsstat status) {
    276 case NFS_OK:
    277 	dirlist reply;
    278 default:
    279 	void;
    280 };
    281 
    282 struct statfsokres {
    283 	unsigned tsize;	/* preferred transfer size in bytes */
    284 	unsigned bsize;	/* fundamental file system block size */
    285 	unsigned blocks;	/* total blocks in file system */
    286 	unsigned bfree;	/* free blocks in fs */
    287 	unsigned bavail;	/* free blocks avail to non-superuser */
    288 };
    289 
    290 union statfsres switch (nfsstat status) {
    291 case NFS_OK:
    292 	statfsokres reply;
    293 default:
    294 	void;
    295 };
    296 
    297 /*
    298  * Remote file service routines
    299  */
    300 program NFS_PROGRAM {
    301 	version NFS_VERSION {
    302 		void
    303 		NFSPROC_NULL(void) = 0;
    304 
    305 		attrstat
    306 		NFSPROC_GETATTR(nfs_fh) =	1;
    307 
    308 		attrstat
    309 		NFSPROC_SETATTR(sattrargs) = 2;
    310 
    311 		void
    312 		NFSPROC_ROOT(void) = 3;
    313 
    314 		diropres
    315 		NFSPROC_LOOKUP(diropargs) = 4;
    316 
    317 		readlinkres
    318 		NFSPROC_READLINK(nfs_fh) = 5;
    319 
    320 		readres
    321 		NFSPROC_READ(readargs) = 6;
    322 
    323 		void
    324 		NFSPROC_WRITECACHE(void) = 7;
    325 
    326 		attrstat
    327 		NFSPROC_WRITE(writeargs) = 8;
    328 
    329 		diropres
    330 		NFSPROC_CREATE(createargs) = 9;
    331 
    332 		nfsstat
    333 		NFSPROC_REMOVE(diropargs) = 10;
    334 
    335 		nfsstat
    336 		NFSPROC_RENAME(renameargs) = 11;
    337 
    338 		nfsstat
    339 		NFSPROC_LINK(linkargs) = 12;
    340 
    341 		nfsstat
    342 		NFSPROC_SYMLINK(symlinkargs) = 13;
    343 
    344 		diropres
    345 		NFSPROC_MKDIR(createargs) = 14;
    346 
    347 		nfsstat
    348 		NFSPROC_RMDIR(diropargs) = 15;
    349 
    350 		readdirres
    351 		NFSPROC_READDIR(readdirargs) = 16;
    352 
    353 		statfsres
    354 		NFSPROC_STATFS(nfs_fh) = 17;
    355 	} = 2;
    356 } = 100003;
    357 
    358