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