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