home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / NextDeveloper / Headers / bsd / nfs / nfs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  11.2 KB  |  465 lines

  1. /*    @(#)nfs.h    2.2 88/05/20 NFSSRC4.0 from  2.36 88/02/08 SMI     */
  2.  
  3. /*
  4.  * HISTORY
  5.  * 19-Dec-88  Peter King (king) at NeXT
  6.  *    NFS 4.0 Changes:  Increased default timeouts.  Minor structure 
  7.  *              additions
  8.  */
  9.  
  10. #ifndef __NFS_HEADER__
  11. #define __NFS_HEADER__
  12.  
  13. /* Maximum size of data portion of a remote request */
  14. #define    NFS_MAXDATA    8192
  15. #define    NFS_MAXNAMLEN    255
  16. #define    NFS_MAXPATHLEN    1024
  17.  
  18. /*
  19.  * Rpc retransmission parameters
  20.  */
  21. #define    NFS_TIMEO    11    /* initial timeout in tenths of a sec. */
  22. #define    NFS_RETRIES    5    /* times to retry request */
  23.  
  24. /*
  25.  * maximum transfer size for different interfaces
  26.  */
  27. #if    NeXT
  28. /* Sun defined these things depending on their hardware devices! */
  29. #define NFSTSIZE 8192
  30. #else    NeXT
  31. #define    ECTSIZE    4096
  32. #define    IETSIZE    8192
  33. #endif    NeXT
  34.  
  35. #if    NeXT
  36. #define    NFS_BLOCKSIZE    1024        /* no more DEV_BSIZE */
  37. #endif    NeXT
  38. /*
  39.  * Error status
  40.  * Should include all possible net errors.
  41.  * For now we just cast errno into an enum nfsstat.
  42.  */
  43. enum nfsstat {
  44.     NFS_OK = 0,            /* no error */
  45.     NFSERR_PERM=EPERM,        /* Not owner */
  46.     NFSERR_NOENT=ENOENT,        /* No such file or directory */
  47.     NFSERR_IO=EIO,            /* I/O error */
  48.     NFSERR_NXIO=ENXIO,        /* No such device or address */
  49.     NFSERR_ACCES=EACCES,        /* Permission denied */
  50.     NFSERR_EXIST=EEXIST,        /* File exists */
  51.     NFSERR_NODEV=ENODEV,        /* No such device */
  52.     NFSERR_NOTDIR=ENOTDIR,        /* Not a directory */
  53.     NFSERR_ISDIR=EISDIR,        /* Is a directory */
  54.     NFSERR_FBIG=EFBIG,        /* File too large */
  55.     NFSERR_NOSPC=ENOSPC,        /* No space left on device */
  56.     NFSERR_ROFS=EROFS,        /* Read-only file system */
  57.     NFSERR_NAMETOOLONG=ENAMETOOLONG,/* File name too long */
  58.     NFSERR_NOTEMPTY=ENOTEMPTY,    /* Directory not empty */
  59.     NFSERR_DQUOT=EDQUOT,        /* Disc quota exceeded */
  60.     NFSERR_STALE=ESTALE,        /* Stale NFS file handle */
  61.     NFSERR_WFLUSH            /* write cache flushed */
  62. };
  63. #define    puterrno(error)        ((enum nfsstat)error)
  64. #define    geterrno(status)    ((int)status)
  65.  
  66. /*
  67.  * File types
  68.  */
  69. enum nfsftype {
  70.     NFNON,
  71.     NFREG,        /* regular file */
  72.     NFDIR,        /* directory */
  73.     NFBLK,        /* block special */
  74.     NFCHR,        /* character special */
  75.     NFLNK        /* symbolic link */
  76. };
  77.  
  78. /*
  79.  * Special kludge for fifos (named pipes)  [to adhere to NFS Protocol Spec]
  80.  *
  81.  * VFIFO is not in the protocol spec (VNON will be replaced by VFIFO)
  82.  * so the over-the-wire representation is VCHR with a '-1' device number.
  83.  *
  84.  * NOTE: This kludge becomes unnecessary with the Protocol Revision,
  85.  *       but it may be necessary to support it (backwards compatibility).
  86.  */
  87. #define NFS_FIFO_TYPE    NFCHR
  88. #define NFS_FIFO_MODE    S_IFCHR
  89. #define NFS_FIFO_DEV    (~0)
  90.  
  91. /* identify fifo in nfs attributes */
  92. #define NA_ISFIFO(NA)    (((NA)->na_type == NFS_FIFO_TYPE) && \
  93.                 ((NA)->na_rdev == NFS_FIFO_DEV))
  94.  
  95. /* set fifo in nfs attributes */
  96. #define NA_SETFIFO(NA)    { \
  97.             (NA)->na_type = NFS_FIFO_TYPE; \
  98.             (NA)->na_rdev = NFS_FIFO_DEV; \
  99.             (NA)->na_mode = ((NA)->na_mode&~S_IFMT)|NFS_FIFO_MODE; \
  100.             }
  101.  
  102.  
  103. /*
  104.  * Size of an fhandle in bytes
  105.  */
  106. #define    NFS_FHSIZE    32
  107.  
  108. /*
  109.  * File access handle
  110.  * This structure is the Sun server representation of a file.
  111.  * It is handed out by a server for the client to use in further
  112.  * file transactions.
  113.  */
  114.  
  115. #ifdef NFS_SERVER
  116. /*
  117.  * This struct is only used to find the size of the data field in the 
  118.  * fhandle structure below.
  119.  */
  120. struct fhsize {
  121.     fsid_t    f1;
  122.     u_short    f2;
  123.     char    f3[4];
  124.     u_short f4;
  125.     char    f5[4];
  126. };
  127. #define    NFS_FHMAXDATA   ((NFS_FHSIZE - sizeof(struct fhsize) + 8) / 2)
  128.  
  129. struct svcfh {
  130.     fsid_t    fh_fsid;        /* filesystem id */
  131.     u_short fh_len;                 /* file number length */
  132.     char    fh_data[NFS_FHMAXDATA]; /* and data */
  133.     u_short fh_xlen;                /* export file number length */
  134.     char    fh_xdata[NFS_FHMAXDATA];/* and data */
  135. };
  136.  
  137. typedef struct svcfh fhandle_t;
  138. #else
  139. /*
  140.  * This is the client view of an fhandle
  141.  */
  142. typedef struct {
  143.     char    fh_data[NFS_FHSIZE];    /* opaque data */
  144. } fhandle_t;
  145. #endif
  146.  
  147.  
  148. /*
  149.  * Arguments to remote write and writecache
  150.  */
  151. struct nfswriteargs {
  152.     fhandle_t    wa_fhandle;    /* handle for file */
  153.     u_long        wa_begoff;    /* beginning byte offset in file */
  154.     u_long        wa_offset;      /* current byte offset in file */
  155.     u_long        wa_totcount;    /* total write count (to this offset)*/
  156.     u_long        wa_count;    /* size of this write */
  157.     char        *wa_data;    /* data to write (up to NFS_MAXDATA) */
  158.     struct mbuf    *wa_mbuf;    /* mbuf containing data */
  159. };
  160.  
  161.  
  162. /*
  163.  * File attributes
  164.  */
  165. struct nfsfattr {
  166.     enum nfsftype    na_type;    /* file type */
  167.     u_long        na_mode;    /* protection mode bits */
  168.     u_long        na_nlink;    /* # hard links */
  169.     u_long        na_uid;        /* owner user id */
  170.     u_long        na_gid;        /* owner group id */
  171.     u_long        na_size;    /* file size in bytes */
  172.     u_long        na_blocksize;    /* prefered block size */
  173.     u_long        na_rdev;    /* special device # */
  174.     u_long        na_blocks;    /* Kb of disk used by file */
  175.     u_long        na_fsid;    /* device # */
  176.     u_long        na_nodeid;    /* inode # */
  177.     struct timeval    na_atime;    /* time of last access */
  178.     struct timeval    na_mtime;    /* time of last modification */
  179.     struct timeval    na_ctime;    /* time of last change */
  180. };
  181.  
  182. #define n2v_type(x)    (NA_ISFIFO(x) ? VFIFO : (enum vtype)((x)->na_type))
  183. #define n2v_rdev(x)    (NA_ISFIFO(x) ? 0 : (x)->na_rdev)
  184.  
  185. /*
  186.  * Arguments to remote read
  187.  */
  188. struct nfsreadargs {
  189.     fhandle_t    ra_fhandle;    /* handle for file */
  190.     u_long        ra_offset;    /* byte offset in file */
  191.     u_long        ra_count;    /* immediate read count */
  192.     u_long        ra_totcount;    /* total read cnt (from this offset)*/
  193. };
  194.  
  195. /*
  196.  * Status OK portion of remote read reply
  197.  */
  198. struct nfsrrok {
  199.     struct nfsfattr    rrok_attr;    /* attributes, need for pagin */
  200.     u_long        rrok_count;    /* bytes of data */
  201.     char        *rrok_data;    /* data (up to NFS_MAXDATA bytes) */
  202.     struct buf    *rrok_bp;    /* buffer pointer for bread */
  203.     struct vnode    *rrok_vp;    /* vnode assoc. with mapping */
  204. };
  205.  
  206. /*
  207.  * Reply from remote read
  208.  */
  209. struct nfsrdresult {
  210.     enum nfsstat    rr_status;        /* status of read */
  211.     union {
  212.         struct nfsrrok    rr_ok_u;    /* attributes, need for pagin*/
  213.     } rr_u;
  214. };
  215. #define    rr_ok        rr_u.rr_ok_u
  216. #define    rr_attr        rr_u.rr_ok_u.rrok_attr
  217. #define    rr_count    rr_u.rr_ok_u.rrok_count
  218. #define    rr_data        rr_u.rr_ok_u.rrok_data
  219. #define rr_bp        rr_u.rr_ok_u.rrok_bp
  220. #define rr_vp        rr_u.rr_ok_u.rrok_vp
  221.  
  222.  
  223. /*
  224.  * File attributes which can be set
  225.  */
  226. struct nfssattr {
  227.     u_long        sa_mode;    /* protection mode bits */
  228.     u_long        sa_uid;        /* owner user id */
  229.     u_long        sa_gid;        /* owner group id */
  230.     u_long        sa_size;    /* file size in bytes */
  231.     struct timeval    sa_atime;    /* time of last access */
  232.     struct timeval    sa_mtime;    /* time of last modification */
  233. };
  234.  
  235.  
  236. /*
  237.  * Reply status with file attributes
  238.  */
  239. struct nfsattrstat {
  240.     enum nfsstat    ns_status;        /* reply status */
  241.     union {
  242.         struct nfsfattr ns_attr_u;    /* NFS_OK: file attributes */
  243.     } ns_u;
  244. };
  245. #define    ns_attr    ns_u.ns_attr_u
  246.  
  247.  
  248. /*
  249.  * NFS_OK part of read sym link reply union
  250.  */
  251. struct nfssrok {
  252.     u_long    srok_count;    /* size of string */
  253.     char    *srok_data;    /* string (up to NFS_MAXPATHLEN bytes) */
  254. };
  255.  
  256. /*
  257.  * Result of reading symbolic link
  258.  */
  259. struct nfsrdlnres {
  260.     enum nfsstat    rl_status;        /* status of symlink read */
  261.     union {
  262.         struct nfssrok    rl_srok_u;    /* name of linked to */
  263.     } rl_u;
  264. };
  265. #define    rl_srok        rl_u.rl_srok_u
  266. #define    rl_count    rl_u.rl_srok_u.srok_count
  267. #define    rl_data        rl_u.rl_srok_u.srok_data
  268.  
  269.  
  270. /*
  271.  * Arguments to readdir
  272.  */
  273. struct nfsrddirargs {
  274.     fhandle_t rda_fh;    /* directory handle */
  275.     u_long rda_offset;    /* offset in directory (opaque) */
  276.     u_long rda_count;    /* number of directory bytes to read */
  277. };
  278.  
  279. /*
  280.  * NFS_OK part of readdir result
  281.  */
  282. struct nfsrdok {
  283.     u_long    rdok_offset;        /* next offset (opaque) */
  284.     u_long    rdok_size;        /* size in bytes of entries */
  285.     bool_t    rdok_eof;        /* true if last entry is in result*/
  286.     struct direct *rdok_entries;    /* variable number of entries */
  287. };
  288.  
  289. /*
  290.  * Readdir result
  291.  */
  292. struct nfsrddirres {
  293.     u_long        rd_bufsize;    /* client request size (not xdr'ed)*/
  294.     enum nfsstat    rd_status;
  295.     union {
  296.         struct nfsrdok rd_rdok_u;
  297.     } rd_u;
  298. };
  299. #define    rd_rdok        rd_u.rd_rdok_u
  300. #define    rd_offset    rd_u.rd_rdok_u.rdok_offset
  301. #define    rd_size        rd_u.rd_rdok_u.rdok_size
  302. #define    rd_eof        rd_u.rd_rdok_u.rdok_eof
  303. #define    rd_entries    rd_u.rd_rdok_u.rdok_entries
  304.  
  305.  
  306. /*
  307.  * Arguments for directory operations
  308.  */
  309. struct nfsdiropargs {
  310.     fhandle_t    da_fhandle;    /* directory file handle */
  311.     char        *da_name;    /* name (up to NFS_MAXNAMLEN bytes) */
  312. };
  313.  
  314. /*
  315.  * NFS_OK part of directory operation result
  316.  */
  317. struct  nfsdrok {
  318.     fhandle_t    drok_fhandle;    /* result file handle */
  319.     struct nfsfattr    drok_attr;    /* result file attributes */
  320. };
  321.  
  322. /*
  323.  * Results from directory operation 
  324.  */
  325. struct  nfsdiropres {
  326.     enum nfsstat    dr_status;    /* result status */
  327.     union {
  328.         struct  nfsdrok    dr_drok_u;    /* NFS_OK result */
  329.     } dr_u;
  330. };
  331. #define    dr_drok        dr_u.dr_drok_u
  332. #define    dr_fhandle    dr_u.dr_drok_u.drok_fhandle
  333. #define    dr_attr        dr_u.dr_drok_u.drok_attr
  334.  
  335. /*
  336.  * arguments to setattr
  337.  */
  338. struct nfssaargs {
  339.     fhandle_t    saa_fh;        /* fhandle of file to be set */
  340.     struct nfssattr    saa_sa;        /* new attributes */
  341. };
  342.  
  343. /*
  344.  * arguments to create and mkdir
  345.  */
  346. struct nfscreatargs {
  347.     struct nfsdiropargs    ca_da;    /* file name to create and parent dir */
  348.     struct nfssattr        ca_sa;    /* initial attributes */
  349. };
  350.  
  351. /*
  352.  * arguments to link
  353.  */
  354. struct nfslinkargs {
  355.     fhandle_t        la_from;    /* old file */
  356.     struct nfsdiropargs    la_to;        /* new file and parent dir */
  357. };
  358.  
  359. /*
  360.  * arguments to rename
  361.  */
  362. struct nfsrnmargs {
  363.     struct nfsdiropargs rna_from;    /* old file and parent dir */
  364.     struct nfsdiropargs rna_to;    /* new file and parent dir */
  365. };
  366.  
  367. /*
  368.  * arguments to symlink
  369.  */
  370. struct nfsslargs {
  371.     struct nfsdiropargs    sla_from;    /* old file and parent dir */
  372.     char            *sla_tnm;    /* new name */
  373.     struct nfssattr        sla_sa;        /* attributes */
  374. };
  375.  
  376. /*
  377.  * NFS_OK part of statfs operation
  378.  */
  379. struct nfsstatfsok {
  380.     u_long fsok_tsize;    /* preferred transfer size in bytes */
  381.     u_long fsok_bsize;    /* fundamental file system block size */
  382.     u_long fsok_blocks;    /* total blocks in file system */
  383.     u_long fsok_bfree;    /* free blocks in fs */
  384.     u_long fsok_bavail;    /* free blocks avail to non-superuser */
  385. };
  386.  
  387. /*
  388.  * Results of statfs operation
  389.  */
  390. struct nfsstatfs {
  391.     enum nfsstat    fs_status;    /* result status */
  392.     union {
  393.         struct    nfsstatfsok fs_fsok_u;    /* NFS_OK result */
  394.     } fs_u;
  395. };
  396. #define    fs_fsok        fs_u.fs_fsok_u
  397. #define    fs_tsize    fs_u.fs_fsok_u.fsok_tsize
  398. #define    fs_bsize    fs_u.fs_fsok_u.fsok_bsize
  399. #define    fs_blocks    fs_u.fs_fsok_u.fsok_blocks
  400. #define    fs_bfree    fs_u.fs_fsok_u.fsok_bfree
  401. #define    fs_bavail    fs_u.fs_fsok_u.fsok_bavail
  402.  
  403. /*
  404.  * XDR routines for handling structures defined above
  405.  */
  406. bool_t xdr_attrstat();
  407. bool_t xdr_creatargs();
  408. bool_t xdr_diropargs();
  409. bool_t xdr_diropres();
  410. bool_t xdr_fhandle();
  411. bool_t xdr_linkargs();
  412. bool_t xdr_rddirargs();
  413. bool_t xdr_putrddirres();
  414. bool_t xdr_getrddirres();
  415. bool_t xdr_rdlnres();
  416. bool_t xdr_rdresult();
  417. bool_t xdr_readargs();
  418. bool_t xdr_rnmargs();
  419. bool_t xdr_saargs();
  420. bool_t xdr_slargs();
  421. bool_t xdr_writeargs();
  422. bool_t xdr_statfs();
  423.  
  424. #if    STATIC_ONLY
  425. bool_t xdr_drok();
  426. bool_t xdr_srok();
  427. bool_t xdr_rrok();
  428. bool_t xdr_fattr();
  429. bool_t xdr_sattr();
  430. bool_t xdr_timeval();
  431. #endif    STATIC_ONLY
  432.  
  433.  
  434. /*
  435.  * Remote file service routines
  436.  */
  437. #define    RFS_NULL    0
  438. #define    RFS_GETATTR    1
  439. #define    RFS_SETATTR    2
  440. #define    RFS_ROOT    3
  441. #define    RFS_LOOKUP    4
  442. #define    RFS_READLINK    5
  443. #define    RFS_READ    6
  444. #define    RFS_WRITECACHE    7
  445. #define    RFS_WRITE    8
  446. #define    RFS_CREATE    9
  447. #define    RFS_REMOVE    10
  448. #define    RFS_RENAME    11
  449. #define    RFS_LINK    12
  450. #define    RFS_SYMLINK    13
  451. #define    RFS_MKDIR    14
  452. #define    RFS_RMDIR    15
  453. #define    RFS_READDIR    16
  454. #define    RFS_STATFS    17
  455. #define    RFS_NPROC    18
  456.  
  457. /*
  458.  * remote file service numbers
  459.  */
  460. #define    NFS_PROGRAM    ((u_long)100003)
  461. #define    NFS_VERSION    ((u_long)2)
  462. #define    NFS_PORT    2049
  463.  
  464. #endif !__NFS_HEADER__
  465.