/*
	$Id: nfs2-spec 208 2005-05-14 22:32:57Z ajw $
	$URL: http://svn.cp15.org/NFS/tags/v106/!Sunfish/nfs2-spec $

	XDR Specification for the NFS V2 protocol.
	See RFC 1094 for more details.

	StrongEd$Mode=C
*/

#define NFS_RPC_PROGRAM 100003
#define NFS_RPC_VERSION 2

/* The maximum number of bytes of data in a READ or WRITE request. */
const NFS2MAXDATA = 8192;

/* The maximum number of bytes in a pathname argument. */
const MAXPATHLEN = 1024;

/* The maximum number of bytes in a file name argument. */
const MAXNAMLEN = 255;

/* The size in bytes of the opaque "cookie" passed by READDIR. */
const COOKIESIZE  = 4;

/* The size in bytes of the opaque file handle. */
const FHSIZE = 32;


enum nstat {
    NFS_OK = 0,
    NFSERR_PERM=1,

    NFSERR_NOENT=2,
    NFSERR_IO=5,
    NFSERR_NXIO=6,
    NFSERR_ACCES=13,
    NFSERR_EXIST=17,
    NFSERR_NODEV=19,
    NFSERR_NOTDIR=20,
    NFSERR_ISDIR=21,
    NFSERR_FBIG=27,
    NFSERR_NOSPC=28,
    NFSERR_ROFS=30,
    NFSERR_NAMETOOLONG=63,
    NFSERR_NOTEMPTY=66,
    NFSERR_DQUOT=69,
    NFSERR_STALE=70,
    NFSERR_WFLUSH=99
};

enum ftype {
    NFNON = 0,
    NFREG = 1,
    NFDIR = 2,
    NFBLK = 3,
    NFCHR = 4,
    NFLNK = 5
};

#ifndef NFS_FH
#define NFS_FH
typedef opaque fhdata[FHSIZE];

struct nfs_fh {
   fhdata data;
};
#endif

struct ntimeval {
    unsigned int seconds;
    unsigned int useconds;
};

struct fattr {
    ftype        type;
    unsigned int mode;
    unsigned int nlink;
    unsigned int uid;
    unsigned int gid;
    unsigned int size;
    unsigned int blocksize;
    unsigned int rdev;
    unsigned int blocks;

    unsigned int fsid;
    unsigned int fileid;
    ntimeval      atime;
    ntimeval      mtime;
    ntimeval      ctime;
};

struct sattr {
    unsigned int mode;
    unsigned int uid;
    unsigned int gid;
    unsigned int size;
    ntimeval      atime;
    ntimeval      mtime;
};

typedef string filename<MAXNAMLEN>;

typedef string path<MAXPATHLEN>;


void NFSPROC_NULL(void) = 0;

union attrstat switch (nstat status) {
case NFS_OK:
    fattr attributes;
default:
    void;
};

struct diropargs {
    nfs_fh  dir;
    filename name;
};

struct diropok {
    nfs_fh file;
    fattr   attributes;
};

union diropres switch (nstat status) {
case NFS_OK:
    diropok diropok;
default:
    void;
};


diropres NFSPROC_LOOKUP(diropargs) = 4;

typedef int nfscookie;

struct readdirargs {
        nfs_fh dir;
        nfscookie cookie;
        unsigned count;
};

struct *entry {
        unsigned fileid;
        filename name;
        nfscookie cookie;
        entry *next;
};

struct readdirok {
        entry *entries;
        bool eof;
};

union readdirres switch (nstat status) {
case NFS_OK:
        readdirok readdirok;
default:
        void;
};

readdirres NFSPROC_READDIR(readdirargs) = 16;

struct readargs {
        nfs_fh file;
        unsigned offset;
        unsigned count;
        unsigned totalcount;
};

union readres switch (nstat status) {
case NFS_OK:
        fattr attributes;
        opaque data<>;
default:
        void;
};

readres NFSPROC_READ(readargs) = 6;

struct writeargs {
        nfs_fh file;
        unsigned beginoffset;
        unsigned offset;
        unsigned totalcount;
        opaque data<>;
};

attrstat NFSPROC_WRITE(writeargs) = 8;

struct createargs {
        diropargs where;
        sattr attributes;
};

union createres switch (nstat status) {
case NFS_OK:
    diropok diropok;
default:
    void;
};

createres NFSPROC_CREATE(createargs) = 9;

struct removeres {
        nstat status;
};

removeres NFSPROC_RMDIR(diropargs) = 15;

removeres NFSPROC_REMOVE(diropargs) = 10;

struct renameargs {
        diropargs from;
        diropargs to;
};

struct renameres {
        nstat status;
};

renameres NFSPROC_RENAME(renameargs) = 11;

struct getattrargs {
	nfs_fh fhandle;
};

attrstat NFSPROC_GETATTR(getattrargs) = 1;

struct mkdirargs {
        diropargs where;
        sattr attributes;
};

createres NFSPROC_MKDIR(mkdirargs) = 14;

struct sattrargs {
        nfs_fh file;
        sattr attributes;
};

union sattrres switch (nstat status) {
case NFS_OK:
    fattr attributes;
default:
    void;
};

sattrres NFSPROC_SETATTR(sattrargs) = 2;

struct info {
    unsigned tsize;
    unsigned bsize;
    unsigned blocks;
    unsigned bfree;
    unsigned bavail;
};

union statfsres switch (nstat status) {
case NFS_OK:
	info info;
default:
        void;
};

struct statfsargs {
	nfs_fh fhandle;
};

statfsres NFSPROC_STATFS(statfsargs) = 17;

struct readlinkargs {
	nfs_fh fhandle;
};

struct readlinkresok {
	path data;
};

union readlinkres switch (nstat status) {
case NFS_OK:
    readlinkresok resok;
default:
    void;
};

readlinkres NFSPROC_READLINK(readlinkargs) = 5;

