home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilss / sockets / include / sys / h / buf < prev    next >
Encoding:
Text File  |  1995-01-11  |  7.7 KB  |  238 lines

  1. /*
  2.  * $Header: /ax/networking:include/sys/buf.h:networking  1.1  $
  3.  * $Source: /ax/networking:include/sys/buf.h: $
  4.  *
  5.  * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
  6.  *
  7.  * $Desc$
  8.  * $Log:    buf.h,v $
  9.  * Revision 1.1  95/01/11  10:18:57  kwelton
  10.  * Initial revision
  11.  * 
  12.  * Revision 1.4  88/10/10  16:12:54  keith
  13.  * Removed statically allocated buffer space, buffers are
  14.  * now allocated in the same page as u-areas.
  15.  * 
  16.  * Revision 1.3  88/06/17  20:18:19  beta
  17.  * Acorn Unix initial beta version
  18.  * 
  19.  */
  20. /* @(#)buf.h    1.4 87/05/15 3.2/4.3NFSSRC */
  21. /*
  22.  * Copyright (c) 1982, 1986 Regents of the University of California.
  23.  * All rights reserved.  The Berkeley software License Agreement
  24.  * specifies the terms and conditions for redistribution.
  25.  *
  26.  *    @(#)buf.h    7.1 (Berkeley) 6/4/86
  27.  */
  28.  
  29. #ifndef _BUF_
  30. #define _BUF_
  31.  
  32. /*
  33.  * The header for buffers in the buffer pool and otherwise used
  34.  * to describe a block i/o request is given here.  The routines
  35.  * which manipulate these things are given in bio.c.
  36.  *
  37.  * Each buffer in the pool is usually doubly linked into 2 lists:
  38.  * hashed into a chain by <dev,blkno> so it can be located in the cache,
  39.  * and (usually) on (one of several) queues.  These lists are circular and
  40.  * doubly linked for easy removal.
  41.  *
  42.  * There are currently three queues for buffers:
  43.  *    one for buffers which must be kept permanently (super blocks)
  44.  *     one for buffers containing ``useful'' information (the cache)
  45.  *    one for buffers containing ``non-useful'' information
  46.  *        (and empty buffers, pushed onto the front)
  47.  * The latter two queues contain the buffers which are available for
  48.  * reallocation, are kept in lru order.  When not on one of these queues,
  49.  * the buffers are ``checked out'' to drivers which use the available list
  50.  * pointers to keep track of them in their i/o active queues.
  51.  */
  52.  
  53. /*
  54.  * Bufhd structures used at the head of the hashed buffer queues.
  55.  * We only need three words for these, so this abbreviated
  56.  * definition saves some space.
  57.  */
  58. struct bufhd
  59. {
  60.     long    b_flags;        /* see defines below */
  61.     struct    buf *b_forw, *b_back;    /* fwd/bkwd pointer in chain */
  62. };
  63. struct buf
  64. {
  65.     long    b_flags;        /* too much goes here to describe */
  66.     struct    buf *b_forw, *b_back;    /* hash chain (2 way street) */
  67.     struct    buf *av_forw, *av_back;    /* position on free list if not BUSY */
  68. #define    b_actf    av_forw            /* alternate names for driver queue */
  69. #define    b_actl    av_back            /*    head - isn't history wonderful */
  70.     long    b_bcount;        /* transfer count */
  71.     long    b_bufsize;        /* size of allocated buffer */
  72. #define    b_active b_bcount        /* driver queue head: drive active */
  73.     short    b_error;        /* returned after I/O */
  74.     dev_t    b_dev;            /* major+minor device name */
  75.     union {
  76.         caddr_t b_addr;        /* low order core address */
  77.         int    *b_words;        /* words for clearing */
  78.         struct fs *b_fs;        /* superblocks */
  79.         struct csum *b_cs;        /* superblock summary information */
  80.         struct cg *b_cg;        /* cylinder group block */
  81.         struct dinode *b_dino;    /* ilist */
  82.         daddr_t *b_daddr;        /* indirect block */
  83.     } b_un;
  84.     daddr_t    b_blkno;        /* block # on device */
  85.     long    b_resid;        /* words not transferred after error */
  86. #define    b_errcnt b_resid        /* while i/o in progress: # retries */
  87.     struct  proc *b_proc;        /* proc doing physical or swap I/O */
  88.     int    (*b_iodone)();        /* function called by iodone */
  89.     struct    vnode *b_vp;        /* vnode associated with block */
  90.     int    b_pfcent;        /* center page when swapping cluster */
  91.  
  92.     /* ARM implementation specific (because I took the SYS-V Winchester Driver)  */
  93.     int    b_acts;            /* for temp. storage in drivers */
  94.     int    b_start;        /* request start time */    
  95.     int    io_start;        /* ... ditto ... */
  96.     int    b_qcnt;            /* outstanding job request counter */
  97.  
  98.     /* ARM implementation specific (because of cleanup) */
  99.     caddr_t b_p2addr;        /* virtual address of proc-2 page */
  100. };
  101.  
  102. #define    BQUEUES        4        /* number of free buffer queues */
  103.  
  104. #define    BQ_LOCKED    0        /* super-blocks &c */
  105. #define    BQ_LRU        1        /* lru, useful buffers */
  106. #define    BQ_AGE        2        /* rubbish */
  107. #define    BQ_EMPTY    3        /* buffer headers with no memory */
  108.  
  109. #ifdef    KERNEL
  110. #define    BUFHSZ    512
  111. #define RND    (MAXBSIZE/DEV_BSIZE)
  112. #if    ((BUFHSZ&(BUFHSZ-1)) == 0)
  113. #define    BUFHASH(dvp, dblkno)    \
  114.     ((struct buf *)&bufhash[((u_int)(dvp)+(((int)(dblkno))/RND))&(BUFHSZ-1)])
  115. #else
  116. #define    BUFHASH(dvp, dblkno)    \
  117.     ((struct buf *)&bufhash[((u_int)(dvp)+(((int)(dblkno))/RND)) % BUFHSZ])
  118. #endif
  119.  
  120. #ifdef  DYNALLOC
  121. struct    buf *buf;        /* the buffer pool itself */
  122. char    *buffers;
  123. #else    DYNALLOC
  124. struct    buf stat_buf[NBUF], *buf;
  125. #endif    DYNALLOC
  126. int    nbuf;            /* number of buffer headers */
  127. int    bufpages;        /* number of memory pages in the buffer pool */
  128. #ifdef    DYNALLOC
  129. struct    buf *swbuf;        /* swap I/O headers */
  130. #else    DYNALLOC
  131. struct    buf stat_swbuf[NSWBUF], *swbuf;
  132. #endif    DYNALLOC
  133. int    nswbuf;
  134. struct    bufhd bufhash[BUFHSZ];    /* heads of hash lists */
  135. struct    buf bfreelist[BQUEUES];    /* heads of available lists */
  136. struct    buf bswlist;        /* head of free swap header list */
  137. struct    buf *bclnlist;        /* head of cleaned page list */
  138.  
  139. struct    buf *alloc();
  140. struct    buf *realloccg();
  141. struct    buf *baddr();
  142. struct    buf *getblk();
  143. struct    buf *geteblk();
  144. struct    buf *getnewbuf();
  145. struct    buf *bread();
  146. struct    buf *breada();
  147. struct    vnode *bdevvp();
  148.  
  149. unsigned minphys();
  150. #endif
  151.  
  152. /*
  153.  * These flags are kept in b_flags.
  154.  */
  155. #define    B_WRITE        0x000000    /* non-read pseudo-flag */
  156. #define    B_READ        0x000001    /* read when I/O occurs */
  157. #define    B_DONE        0x000002    /* transaction finished */
  158. #define    B_ERROR        0x000004    /* transaction aborted */
  159. #define    B_BUSY        0x000008    /* not on av_forw/back list */
  160. #define    B_PHYS        0x000010    /* physical IO */
  161. #define    B_XXX        0x000020    /* was B_MAP, alloc UNIBUS on pdp-11 */
  162. #define    B_WANTED    0x000040    /* issue wakeup when BUSY goes off */
  163. #define    B_AGE        0x000080    /* delayed write for correct aging */
  164. #define    B_ASYNC        0x000100    /* don't wait for I/O completion */
  165. #define    B_DELWRI    0x000200    /* write at exit of avail list */
  166. #define    B_TAPE        0x000400    /* this is a magtape (no bdwrite) */
  167. #define    B_UAREA        0x000800    /* add u-area to a swap operation */
  168. #define    B_PAGET        0x001000    /* page in/out of page table space */
  169. #define    B_DIRTY        0x002000    /* dirty page to be pushed out async */
  170. #define    B_PGIN        0x004000    /* pagein op, so swap() can count it */
  171. #define    B_CACHE        0x008000    /* did bread find us in the cache ? */
  172. #define    B_INVAL        0x010000    /* does not contain valid info  */
  173. #define    B_LOCKED    0x020000    /* locked in core (not reusable) */
  174. #define    B_HEAD        0x040000    /* a buffer header, not a buffer */
  175. #define    B_BAD        0x100000    /* bad block revectoring in progress */
  176. #define    B_CALL        0x200000    /* call b_iodone from iodone */
  177. #define    B_NOCACHE    0x400000    /* don't cache block when released */
  178.  
  179. /*
  180.  * Insq/Remq for the buffer hash lists.
  181.  */
  182. #define    bremhash(bp) { \
  183.     (bp)->b_back->b_forw = (bp)->b_forw; \
  184.     (bp)->b_forw->b_back = (bp)->b_back; \
  185. }
  186. #define    binshash(bp, dp) { \
  187.     (bp)->b_forw = (dp)->b_forw; \
  188.     (bp)->b_back = (dp); \
  189.     (dp)->b_forw->b_back = (bp); \
  190.     (dp)->b_forw = (bp); \
  191. }
  192.  
  193. /*
  194.  * Insq/Remq for the buffer free lists.
  195.  */
  196. #define    bremfree(bp) { \
  197.     (bp)->av_back->av_forw = (bp)->av_forw; \
  198.     (bp)->av_forw->av_back = (bp)->av_back; \
  199. }
  200. #define    binsheadfree(bp, dp) { \
  201.     (dp)->av_forw->av_back = (bp); \
  202.     (bp)->av_forw = (dp)->av_forw; \
  203.     (dp)->av_forw = (bp); \
  204.     (bp)->av_back = (dp); \
  205. }
  206. #define    binstailfree(bp, dp) { \
  207.     (dp)->av_back->av_forw = (bp); \
  208.     (bp)->av_back = (dp)->av_back; \
  209.     (dp)->av_back = (bp); \
  210.     (bp)->av_forw = (dp); \
  211. }
  212.  
  213. /*
  214.  * Take a buffer off the free list it's on and
  215.  * mark it as being use (B_BUSY) by a device.
  216.  */
  217. #define    notavail(bp) { \
  218.     int x = splbio(); \
  219.     bremfree(bp); \
  220.     (bp)->b_flags |= B_BUSY; \
  221.     (void) splx(x); \
  222. }
  223.  
  224. #define    iodone    biodone
  225. #define    iowait    biowait
  226.  
  227. /*
  228.  * Zero out a buffer's data portion.
  229.  */
  230. #define    clrbuf(bp) { \
  231.     bzero((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
  232.     (bp)->b_resid = 0; \
  233. }
  234.  
  235. #endif _BUF_
  236.  
  237. /* EOF buf.h */
  238.