home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / nfs / rnode.h < prev   
C/C++ Source or Header  |  1993-10-19  |  3KB  |  125 lines

  1. /*      @(#)rnode.h    1.4 88/07/15 NFSSRC4.0 from 1.21 88/02/08 SMI      */
  2. /*    Copyright (C) 1988, Sun Microsystems Inc. */
  3.  
  4. /*
  5.  * HISTORY
  6.  * 06-Feb-90  Morris Meyer (mmeyer) at NeXT
  7.  *     Lock the vnode on a per-thread basis.
  8.  *
  9.  * 21-Dec-88  Peter King (king) at NeXT
  10.  *    NFS 4.0 Changes:  changed nfs_attr struct to vattr struct.
  11.  *              improved locking.
  12.  */
  13.  
  14. #ifndef _nfs_rnode_h
  15. #define _nfs_rnode_h
  16.  
  17. /*
  18.  * Remote file information structure.
  19.  * The rnode is the "inode" for remote files.  It contains all the
  20.  * information necessary to handle remote file on the client side.
  21.  */
  22. struct rnode {
  23.     struct rnode    *r_freef;    /* free list forward pointer */
  24.     struct rnode    *r_freeb;    /* free list back pointer */
  25.     struct rnode    *r_hash;    /* rnode hash chain */
  26.     struct vnode    r_vnode;    /* vnode for remote file */
  27.     fhandle_t    r_fh;        /* file handle */
  28.     u_short        r_flags;    /* flags, see below */
  29.     short        r_error;    /* async write error */
  30.     daddr_t        r_lastr;    /* last block read (read-ahead) */
  31. #ifdef MACH
  32.     struct thread    *r_thread;    /* Thread index for locker of rnode */
  33. #else
  34.     short        r_owner;    /* proc index for locker of rnode */
  35. #endif MACH
  36.     short        r_count;    /* number of rnode locks for r_owner */
  37.     struct ucred    *r_cred;    /* current credentials */
  38.     struct ucred    *r_unlcred;    /* unlinked credentials */
  39.     char        *r_unlname;    /* unlinked file name */
  40.     struct vnode    *r_unldvp;    /* parent dir of unlinked file */
  41.     struct vattr    r_attr;        /* cached vnode attributes */
  42.     struct timeval    r_attrtime;    /* time attributes become invalid */
  43. };
  44.  
  45. #define r_size    r_attr.va_size        /* file size in bytes */
  46.  
  47. /*
  48.  * Flags
  49.  */
  50. #define    RLOCKED        0x01        /* rnode is in use */
  51. #define    RWANT        0x02        /* someone wants a wakeup */
  52. #define    RATTRVALID    0x04        /* Attributes in the rnode are valid */
  53. #define    REOF        0x08        /* EOF encountered on read */
  54. #define    RDIRTY        0x10        /* dirty pages from write operation */
  55.  
  56. #if NeXT
  57. #define    RTIMEDOUT     0x20        /* timeout occured on lock */
  58. #endif
  59.  
  60. /*
  61.  * Convert between vnode and rnode
  62.  */
  63. #define    rtov(rp)    (&(rp)->r_vnode)
  64. #define    vtor(vp)    ((struct rnode *)((vp)->v_data))
  65. #define    vtofh(vp)    (&(vtor(vp)->r_fh))
  66. #define    rtofh(rp)    (&(rp)->r_fh)
  67.  
  68. /*
  69.  * Lock and unlock rnodes.
  70.  */
  71. #ifdef MACH
  72. #define    RLOCK(rp) { \
  73.     while (((rp)->r_flags & RLOCKED) && \
  74.         (rp)->r_thread != current_thread()) { \
  75.         (rp)->r_flags |= RWANT; \
  76.         (void) sleep((caddr_t)(rp), PINOD); \
  77.     } \
  78.     (rp)->r_thread = current_thread(); \
  79.     (rp)->r_count++; \
  80.     (rp)->r_flags |= RLOCKED; \
  81. }
  82. #else
  83. #define    RLOCK(rp) { \
  84.     while (((rp)->r_flags & RLOCKED) && \
  85.         (rp)->r_owner != u.u_procp - proc) { \
  86.         (rp)->r_flags |= RWANT; \
  87.         (void) sleep((caddr_t)(rp), PINOD); \
  88.     } \
  89.     (rp)->r_owner = u.u_procp - proc; \
  90.     (rp)->r_count++; \
  91.     (rp)->r_flags |= RLOCKED; \
  92. }
  93. #endif MACH
  94.  
  95. #if NeXT
  96.  
  97. #define    RUNLOCK(rp) { \
  98.     if (--(rp)->r_count < 0) \
  99.         panic("RUNLOCK"); \
  100.     if ((rp)->r_count == 0) { \
  101.         (rp)->r_flags &= ~(RLOCKED|RTIMEDOUT); \
  102.         if ((rp)->r_flags & RWANT) { \
  103.             (rp)->r_flags &= ~RWANT; \
  104.             wakeup((caddr_t)(rp)); \
  105.         } \
  106.     } \
  107. }
  108.  
  109. #else
  110.  
  111. #define    RUNLOCK(rp) { \
  112.     if (--(rp)->r_count < 0) \
  113.         panic("RUNLOCK"); \
  114.     if ((rp)->r_count == 0) { \
  115.         (rp)->r_flags &= ~RLOCKED; \
  116.         if ((rp)->r_flags & RWANT) { \
  117.             (rp)->r_flags &= ~RWANT; \
  118.             wakeup((caddr_t)(rp)); \
  119.         } \
  120.     } \
  121. }
  122.  
  123. #endif
  124. #endif !_nfs_rnode_h
  125.