home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / sys / buf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  9.5 KB  |  252 lines

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