home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / buf.h < prev    next >
Text File  |  1993-10-19  |  7KB  |  225 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)buf.h    7.1 (Berkeley) 6/4/86
  7.  *
  8.  * History
  9.  * 05-Jul-90    Doug Mitchell at NeXT
  10.  *    Added B_KERNSPACE flag.
  11.  */
  12.  
  13. #ifndef    _SYS_BUF_
  14. #define    _SYS_BUF_
  15.  
  16. #import <sys/types.h>
  17.  
  18. /*
  19.  * The header for buffers in the buffer pool and otherwise used
  20.  * to describe a block i/o request is given here.  The routines
  21.  * which manipulate these things are given in bio.c.
  22.  *
  23.  * Each buffer in the pool is usually doubly linked into 2 lists:
  24.  * hashed into a chain by <dev,blkno> so it can be located in the cache,
  25.  * and (usually) on (one of several) queues.  These lists are circular and
  26.  * doubly linked for easy removal.
  27.  *
  28.  * There are currently three queues for buffers:
  29.  *    one for buffers which must be kept permanently (super blocks)
  30.  *     one for buffers containing ``useful'' information (the cache)
  31.  *    one for buffers containing ``non-useful'' information
  32.  *        (and empty buffers, pushed onto the front)
  33.  * The latter two queues contain the buffers which are available for
  34.  * reallocation, are kept in lru order.  When not on one of these queues,
  35.  * the buffers are ``checked out'' to drivers which use the available list
  36.  * pointers to keep track of them in their i/o active queues.
  37.  */
  38.  
  39. /*
  40.  * Bufhd structures used at the head of the hashed buffer queues.
  41.  * We only need three words for these, so this abbreviated
  42.  * definition saves some space.
  43.  */
  44. struct bufhd
  45. {
  46.     long    b_flags;        /* see defines below */
  47.     struct    buf *b_forw, *b_back;    /* fwd/bkwd pointer in chain */
  48. };
  49. struct buf
  50. {
  51.     long    b_flags;        /* too much goes here to describe */
  52.     struct    buf *b_forw, *b_back;    /* hash chain (2 way street) */
  53.     struct    buf *av_forw, *av_back;    /* position on free list if not BUSY */
  54. #define    b_actf    av_forw            /* alternate names for driver queue */
  55. #define    b_actl    av_back            /*    head - isn't history wonderful */
  56.     long    b_bcount;        /* transfer count */
  57.     long    b_bufsize;        /* size of allocated buffer */
  58. #define    b_active b_bcount        /* driver queue head: drive active */
  59.     short    b_error;        /* returned after I/O */
  60.     dev_t    b_dev;            /* major+minor device name */
  61.     union {
  62.         caddr_t b_addr;        /* low order core address */
  63.         int    *b_words;        /* words for clearing */
  64.         struct fs *b_fs;        /* superblocks */
  65.         struct csum *b_cs;        /* superblock summary information */
  66.         struct cg *b_cg;        /* cylinder group block */
  67.         struct dinode *b_dino;    /* ilist */
  68.         daddr_t *b_daddr;        /* indirect block */
  69.     } b_un;
  70.     daddr_t    b_blkno;        /* block # on device */
  71.     long    b_resid;        /* words not transferred after error */
  72. #define    b_errcnt b_resid        /* while i/o in progress: # retries */
  73.     struct  proc *b_proc;        /* proc doing physical or swap I/O */
  74.     int    (*b_iodone)();        /* function called by iodone */
  75.     int    b_pfcent;        /* center page when swapping cluster */
  76. #ifdef    NeXT
  77.     int    b_sort_key;        /* used by disk sort */
  78.     int    b_rtpri;        /* realtime priority */
  79. #define    RTPRI_NONE    0
  80. #define    RTPRI_MIN    1
  81. #define    RTPRI_MAX    127
  82. #endif    NeXT
  83.     struct  vnode *b_vp;            /* vnode associated with block */
  84. };
  85.  
  86. #define    BQUEUES        4        /* number of free buffer queues */
  87.  
  88. #define    BQ_LOCKED    0        /* super-blocks &c */
  89. #define    BQ_LRU        1        /* lru, useful buffers */
  90. #define    BQ_AGE        2        /* rubbish */
  91. #define    BQ_EMPTY    3        /* buffer headers with no memory */
  92.  
  93. #ifdef    KERNEL
  94. #if    NeXT
  95. #define    BUFHSZ    16
  96. #else    NeXT
  97. #define    BUFHSZ    512
  98. #endif    NeXT
  99. #define RND    (MAXBSIZE/1024)
  100. #define    BUFHASH(dvp, dblkno)    \
  101.     ((struct buf *)&bufhash[((u_int)(dvp)+(((int)(dblkno))/RND)) % BUFHSZ])
  102.  
  103. struct    buf *buf;        /* the buffer pool itself */
  104. char    *buffers;
  105. int    nbuf;            /* number of buffer headers */
  106. int    bufpages;        /* number of memory pages in the buffer pool */
  107. struct    bufhd bufhash[BUFHSZ];    /* heads of hash lists */
  108. struct    buf bfreelist[BQUEUES];    /* heads of available lists */
  109. #if NeXT
  110. struct    buf *swbuf;        
  111. struct    buf *swbuf_freelist;        
  112. struct    buf *swbuf_cleanlist;        
  113. int     nswbuf;        
  114. #endif
  115.  
  116. struct    buf *alloc();
  117. struct    buf *realloccg();
  118. struct    buf *baddr();
  119. struct    buf *getblk();
  120. struct    buf *geteblk();
  121. struct    buf *getnewbuf();
  122. struct    buf *bread();
  123. struct    buf *breada();
  124. #if    NeXT
  125. struct    buf *getemptybuf();
  126. struct    buf *getpblk();
  127. struct    buf *breadp();
  128. #endif    NeXT
  129. struct    vnode *bdevvp();    /* Added for use by the specfs routines */
  130.  
  131. unsigned minphys();
  132. #endif
  133.  
  134. /*
  135.  * These flags are kept in b_flags.
  136.  */
  137. #define    B_WRITE        0x00000000    /* non-read pseudo-flag */
  138. #define    B_READ        0x00000001    /* read when I/O occurs */
  139. #define    B_DONE        0x00000002    /* transaction finished */
  140. #define    B_ERROR        0x00000004    /* transaction aborted */
  141. #define    B_BUSY        0x00000008    /* not on av_forw/back list */
  142. #define    B_PHYS        0x00000010    /* physical IO */
  143. #define    B_XXX        0x00000020    /* was B_MAP, alloc UNIBUS on pdp-11 */
  144. #define    B_WANTED    0x00000040    /* issue wakeup when BUSY goes off */
  145. #define    B_AGE        0x00000080    /* delayed write for correct aging */
  146. #define    B_ASYNC        0x00000100    /* don't wait for I/O completion */
  147. #define    B_DELWRI    0x00000200    /* write at exit of avail list */
  148. #define    B_TAPE        0x00000400    /* this is a magtape (no bdwrite) */
  149. #if NeXT
  150. #define    B_PAGEOUT    0x00000800    /* Pageout operation */
  151. #define    B_PAGEIN    0x00001000    /* Pagein operation */
  152. #else
  153. #define    B_UAREA        0x00000800    /* add u-area to a swap operation */
  154. #define    B_PAGET        0x00001000    /* page in/out of page table space */
  155. #define    B_PGIN        0x00004000    /* pagein op, so swap() can count it */
  156. #endif
  157. #define    B_DIRTY        0x00002000    /* dirty page to be pushed out async */
  158. #define    B_CACHE        0x00008000    /* did bread find us in the cache ? */
  159. #define    B_INVAL        0x00010000    /* does not contain valid info  */
  160. #define    B_LOCKED    0x00020000    /* locked in core (not reusable) */
  161. #define    B_HEAD        0x00040000    /* a buffer header, not a buffer */
  162. #define    B_BAD        0x00100000    /* bad block revectoring in progress */
  163. #define    B_CALL        0x00200000    /* call b_iodone from iodone */
  164. #define    B_NOCACHE    0x00400000    /* don't cache block when released */
  165. #define B_PRIVATE    0x02000000    /* memory attached to buffer is private */
  166. #define B_KERNSPACE    0x04000000    /* physical I/O to kernel space */
  167.  
  168. /*
  169.  * Insq/Remq for the buffer hash lists.
  170.  */
  171. #define    bremhash(bp) { \
  172.     (bp)->b_back->b_forw = (bp)->b_forw; \
  173.     (bp)->b_forw->b_back = (bp)->b_back; \
  174. }
  175. #define    binshash(bp, dp) { \
  176.     (bp)->b_forw = (dp)->b_forw; \
  177.     (bp)->b_back = (dp); \
  178.     (dp)->b_forw->b_back = (bp); \
  179.     (dp)->b_forw = (bp); \
  180. }
  181.  
  182. /*
  183.  * Insq/Remq for the buffer free lists.
  184.  */
  185. #define    bremfree(bp) { \
  186.     (bp)->av_back->av_forw = (bp)->av_forw; \
  187.     (bp)->av_forw->av_back = (bp)->av_back; \
  188. }
  189. #define    binsheadfree(bp, dp) { \
  190.     (dp)->av_forw->av_back = (bp); \
  191.     (bp)->av_forw = (dp)->av_forw; \
  192.     (dp)->av_forw = (bp); \
  193.     (bp)->av_back = (dp); \
  194. }
  195. #define    binstailfree(bp, dp) { \
  196.     (dp)->av_back->av_forw = (bp); \
  197.     (bp)->av_back = (dp)->av_back; \
  198.     (dp)->av_back = (bp); \
  199.     (bp)->av_forw = (dp); \
  200. }
  201.  
  202. /*
  203.  * Take a buffer off the free list it's on and
  204.  * mark it as being use (B_BUSY) by a device.
  205.  */
  206. #define    notavail(bp) { \
  207.     int x = splbio(); \
  208.     bremfree(bp); \
  209.     (bp)->b_flags |= B_BUSY; \
  210.     (void) splx(x); \
  211. }
  212.  
  213. #define    iodone    biodone
  214. #define    iowait    biowait
  215.  
  216. /*
  217.  * Zero out a buffer's data portion.
  218.  */
  219. #define    clrbuf(bp) { \
  220.     blkclr((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
  221.     (bp)->b_resid = 0; \
  222. }
  223.  
  224. #endif    _SYS_BUF_
  225.