home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / sys / buf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  9.0 KB  |  232 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    from: @(#)buf.h    7.11 (Berkeley) 5/9/90
  34.  *    $Id: buf.h,v 1.9 1993/07/19 16:39:23 cgd Exp $
  35.  */
  36.  
  37. #ifndef _SYS_BUF_H_
  38. #define _SYS_BUF_H_
  39.  
  40. /*
  41.  * The header for buffers in the buffer pool and otherwise used
  42.  * to describe a block i/o request is given here.
  43.  *
  44.  * Each buffer in the pool is usually doubly linked into 2 lists:
  45.  * hashed into a chain by <dev,blkno> so it can be located in the cache,
  46.  * and (usually) on (one of several) queues.  These lists are circular and
  47.  * doubly linked for easy removal.
  48.  *
  49.  * There are currently three queues for buffers:
  50.  *    one for buffers which must be kept permanently (super blocks)
  51.  *     one for buffers containing ``useful'' information (the cache)
  52.  *    one for buffers containing ``non-useful'' information
  53.  *        (and empty buffers, pushed onto the front)
  54.  * The latter two queues contain the buffers which are available for
  55.  * reallocation, are kept in lru order.  When not on one of these queues,
  56.  * the buffers are ``checked out'' to drivers which use the available list
  57.  * pointers to keep track of them in their i/o active queues.
  58.  */
  59.  
  60. /*
  61.  * Bufhd structures used at the head of the hashed buffer queues.
  62.  * We only need three words for these, so this abbreviated
  63.  * definition saves some space.
  64.  */
  65. struct bufhd
  66. {
  67.     long    b_flags;        /* see defines below */
  68.     struct    buf *b_forw, *b_back;    /* fwd/bkwd pointer in chain */
  69. };
  70. struct buf
  71. {
  72.     long    b_flags;        /* too much goes here to describe */
  73.     struct    buf *b_forw, *b_back;    /* hash chain (2 way street) */
  74.     struct    buf *av_forw, *av_back;    /* position on free list if not BUSY */
  75.     struct    buf *b_blockf, **b_blockb;/* associated vnode */
  76. #define    b_actf    av_forw            /* alternate names for driver queue */
  77. #define    b_actl    av_back            /*    head - isn't history wonderful */
  78.     long    b_bcount;        /* transfer count */
  79.     long    b_bufsize;        /* size of allocated buffer */
  80. #define    b_active b_bcount        /* driver queue head: drive active */
  81.     short    b_error;        /* returned after I/O */
  82.     dev_t    b_dev;            /* major+minor device name */
  83.     union {
  84.         caddr_t b_addr;        /* low order core address */
  85.         int    *b_words;        /* words for clearing */
  86.         struct fs *b_fs;        /* superblocks */
  87.         struct csum *b_cs;        /* superblock summary information */
  88.         struct cg *b_cg;        /* cylinder group block */
  89.         struct dinode *b_dino;    /* ilist */
  90.         daddr_t *b_daddr;        /* indirect block */
  91.     } b_un;
  92.     daddr_t    b_lblkno;        /* logical block number */
  93.     daddr_t    b_blkno;        /* block # on device */
  94.     long    b_resid;        /* words not transferred after error */
  95. #define    b_errcnt b_resid        /* while i/o in progress: # retries */
  96.     struct  proc *b_proc;        /* proc doing physical or swap I/O */
  97.     int    (*b_iodone)();        /* function called by iodone */
  98.     struct    vnode *b_vp;        /* vnode for dev */
  99.     int    b_pfcent;        /* center page when swapping cluster */
  100.     struct    ucred *b_rcred;        /* ref to read credentials */
  101.     struct    ucred *b_wcred;        /* ref to write credendtials */
  102.     int    b_dirtyoff;        /* offset in buffer of dirty region */
  103.     int    b_dirtyend;        /* offset of end of dirty region */
  104.     caddr_t    b_saveaddr;        /* original b_addr for PHYSIO */
  105. };
  106.  
  107. #define    BQUEUES        4        /* number of free buffer queues */
  108.  
  109. #define    BQ_LOCKED    0        /* super-blocks &c */
  110. #define    BQ_LRU        1        /* lru, useful buffers */
  111. #define    BQ_AGE        2        /* rubbish */
  112. #define    BQ_EMPTY    3        /* buffer headers with no memory */
  113.  
  114. #ifdef    KERNEL
  115. #define    BUFHSZ    512
  116. #define RND    (MAXBSIZE/DEV_BSIZE)
  117. /* 20 Aug 92    BUFHASH*/
  118. #if    ((BUFHSZ&(BUFHSZ-1)) == 0)
  119. #define    BUFHASH(dvp, dblkno)    \
  120.     ((struct buf *)&bufhash[((int)(dvp)/sizeof(struct vnode)+(int)(dblkno))&(BUFHSZ-1)])
  121. #else
  122. #define    BUFHASH(dvp, dblkno)    \
  123.     ((struct buf *)&bufhash[((int)(dvp)/sizeof(struct vnode)+(int)(dblkno)) % BUFHSZ])
  124. #endif
  125.  
  126. extern struct    buf *buf;        /* the buffer pool itself */
  127. extern char    *buffers;
  128. extern int    nbuf;            /* number of buffer headers */
  129. extern int    bufpages;        /* number of memory pages in the buffer pool */
  130. extern struct    buf *swbuf;        /* swap I/O headers */
  131. extern int    nswbuf;
  132. extern struct    bufhd bufhash[BUFHSZ];    /* heads of hash lists */
  133. extern struct    buf bfreelist[BQUEUES];    /* heads of available lists */
  134. extern struct    buf bswlist;        /* head of free swap header list */
  135. extern struct    buf *bclnlist;        /* head of cleaned page list */
  136.  
  137. void    bufinit        __P((void));
  138. int    bread        __P((struct vnode *, daddr_t, int, struct ucred *,
  139.                 struct buf **));
  140. int    breada        __P((struct vnode *, daddr_t, int, daddr_t, int,
  141.                 struct ucred *, struct buf **));
  142. int    bwrite        __P((struct buf *));
  143. void    bdwrite        __P((struct buf *));
  144. void    bawrite        __P((struct buf *));
  145. void    brelse        __P((struct buf *));
  146. struct    buf *incore    __P((struct vnode *, daddr_t));
  147. struct    buf *getblk    __P((struct vnode *, daddr_t, int));
  148. struct    buf *geteblk    __P((int));
  149. void    allocbuf    __P((struct buf *, int));
  150. int    biowait        __P((struct buf *));
  151. void    biodone        __P((struct buf *));
  152.  
  153. u_int    minphys        __P((struct buf *));
  154. #endif
  155.  
  156. /*
  157.  * These flags are kept in b_flags.
  158.  */
  159. #define    B_WRITE        0x000000    /* non-read pseudo-flag */
  160. #define    B_READ        0x000001    /* read when I/O occurs */
  161. #define    B_DONE        0x000002    /* transaction finished */
  162. #define    B_ERROR        0x000004    /* transaction aborted */
  163. #define    B_BUSY        0x000008    /* not on av_forw/back list */
  164. #define    B_PHYS        0x000010    /* physical IO */
  165. #define    B_XXX        0x000020    /* was B_MAP, alloc UNIBUS on pdp-11 */
  166. #define    B_WANTED    0x000040    /* issue wakeup when BUSY goes off */
  167. #define    B_AGE        0x000080    /* delayed write for correct aging */
  168. #define    B_ASYNC        0x000100    /* don't wait for I/O completion */
  169. #define    B_DELWRI    0x000200    /* write at exit of avail list */
  170. #define    B_TAPE        0x000400    /* this is a magtape (no bdwrite) */
  171. #define    B_VMPAGE    0x000800    /* buffer from virtual memory */
  172. #define    B_MALLOC    0x001000    /* buffer from malloc space */
  173. #define    B_DIRTY        0x002000    /* dirty page to be pushed out async */
  174. #define    B_PGIN        0x004000    /* pagein op, so swap() can count it */
  175. #define    B_CACHE        0x008000    /* did bread find us in the cache ? */
  176. #define    B_INVAL        0x010000    /* does not contain valid info  */
  177. #define    B_LOCKED    0x020000    /* locked in core (not reusable) */
  178. #define    B_HEAD        0x040000    /* a buffer header, not a buffer */
  179. #define    B_BAD        0x100000    /* bad block revectoring in progress */
  180. #define    B_CALL        0x200000    /* call b_iodone from iodone */
  181. #define    B_RAW        0x400000    /* set by physio for raw transfers */
  182. #define    B_NOCACHE    0x800000    /* do not cache block after use */
  183.  
  184. /*
  185.  * Insq/Remq for the buffer hash lists.
  186.  */
  187. #define    bremhash(bp) { \
  188.     (bp)->b_back->b_forw = (bp)->b_forw; \
  189.     (bp)->b_forw->b_back = (bp)->b_back; \
  190. }
  191. #define    binshash(bp, dp) { \
  192.     (bp)->b_forw = (dp)->b_forw; \
  193.     (bp)->b_back = (dp); \
  194.     (dp)->b_forw->b_back = (bp); \
  195.     (dp)->b_forw = (bp); \
  196. }
  197.  
  198. /*
  199.  * Insq/Remq for the buffer free lists.
  200.  */
  201. #define    bremfree(bp) { \
  202.     (bp)->av_back->av_forw = (bp)->av_forw; \
  203.     (bp)->av_forw->av_back = (bp)->av_back; \
  204. }
  205. #define    binsheadfree(bp, dp) { \
  206.     (dp)->av_forw->av_back = (bp); \
  207.     (bp)->av_forw = (dp)->av_forw; \
  208.     (dp)->av_forw = (bp); \
  209.     (bp)->av_back = (dp); \
  210. }
  211. #define    binstailfree(bp, dp) { \
  212.     (dp)->av_back->av_forw = (bp); \
  213.     (bp)->av_back = (dp)->av_back; \
  214.     (dp)->av_back = (bp); \
  215.     (bp)->av_forw = (dp); \
  216. }
  217.  
  218. #define    iodone    biodone
  219. #define    iowait    biowait
  220.  
  221. /*
  222.  * Zero out a buffer's data portion.
  223.  */
  224. #define    clrbuf(bp) { \
  225.     bzero((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
  226.     (bp)->b_resid = 0; \
  227. }
  228. #define B_CLRBUF    0x1    /* request allocated buffer be cleared */
  229. #define B_SYNC        0x2    /* do all allocations synchronously */
  230.  
  231. #endif /* !_SYS_BUF_H_ */
  232.