1*3a50f0a9Sjmc /* $OpenBSD: nfs_prot.x,v 1.2 2022/12/28 21:30:15 jmc Exp $ */ 23cf360acSguenther 33cf360acSguenther /* 43cf360acSguenther * Copyright (c) 2010, Oracle America, Inc. 53cf360acSguenther * 63cf360acSguenther * Redistribution and use in source and binary forms, with or without 73cf360acSguenther * modification, are permitted provided that the following conditions are 83cf360acSguenther * met: 93cf360acSguenther * 103cf360acSguenther * * Redistributions of source code must retain the above copyright 113cf360acSguenther * notice, this list of conditions and the following disclaimer. 123cf360acSguenther * * Redistributions in binary form must reproduce the above 133cf360acSguenther * copyright notice, this list of conditions and the following 143cf360acSguenther * disclaimer in the documentation and/or other materials 153cf360acSguenther * provided with the distribution. 163cf360acSguenther * * Neither the name of the "Oracle America, Inc." nor the names of its 173cf360acSguenther * contributors may be used to endorse or promote products derived 183cf360acSguenther * from this software without specific prior written permission. 193cf360acSguenther * 203cf360acSguenther * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 213cf360acSguenther * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 223cf360acSguenther * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 233cf360acSguenther * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 243cf360acSguenther * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 253cf360acSguenther * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 263cf360acSguenther * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 273cf360acSguenther * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 283cf360acSguenther * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 293cf360acSguenther * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 303cf360acSguenther * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 313cf360acSguenther * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 323cf360acSguenther */ 333cf360acSguenther 343cf360acSguenther #ifndef RPC_HDR 353cf360acSguenther #endif 363cf360acSguenther 373cf360acSguenther const NFS_PORT = 2049; 383cf360acSguenther const NFS_MAXDATA = 8192; 393cf360acSguenther const NFS_MAXPATHLEN = 1024; 403cf360acSguenther const NFS_MAXNAMLEN = 255; 413cf360acSguenther const NFS_FHSIZE = 32; 423cf360acSguenther const NFSX_V2FH = 32; 433cf360acSguenther const NFSX_V3FHMAX = 64; 443cf360acSguenther const NFS_COOKIESIZE = 4; 453cf360acSguenther const NFS_FIFO_DEV = -1; /* size kludge for named pipes */ 463cf360acSguenther 473cf360acSguenther /* 483cf360acSguenther * File types 493cf360acSguenther */ 503cf360acSguenther const NFSMODE_FMT = 0170000; /* type of file */ 513cf360acSguenther const NFSMODE_DIR = 0040000; /* directory */ 523cf360acSguenther const NFSMODE_CHR = 0020000; /* character special */ 533cf360acSguenther const NFSMODE_BLK = 0060000; /* block special */ 543cf360acSguenther const NFSMODE_REG = 0100000; /* regular */ 553cf360acSguenther const NFSMODE_LNK = 0120000; /* symbolic link */ 563cf360acSguenther const NFSMODE_SOCK = 0140000; /* socket */ 573cf360acSguenther const NFSMODE_FIFO = 0010000; /* fifo */ 583cf360acSguenther 593cf360acSguenther /* 603cf360acSguenther * Error status 613cf360acSguenther */ 623cf360acSguenther #ifdef RPC_HDR 633cf360acSguenther %typedef int nfsstat; 643cf360acSguenther %#define xdr_nfsstat xdr_int 653cf360acSguenther #define nfsstat int 663cf360acSguenther %enum { 673cf360acSguenther % NFS_OK= 0, /* no error */ 683cf360acSguenther % NFSERR_PERM=1, /* Not owner */ 693cf360acSguenther % NFSERR_NOENT=2, /* No such file or directory */ 703cf360acSguenther % NFSERR_IO=5, /* I/O error */ 713cf360acSguenther % NFSERR_NXIO=6, /* No such device or address */ 723cf360acSguenther % NFSERR_ACCES=13, /* Permission denied */ 733cf360acSguenther % NFSERR_EXIST=17, /* File exists */ 743cf360acSguenther % NFSERR_NODEV=19, /* No such device */ 753cf360acSguenther % NFSERR_NOTDIR=20, /* Not a directory*/ 763cf360acSguenther % NFSERR_ISDIR=21, /* Is a directory */ 773cf360acSguenther % NFSERR_FBIG=27, /* File too large */ 783cf360acSguenther % NFSERR_NOSPC=28, /* No space left on device */ 793cf360acSguenther % NFSERR_ROFS=30, /* Read-only file system */ 803cf360acSguenther % NFSERR_NAMETOOLONG=63, /* File name too long */ 813cf360acSguenther % NFSERR_NOTEMPTY=66, /* Directory not empty */ 823cf360acSguenther % NFSERR_DQUOT=69, /* Disc quota exceeded */ 833cf360acSguenther % NFSERR_STALE=70, /* Stale NFS file handle */ 843cf360acSguenther % NFSERR_WFLUSH=99 /* write cache flushed */ 853cf360acSguenther %}; 863cf360acSguenther #elif RPC_XDR 873cf360acSguenther #define nfsstat int 883cf360acSguenther #else 893cf360acSguenther typedef int nfsstat; 903cf360acSguenther #endif 913cf360acSguenther 923cf360acSguenther /* 933cf360acSguenther * File types 943cf360acSguenther */ 953cf360acSguenther #ifdef RPC_HDR 963cf360acSguenther %typedef int ftype; 973cf360acSguenther #define ftype int 983cf360acSguenther %enum { 993cf360acSguenther % NFNON = 0, /* non-file */ 1003cf360acSguenther % NFREG = 1, /* regular file */ 1013cf360acSguenther % NFDIR = 2, /* directory */ 1023cf360acSguenther % NFBLK = 3, /* block special */ 1033cf360acSguenther % NFCHR = 4, /* character special */ 1043cf360acSguenther % NFLNK = 5, /* symbolic link */ 1053cf360acSguenther % NFSOCK = 6, /* unix domain sockets */ 1063cf360acSguenther % NFBAD = 7, /* unused */ 1073cf360acSguenther % NFFIFO = 8 /* named pipe */ 1083cf360acSguenther %}; 1093cf360acSguenther #elif RPC_XDR 1103cf360acSguenther #define ftype int 1113cf360acSguenther #else 1123cf360acSguenther typedef int ftype; 1133cf360acSguenther #endif 1143cf360acSguenther 1153cf360acSguenther /* 1163cf360acSguenther * File access handle 1173cf360acSguenther */ 1183cf360acSguenther struct nfs_fh { 1193cf360acSguenther opaque data[NFS_FHSIZE]; 1203cf360acSguenther }; 1213cf360acSguenther 1223cf360acSguenther /* 1233cf360acSguenther * Timeval 1243cf360acSguenther */ 1253cf360acSguenther struct nfstime { 1263cf360acSguenther unsigned seconds; 1273cf360acSguenther unsigned useconds; 1283cf360acSguenther }; 1293cf360acSguenther 1303cf360acSguenther 1313cf360acSguenther /* 1323cf360acSguenther * File attributes 1333cf360acSguenther */ 1343cf360acSguenther struct fattr { 1353cf360acSguenther ftype type; /* file type */ 1363cf360acSguenther unsigned mode; /* protection mode bits */ 1373cf360acSguenther unsigned nlink; /* # hard links */ 1383cf360acSguenther unsigned uid; /* owner user id */ 1393cf360acSguenther unsigned gid; /* owner group id */ 1403cf360acSguenther unsigned size; /* file size in bytes */ 141*3a50f0a9Sjmc unsigned blocksize; /* preferred block size */ 1423cf360acSguenther unsigned rdev; /* special device # */ 1433cf360acSguenther unsigned blocks; /* Kb of disk used by file */ 1443cf360acSguenther unsigned fsid; /* device # */ 1453cf360acSguenther unsigned fileid; /* inode # */ 1463cf360acSguenther nfstime atime; /* time of last access */ 1473cf360acSguenther nfstime mtime; /* time of last modification */ 1483cf360acSguenther nfstime ctime; /* time of last change */ 1493cf360acSguenther }; 1503cf360acSguenther 1513cf360acSguenther /* 1523cf360acSguenther * File attributes which can be set 1533cf360acSguenther */ 1543cf360acSguenther struct sattr { 1553cf360acSguenther unsigned mode; /* protection mode bits */ 1563cf360acSguenther unsigned uid; /* owner user id */ 1573cf360acSguenther unsigned gid; /* owner group id */ 1583cf360acSguenther unsigned size; /* file size in bytes */ 1593cf360acSguenther nfstime atime; /* time of last access */ 1603cf360acSguenther nfstime mtime; /* time of last modification */ 1613cf360acSguenther }; 1623cf360acSguenther 1633cf360acSguenther 1643cf360acSguenther typedef string filename<NFS_MAXNAMLEN>; 1653cf360acSguenther typedef string nfspath<NFS_MAXPATHLEN>; 1663cf360acSguenther 1673cf360acSguenther /* 1683cf360acSguenther * Reply status with file attributes 1693cf360acSguenther */ 1703cf360acSguenther union attrstat switch (nfsstat status) { 1713cf360acSguenther case NFS_OK: 1723cf360acSguenther fattr attributes; 1733cf360acSguenther default: 1743cf360acSguenther void; 1753cf360acSguenther }; 1763cf360acSguenther 1773cf360acSguenther struct sattrargs { 1783cf360acSguenther nfs_fh file; 1793cf360acSguenther sattr attributes; 1803cf360acSguenther }; 1813cf360acSguenther 1823cf360acSguenther /* 1833cf360acSguenther * Arguments for directory operations 1843cf360acSguenther */ 1853cf360acSguenther struct diropargs { 1863cf360acSguenther nfs_fh dir; /* directory file handle */ 1873cf360acSguenther filename name; /* name (up to NFS_MAXNAMLEN bytes) */ 1883cf360acSguenther }; 1893cf360acSguenther 1903cf360acSguenther struct diropokres { 1913cf360acSguenther nfs_fh file; 1923cf360acSguenther fattr attributes; 1933cf360acSguenther }; 1943cf360acSguenther 1953cf360acSguenther /* 1963cf360acSguenther * Results from directory operation 1973cf360acSguenther */ 1983cf360acSguenther union diropres switch (nfsstat status) { 1993cf360acSguenther case NFS_OK: 2003cf360acSguenther diropokres diropres; 2013cf360acSguenther default: 2023cf360acSguenther void; 2033cf360acSguenther }; 2043cf360acSguenther 2053cf360acSguenther union readlinkres switch (nfsstat status) { 2063cf360acSguenther case NFS_OK: 2073cf360acSguenther nfspath data; 2083cf360acSguenther default: 2093cf360acSguenther void; 2103cf360acSguenther }; 2113cf360acSguenther 2123cf360acSguenther /* 2133cf360acSguenther * Arguments to remote read 2143cf360acSguenther */ 2153cf360acSguenther struct readargs { 2163cf360acSguenther nfs_fh file; /* handle for file */ 2173cf360acSguenther unsigned offset; /* byte offset in file */ 2183cf360acSguenther unsigned count; /* immediate read count */ 2193cf360acSguenther unsigned totalcount; /* total read count (from this offset)*/ 2203cf360acSguenther }; 2213cf360acSguenther 2223cf360acSguenther /* 2233cf360acSguenther * Status OK portion of remote read reply 2243cf360acSguenther */ 2253cf360acSguenther struct readokres { 2263cf360acSguenther fattr attributes; /* attributes, need for pagin*/ 2273cf360acSguenther opaque data<NFS_MAXDATA>; 2283cf360acSguenther }; 2293cf360acSguenther 2303cf360acSguenther union readres switch (nfsstat status) { 2313cf360acSguenther case NFS_OK: 2323cf360acSguenther readokres reply; 2333cf360acSguenther default: 2343cf360acSguenther void; 2353cf360acSguenther }; 2363cf360acSguenther 2373cf360acSguenther /* 2383cf360acSguenther * Arguments to remote write 2393cf360acSguenther */ 2403cf360acSguenther struct writeargs { 2413cf360acSguenther nfs_fh file; /* handle for file */ 2423cf360acSguenther unsigned beginoffset; /* beginning byte offset in file */ 2433cf360acSguenther unsigned offset; /* current byte offset in file */ 2443cf360acSguenther unsigned totalcount; /* total write count (to this offset)*/ 2453cf360acSguenther opaque data<NFS_MAXDATA>; 2463cf360acSguenther }; 2473cf360acSguenther 2483cf360acSguenther struct createargs { 2493cf360acSguenther diropargs where; 2503cf360acSguenther sattr attributes; 2513cf360acSguenther }; 2523cf360acSguenther 2533cf360acSguenther struct renameargs { 2543cf360acSguenther diropargs from; 2553cf360acSguenther diropargs to; 2563cf360acSguenther }; 2573cf360acSguenther 2583cf360acSguenther struct linkargs { 2593cf360acSguenther nfs_fh from; 2603cf360acSguenther diropargs to; 2613cf360acSguenther }; 2623cf360acSguenther 2633cf360acSguenther struct symlinkargs { 2643cf360acSguenther diropargs from; 2653cf360acSguenther nfspath to; 2663cf360acSguenther sattr attributes; 2673cf360acSguenther }; 2683cf360acSguenther 2693cf360acSguenther 2703cf360acSguenther typedef opaque nfscookie[NFS_COOKIESIZE]; 2713cf360acSguenther 2723cf360acSguenther /* 2733cf360acSguenther * Arguments to readdir 2743cf360acSguenther */ 2753cf360acSguenther struct readdirargs { 2763cf360acSguenther nfs_fh dir; /* directory handle */ 2773cf360acSguenther nfscookie cookie; 2783cf360acSguenther unsigned count; /* number of directory bytes to read */ 2793cf360acSguenther }; 2803cf360acSguenther 2813cf360acSguenther struct entry { 2823cf360acSguenther unsigned fileid; 2833cf360acSguenther filename name; 2843cf360acSguenther nfscookie cookie; 2853cf360acSguenther entry *nextentry; 2863cf360acSguenther }; 2873cf360acSguenther 2883cf360acSguenther struct dirlist { 2893cf360acSguenther entry *entries; 2903cf360acSguenther bool eof; 2913cf360acSguenther }; 2923cf360acSguenther 2933cf360acSguenther union readdirres switch (nfsstat status) { 2943cf360acSguenther case NFS_OK: 2953cf360acSguenther dirlist reply; 2963cf360acSguenther default: 2973cf360acSguenther void; 2983cf360acSguenther }; 2993cf360acSguenther 3003cf360acSguenther struct statfsokres { 3013cf360acSguenther unsigned tsize; /* preferred transfer size in bytes */ 3023cf360acSguenther unsigned bsize; /* fundamental file system block size */ 3033cf360acSguenther unsigned blocks; /* total blocks in file system */ 3043cf360acSguenther unsigned bfree; /* free blocks in fs */ 3053cf360acSguenther unsigned bavail; /* free blocks avail to non-superuser */ 3063cf360acSguenther }; 3073cf360acSguenther 3083cf360acSguenther union statfsres switch (nfsstat status) { 3093cf360acSguenther case NFS_OK: 3103cf360acSguenther statfsokres reply; 3113cf360acSguenther default: 3123cf360acSguenther void; 3133cf360acSguenther }; 3143cf360acSguenther 3153cf360acSguenther /* 3163cf360acSguenther * Remote file service routines 3173cf360acSguenther */ 3183cf360acSguenther program NFS_PROGRAM { 3193cf360acSguenther version NFS_VERSION { 3203cf360acSguenther void 3213cf360acSguenther NFSPROC_NULL(void) = 0; 3223cf360acSguenther 3233cf360acSguenther attrstat 3243cf360acSguenther NFSPROC_GETATTR(nfs_fh) = 1; 3253cf360acSguenther 3263cf360acSguenther attrstat 3273cf360acSguenther NFSPROC_SETATTR(sattrargs) = 2; 3283cf360acSguenther 3293cf360acSguenther void 3303cf360acSguenther NFSPROC_ROOT(void) = 3; 3313cf360acSguenther 3323cf360acSguenther diropres 3333cf360acSguenther NFSPROC_LOOKUP(diropargs) = 4; 3343cf360acSguenther 3353cf360acSguenther readlinkres 3363cf360acSguenther NFSPROC_READLINK(nfs_fh) = 5; 3373cf360acSguenther 3383cf360acSguenther readres 3393cf360acSguenther NFSPROC_READ(readargs) = 6; 3403cf360acSguenther 3413cf360acSguenther void 3423cf360acSguenther NFSPROC_WRITECACHE(void) = 7; 3433cf360acSguenther 3443cf360acSguenther attrstat 3453cf360acSguenther NFSPROC_WRITE(writeargs) = 8; 3463cf360acSguenther 3473cf360acSguenther diropres 3483cf360acSguenther NFSPROC_CREATE(createargs) = 9; 3493cf360acSguenther 3503cf360acSguenther nfsstat 3513cf360acSguenther NFSPROC_REMOVE(diropargs) = 10; 3523cf360acSguenther 3533cf360acSguenther nfsstat 3543cf360acSguenther NFSPROC_RENAME(renameargs) = 11; 3553cf360acSguenther 3563cf360acSguenther nfsstat 3573cf360acSguenther NFSPROC_LINK(linkargs) = 12; 3583cf360acSguenther 3593cf360acSguenther nfsstat 3603cf360acSguenther NFSPROC_SYMLINK(symlinkargs) = 13; 3613cf360acSguenther 3623cf360acSguenther diropres 3633cf360acSguenther NFSPROC_MKDIR(createargs) = 14; 3643cf360acSguenther 3653cf360acSguenther nfsstat 3663cf360acSguenther NFSPROC_RMDIR(diropargs) = 15; 3673cf360acSguenther 3683cf360acSguenther readdirres 3693cf360acSguenther NFSPROC_READDIR(readdirargs) = 16; 3703cf360acSguenther 3713cf360acSguenther statfsres 3723cf360acSguenther NFSPROC_STATFS(nfs_fh) = 17; 3733cf360acSguenther } = 2; 3743cf360acSguenther } = 100003; 3753cf360acSguenther 376