home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / lan / soss.arj / SRC / NFS.H < prev    next >
C/C++ Source or Header  |  1991-04-11  |  13KB  |  482 lines

  1. /*
  2.  *  nfs.h -- header file for nfs server
  3.  *
  4.  *  Author:
  5.  *      See-Mong Tan, 6/12/88
  6.  *  Modified by:
  7.  *    Rich Braun @ Kronos, 2/15/91
  8.  *  Revision history:
  9.  *  
  10.  * $Log: nfs.h_v $
  11.  * Revision 1.4  1991/04/11  20:42:53  richb
  12.  * Release 3.1.
  13.  *
  14.  * Revision 1.3  1991/03/15  22:42:02  richb
  15.  * Changed revision date.
  16.  *
  17.  */
  18.  
  19. /* $Id: nfs.h_v 1.4 1991/04/11 20:42:53 richb Exp $ */
  20.  
  21. #define VERSION_NUM "3.1"
  22. #define VERSION_DATE "10 Apr 91"
  23.  
  24. #define NFS_PROGRAM ((u_long) 100003)
  25. #define NFS_VERSION ((u_long) 2)
  26. #define NFS_PORT 2049
  27.  
  28. /* procedure definitions for version two of NFS protocol */
  29. #define NFS_NULL 0
  30. #define NFS_GETATTR 1
  31. #define NFS_SETATTR 2
  32. #define NFS_ROOT 3        /* not supported */
  33. #define NFS_LOOKUP 4
  34. #define NFS_READLINK 5        /* not supported */
  35. #define NFS_READ 6
  36. #define NFS_WRITECACHE 7    /* not supported */
  37. #define NFS_WRITE 8
  38. #define NFS_CREATE 9
  39. #define NFS_REMOVE 10
  40. #define NFS_RENAME 11
  41. #define NFS_LINK 12        /* not supported in DOS */
  42. #define NFS_SYMLINK 13        /* not supported in DOS */
  43. #define NFS_MKDIR 14
  44. #define NFS_RMDIR 15
  45. #define NFS_READDIR 16
  46. #define NFS_STATFS 17
  47.  
  48.   /* initializes NFS server */
  49. extern bool_t nfs_init();
  50.  
  51. /* NFS server procedures */
  52.   /* does nothing */
  53. extern void nfs_null();
  54.   /* get file attributes */
  55. extern void nfs_getattr();
  56.   /* set file attributes */
  57. extern void nfs_setattr();
  58.   /* reads a file */
  59. extern void nfs_read();
  60.   /* writes a file */
  61. extern void nfs_write();
  62.   /* file system status */
  63. extern void nfs_statfs();
  64.   /* read directory */
  65. extern void nfs_readdir();
  66.   /* directory lookup */
  67. extern void nfs_lookup();
  68.   /* create file */
  69. extern void nfs_create();
  70.   /* make a directory */
  71. extern void nfs_mkdir();
  72.   /* remove a file */
  73. extern void nfs_remove();
  74.   /* remove a directory */
  75. extern void nfs_rmdir();
  76.   /* rename a file */
  77. extern void nfs_rename();
  78.   /* link a file */
  79. extern void nfs_link();
  80.   /* create symbolic link */
  81. extern void nfs_symlink();
  82.  
  83. /* error routines */
  84.   /* write when file system is read only */
  85. extern void nfserr_readonlyfs();
  86.   /* call was an error */
  87. extern void nfs_error();
  88.  
  89. /* imported from unfs.h -- SUN user level NFS file server */
  90.  
  91. /* %W% %E% UNFSSRC */
  92.  
  93. /*
  94.  * Copyright (c) 1986 Sun Microsystems, Inc.
  95.  */
  96.  
  97. #define    NFS_MAXDATA    512
  98. #define RD_SIZ    NFS_MAXDATA
  99. #define WR_SIZ    NFS_MAXDATA
  100. /* path and filename length parameters */
  101. #define    NFS_MAXNAMLEN    255
  102. #define    NFS_MAXPATHLEN    512
  103.  
  104. /*
  105.  * NFS mount option flags
  106.  * WARNING: These must not overlap the mount flags in vfs.h!
  107.  */
  108. #define    NFSMNT_SOFT    0x010000    /* soft mount (hard is default) */
  109. #define    NFSMNT_WSIZE    0x020000    /* set write size */
  110. #define    NFSMNT_RSIZE    0x040000    /* set read size */
  111.  
  112. /*
  113.  * Error status
  114.  * Should include all possible net errors.
  115.  * For now we just cast errno into an enum nfsstat.
  116.  */
  117. enum nfsstat {
  118.     NFS_OK = 0,            /* no error */
  119.     NFSERR_PERM=EPERM,        /* Not owner */
  120.     NFSERR_NOENT=ENOENT,        /* No such file or directory */
  121.     NFSERR_IO=EIO,            /* I/O error */
  122.     NFSERR_NXIO=ENXIO,        /* No such device or address */
  123.     NFSERR_ACCES=EACCES,        /* Permission denied */
  124.     NFSERR_EXIST=EEXIST,        /* File exists */
  125.     NFSERR_NODEV=ENODEV,        /* No such device */
  126.     NFSERR_NOTDIR=ENOTDIR,        /* Not a directory*/
  127.     NFSERR_ISDIR=EISDIR,        /* Is a directory */
  128.     NFSERR_FBIG=EFBIG,        /* File too large */
  129.     NFSERR_NOSPC=ENOSPC,        /* No space left on device */
  130.     NFSERR_ROFS=EROFS,        /* Read-only file system */
  131.     NFSERR_NAMETOOLONG=ENAMETOOLONG,/* File name too long */
  132.     NFSERR_NOTEMPTY=ENOTEMPTY,    /* Directory not empty */
  133.     NFSERR_DQUOT=EDQUOT,        /* Disc quota exceeded */
  134.     NFSERR_STALE=ESTALE,        /* Stale NFS file handle */
  135.     NFSERR_WFLUSH,            /* write cache flushed */
  136.     NFSERR_INVAL=EINVAL        /* invalid parameter */
  137. };
  138. #define    puterrno(error)        ((enum nfsstat)error)
  139. #define    geterrno(status)    ((int)status)
  140.  
  141. /*
  142.  * File types
  143.  */
  144. enum nfsftype {
  145.     NFNON = 0,
  146.     NFREG = 1,        /* regular file */
  147.     NFDIR = 2,        /* directory */
  148.     NFBLK = 3,        /* block special */
  149.     NFCHR = 4,        /* character special */
  150.     NFLNK = 5        /* symbolic link */
  151. };
  152.  
  153. /*
  154.  * Size of an fhandle in bytes
  155.  */
  156. #define    NFS_FHSIZE    32
  157.  
  158. /*
  159.  * File access handle
  160.  * This structure is supposed to be opaque from the client side.
  161.  * It is handed out by a server for the client to use in further
  162.  * file transactions.
  163.  */
  164. struct fhs {
  165.     dev_t    fh_fsid;             /* filesystem id */
  166.     u_long    fh_fno;                /* file number */
  167.     time_t    fh_fgen;            /* file generation */
  168.                         /* fh_fgen not used in SOS */
  169. };
  170.  
  171. /* the size of fhs varies between machines, and the FHANDLE can
  172.  * be at most 32 bytes.  This means that the length of the
  173.  * path name must vary.  This is invisible from the client
  174.  * side.  It is only to keep the code clean.
  175.  */
  176. #define FH_PN    NFS_FHSIZE - sizeof(struct fhs)
  177.  
  178. typedef struct {
  179.     struct fhs f;                /* file itself */
  180.     struct fhs p;                /* parent file */
  181.     char    fh_pn[FH_PN];            /* pathname */
  182. } fhandle_t;
  183.  
  184. /* pcomp_t not used in SOS */
  185. /*
  186.  * Component name
  187.  * This structure contains the component in a pathname.
  188.  */
  189. typedef struct {
  190.     char    p_comp[NFS_MAXNAMLEN+1];    /* component name */
  191. } pcomp_t;
  192.  
  193. /* pname_t not used in SOS */
  194. /*
  195.  * Pathname
  196.  * This structure contains the pathname to a file on the server side.
  197.  * It is mapped from the file handle.
  198.  */
  199. typedef struct {
  200.     char    p_name[NFS_MAXPATHLEN];    /* pathname */
  201. } pname_t;
  202.  
  203. /*
  204.  * Arguments to remote write and writecache
  205.  */
  206. struct nfswriteargs {
  207.     fhandle_t    wa_fhandle;    /* handle for file */
  208.     u_long        wa_begoff;    /* beginning byte offset in file */
  209.     u_long        wa_offset;      /* current byte offset in file */
  210.     u_long        wa_totcount;    /* total write count (to this offset)*/
  211.     u_long        wa_count;    /* size of this write */
  212.     char        *wa_data;    /* data to write (up to NFS_MAXDATA) */
  213. };
  214.  
  215.  
  216. /*
  217.  * File attributes
  218.  */
  219. struct nfsfattr {
  220.     enum nfsftype    na_type;    /* file type */
  221.     u_long        na_mode;    /* protection mode bits */
  222.     u_long        na_nlink;    /* # hard links */
  223.     u_long        na_uid;        /* owner user id */
  224.     u_long        na_gid;        /* owner group id */
  225.     u_long        na_size;    /* file size in bytes */
  226.     u_long        na_blocksize;    /* prefered block size */
  227.     u_long        na_rdev;    /* special device # */
  228.     u_long        na_blocks;    /* Kb of disk used by file */
  229.     u_long        na_fsid;    /* device # */
  230.     u_long        na_nodeid;    /* inode # */
  231.     struct timeval    na_atime;    /* time of last access */
  232.     struct timeval    na_mtime;    /* time of last modification */
  233.     struct timeval    na_ctime;     /* time of last change */
  234. };
  235.  
  236. /*
  237.  * Arguments to remote read
  238.  */
  239. struct nfsreadargs {
  240.     fhandle_t    ra_fhandle;    /* handle for file */
  241.     u_long        ra_offset;    /* byte offset in file */
  242.     u_long        ra_count;    /* immediate read count */
  243.     u_long        ra_totcount;    /* total read count (from this offset)*/
  244. };
  245.  
  246. /*
  247.  * Status OK portion of remote read reply
  248.  */
  249. struct nfsrrok {
  250.     struct nfsfattr    rrok_attr;    /* attributes, need for pagin*/
  251.     u_long        rrok_count;    /* bytes of data */
  252.     char        *rrok_data;    /* data (up to NFS_MAXDATA bytes) */
  253.     struct buf    *rrok_bp;    /* buffer pointer for bread */
  254.     struct vnode    *rrok_vp;    /* vnode assoc. with buffer */
  255. };
  256.  
  257. /*
  258.  * Reply from remote read
  259.  */
  260. struct nfsrdresult {
  261.     enum nfsstat    rr_status;        /* status of read */
  262.     int        rr_bufsize;        /* bytes allocated for buf */
  263.     union {
  264.         struct nfsrrok    rr_ok_u;    /* attributes, need for pagin*/
  265.     } rr_u;
  266. };
  267. #define    rr_ok        rr_u.rr_ok_u
  268. #define    rr_attr        rr_u.rr_ok_u.rrok_attr
  269. #define    rr_count    rr_u.rr_ok_u.rrok_count
  270. #define    rr_data        rr_u.rr_ok_u.rrok_data
  271. #define rr_bp        rr_u.rr_ok_u.rrok_bp
  272. #define rr_vp        rr_u.rr_ok_u.rrok_vp
  273.  
  274.  
  275. /*
  276.  * File attributes which can be set
  277.  */
  278. struct nfssattr {
  279.     u_long        sa_mode;    /* protection mode bits */
  280.     u_long        sa_uid;        /* owner user id */
  281.     u_long        sa_gid;        /* owner group id */
  282.     u_long        sa_size;    /* file size in bytes */
  283.     struct timeval    sa_atime;    /* time of last access */
  284.     struct timeval    sa_mtime;    /* time of last modification */
  285. };
  286.  
  287.  
  288. /*
  289.  * Reply status with file attributes
  290.  */
  291. struct nfsattrstat {
  292.     enum nfsstat    ns_status;        /* reply status */
  293.     union {
  294.         struct nfsfattr ns_attr_u;    /* NFS_OK: file attributes */
  295.     } ns_u;
  296. };
  297. #define    ns_attr    ns_u.ns_attr_u
  298.  
  299.  
  300. /*
  301.  * NFS_OK part of read sym link reply union
  302.  */
  303. struct nfssrok {
  304.     u_long    srok_count;    /* size of string */
  305.     char    *srok_data;    /* string (up to NFS_MAXPATHLEN bytes) */
  306. };
  307.  
  308. /*
  309.  * Result of reading symbolic link
  310.  */
  311. struct nfsrdlnres {
  312.     enum nfsstat    rl_status;        /* status of symlink read */
  313.     union {
  314.         struct nfssrok    rl_srok_u;    /* name of linked to */
  315.     } rl_u;
  316. };
  317. #define    rl_srok        rl_u.rl_srok_u
  318. #define    rl_count    rl_u.rl_srok_u.srok_count
  319. #define    rl_data        rl_u.rl_srok_u.srok_data
  320.  
  321.  
  322. /*
  323.  * Arguments to readdir
  324.  */
  325. struct nfsrddirargs {
  326.     fhandle_t rda_fh;    /* directory handle */
  327.     u_long rda_offset;    /* offset in directory (opaque) */
  328.     u_long rda_count;    /* number of directory bytes to read */
  329. };
  330.  
  331. /*
  332.  * NFS_OK part of readdir result
  333.  */
  334. struct nfsrdok {
  335.     u_long    rdok_offset;        /* next offset (opaque) */
  336.     u_long    rdok_size;        /* size in bytes of entries */
  337.     bool_t    rdok_eof;        /* true if last entry is in result*/
  338.     struct    udirect *rdok_entries;    /* variable number of entries */
  339. };
  340.  
  341. /*
  342.  * Readdir result
  343.  */
  344. struct nfsrddirres {
  345.     u_long        rd_bufsize;    /* size of client request (not xdr'ed)*/
  346.     enum nfsstat    rd_status;
  347.     union {
  348.         struct nfsrdok rd_rdok_u;
  349.     } rd_u;
  350. };
  351. #define    rd_rdok        rd_u.rd_rdok_u
  352. #define    rd_offset    rd_u.rd_rdok_u.rdok_offset
  353. #define    rd_size        rd_u.rd_rdok_u.rdok_size
  354. #define    rd_eof        rd_u.rd_rdok_u.rdok_eof
  355. #define    rd_entries    rd_u.rd_rdok_u.rdok_entries
  356.  
  357.  
  358. /*
  359.  * Arguments for directory operations
  360.  */
  361. struct nfsdiropargs {
  362.     fhandle_t    da_fhandle;    /* directory file handle */
  363.     char        *da_name;    /* name (up to NFS_MAXNAMLEN bytes) */
  364. };
  365.  
  366. /*
  367.  * NFS_OK part of directory operation result
  368.  */
  369. struct  nfsdrok {
  370.     fhandle_t    drok_fhandle;    /* result file handle */
  371.     struct nfsfattr    drok_attr;    /* result file attributes */
  372. };
  373.  
  374. /*
  375.  * Results from directory operation 
  376.  */
  377. struct  nfsdiropres {
  378.     enum nfsstat    dr_status;    /* result status */
  379.     union {
  380.         struct  nfsdrok    dr_drok_u;    /* NFS_OK result */
  381.     } dr_u;
  382. };
  383. #define    dr_drok        dr_u.dr_drok_u
  384. #define    dr_fhandle    dr_u.dr_drok_u.drok_fhandle
  385. #define    dr_attr        dr_u.dr_drok_u.drok_attr
  386.  
  387. /*
  388.  * arguments to setattr
  389.  */
  390. struct nfssaargs {
  391.     fhandle_t    saa_fh;        /* fhandle of file to be set */
  392.     struct nfssattr    saa_sa;        /* new attributes */
  393. };
  394.  
  395. /*
  396.  * arguments to create and mkdir
  397.  */
  398. struct nfscreatargs {
  399.     struct nfsdiropargs    ca_da;    /* file name to create and parent dir */
  400.     struct nfssattr        ca_sa;    /* initial attributes */
  401. };
  402.  
  403. /*
  404.  * arguments to link
  405.  */
  406. struct nfslinkargs {
  407.     fhandle_t        la_from;    /* old file */
  408.     struct nfsdiropargs    la_to;        /* new file and parent dir */
  409. };
  410.  
  411. /*
  412.  * arguments to rename
  413.  */
  414. struct nfsrnmargs {
  415.     struct nfsdiropargs rna_from;    /* old file and parent dir */
  416.     struct nfsdiropargs rna_to;    /* new file and parent dir */
  417. };
  418.  
  419. /*
  420.  * arguments to symlink
  421.  */
  422. struct nfsslargs {
  423.     struct nfsdiropargs    sla_from;    /* old file and parent dir */
  424.     char            *sla_tnm;    /* new name */
  425.     struct nfssattr        sla_sa;        /* attributes */
  426. };
  427.  
  428. /*
  429.  * NFS_OK part of statfs operation
  430.  */
  431. struct nfsstatfsok {
  432.     u_long fsok_tsize;    /* preferred transfer size in bytes */
  433.     u_long fsok_bsize;    /* fundamental file system block size */
  434.     u_long fsok_blocks;    /* total blocks in file system */
  435.     u_long fsok_bfree;    /* free blocks in fs */
  436.     u_long fsok_bavail;    /* free blocks avail to non-superuser */
  437. };
  438.  
  439. /*
  440.  * Results of statfs operation
  441.  */
  442. struct nfsstatfs {
  443.     enum nfsstat    fs_status;    /* result status */
  444.     union {
  445.         struct    nfsstatfsok fs_fsok_u;    /* NFS_OK result */
  446.     } fs_u;
  447. };
  448. #define    fs_fsok        fs_u.fs_fsok_u
  449. #define    fs_tsize    fs_u.fs_fsok_u.fsok_tsize
  450. #define    fs_bsize    fs_u.fs_fsok_u.fsok_bsize
  451. #define    fs_blocks    fs_u.fs_fsok_u.fsok_blocks
  452. #define    fs_bfree    fs_u.fs_fsok_u.fsok_bfree
  453. #define    fs_bavail    fs_u.fs_fsok_u.fsok_bavail
  454.  
  455. /*
  456.  * XDR routines for handling structures defined above
  457.  */
  458. bool_t xdr_attrstat();
  459. bool_t xdr_creatargs();
  460. bool_t xdr_diropargs();
  461. bool_t xdr_diropres();
  462. bool_t xdr_drok();
  463. bool_t xdr_fattr();
  464. bool_t xdr_fhandle();
  465. bool_t xdr_linkargs();
  466. bool_t xdr_rddirargs();
  467. bool_t xdr_putrddirres();
  468. bool_t xdr_getrddirres();
  469. bool_t xdr_rdlnres();
  470. bool_t xdr_rdresult();
  471. bool_t xdr_readargs();
  472. bool_t xdr_rnmargs();
  473. bool_t xdr_rrok();
  474. bool_t xdr_saargs();
  475. bool_t xdr_sattr();
  476. bool_t xdr_slargs();
  477. bool_t xdr_srok();
  478. bool_t xdr_timeval();
  479. bool_t xdr_writeargs();
  480. bool_t xdr_statfs();
  481.  
  482.