home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / buf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  8.1 KB  |  256 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_BUF_H
  11. #define _SYS_BUF_H
  12.  
  13. #ident    "@(#)/usr/include/sys/buf.h.sl 1.1 4.0 12/08/90 61476 AT&T-USL"
  14.  
  15. /*
  16.  *    Each buffer in the pool is usually doubly linked into 2 lists:
  17.  *    the device with which it is currently associated (always)
  18.  *    and also on a list of blocks available for allocation
  19.  *    for other use (usually).
  20.  *    The latter list is kept in last-used order, and the two
  21.  *    lists are doubly linked to make it easy to remove
  22.  *    a buffer from one list when it was found by
  23.  *    looking through the other.
  24.  *    A buffer is on the available list, and is liable
  25.  *    to be reassigned to another disk block, if and only
  26.  *    if it is not marked BUSY.  When a buffer is busy, the
  27.  *    available-list pointers can be used for other purposes.
  28.  *    Most drivers use the forward ptr as a link in their I/O active queue.
  29.  *    A buffer header contains all the information required to perform I/O.
  30.  *    Most of the routines which manipulate these things are in bio.c.
  31.  */
  32. typedef struct    buf {
  33.     uint    b_flags;        /* see defines below */
  34.     struct    buf *b_forw;        /* headed by d_tab of conf.c */
  35.     struct    buf *b_back;        /*  "  */
  36.     struct    buf *av_forw;        /* position on free list, */
  37.     struct    buf *av_back;        /*     if not BUSY*/
  38.     o_dev_t    b_dev;            /* major+minor device name */
  39.     unsigned b_bcount;        /* transfer count */
  40.     union {
  41.         caddr_t b_addr;        /* low order core address */
  42.         int    *b_words;        /* words for clearing */
  43.         daddr_t *b_daddr;        /* disk blocks */
  44.     } b_un;
  45.  
  46. #define paddr(X)    (paddr_t)(X->b_un.b_addr)
  47.  
  48.     daddr_t    b_blkno;        /* block # on device */
  49.     char    b_oerror;        /* OLD error field returned after I/O */
  50.     char    b_res;            /* XENIX Compatibility    */
  51.     ushort    b_cylin;        /* XENIX Compatibility    */
  52.     unsigned int b_resid;        /* words not transferred after error */
  53.     daddr_t    b_sector;        /* physical sector of disk request */
  54.     clock_t    b_start;        /* request start time */
  55.     struct  proc  *b_proc;        /* process doing physical or swap I/O */
  56.     struct    page  *b_pages;        /* page list for PAGEIO */
  57.     clock_t    b_reltime;      /* previous release time */
  58.     /* Begin new stuff */
  59. #define b_actf    av_forw
  60. #define    b_actl    av_back
  61. #define    b_active b_bcount
  62. #define    b_errcnt b_resid
  63.     long    b_bufsize;        /* size of allocated buffer */
  64.     int    (*b_iodone)();        /* function called by iodone */
  65.     struct    vnode *b_vp;        /* vnode associated with block */
  66.     struct     buf *b_chain;        /* chain together all buffers here */
  67.     int    b_reqcnt;        /* number of I/O request generated */
  68.     int    b_error;        /* expanded error field */
  69.     dev_t    b_edev;            /* expanded dev field */
  70.     char *b_private;        /* private data structure */
  71. } buf_t;
  72.  
  73. /*
  74.  * Bufhd structures used at the head of the hashed buffer queues.
  75.  * We only need three words for these, so this abbreviated
  76.  * definition saves some space.
  77.  */
  78. struct bufhd {
  79.     long    b_flags;        /* see defines below */
  80.     struct    buf *b_forw, *b_back;    /* fwd/bkwd pointer in chain */
  81. };
  82. struct diskhd {
  83.     long b_flags;                   /* not used, needed for consistency */
  84.      struct  buf *b_forw, *b_back;   /* queue of unit queues */
  85.      struct  buf *av_forw, *av_back; /* queue of bufs for this unit */
  86.      long    b_bcount;               /* active flag */
  87. };
  88.  
  89. extern    struct    buf    bfreelist;    /* head of available list */
  90. struct    pfree    {
  91.     int    b_flags;
  92.     struct    buf    *av_forw;
  93. };
  94. extern    struct    pfree    pfreelist;
  95. extern    int        pfreecnt;
  96. extern    struct    buf    pbuf[];
  97. #ifndef BUFDEFINE
  98. extern    char        *buffers[];
  99. #endif
  100.  
  101. /*
  102.  *    These flags are kept in b_flags.
  103.  */
  104. #define B_WRITE   0x0000    /* non-read pseudo-flag */
  105. #define B_READ    0x0001    /* read when I/O occurs */
  106. #define B_DONE    0x0002    /* transaction finished */
  107. #define B_ERROR   0x0004    /* transaction aborted */
  108. #define B_BUSY    0x0008    /* not on av_forw/back list */
  109. #define B_PHYS    0x0010    /* Physical IO potentially using UNIBUS map */
  110. #define B_MAP     0x0020    /* This block has the UNIBUS map allocated */
  111. #define B_WANTED  0x0040    /* issue wakeup when BUSY goes off */
  112. #define B_AGE     0x0080    /* delayed write for correct aging */
  113. #define B_ASYNC   0x0100    /* don't wait for I/O completion */
  114. #define B_DELWRI  0x0200    /* delayed write - wait until buffer needed */
  115. #define B_OPEN    0x0400    /* open routine called */
  116. #define B_STALE   0x0800
  117. #define B_VERIFY  0x1000
  118. #define B_FORMAT  0x2000
  119. #define B_S52K      0x8000    /* 2k buffer flag */
  120. #define B_PRIVLG  0xf000    /* privileged operation (internal driver use) */
  121.  
  122. /* fix these numbers; remove ones we don't need */
  123. #define    B_PAGEIO    0x10000        /* do I/O to pages on bp->p_pages */
  124. #define    B_DONTNEED    0x20000        /* after write, need not be cached */
  125. #define    B_TAPE        0x40000        /* this is a magtape (no bdwrite) */
  126. #define    B_UAREA        0x80000        /* add u-area to a swap operation */
  127. #define    B_REMAPPED    0x100000    /* buffer is kernel addressable */
  128. #define    B_FREE        0x200000    /* free page when done */
  129. #define    B_PGIN        0x400000    /* pagein op, so swap() can count it */
  130. #define    B_CACHE        0x800000    /* did bread find us in the cache ? */
  131. #define    B_INVAL        0x1000000    /* does not contain valid info  */
  132. #define    B_FORCE        0x2000000    /* semi-permanent removal from cache */
  133. #define    B_HEAD        0x4000000    /* a buffer header, not a buffer */
  134. #define    B_NOCACHE    0x8000000    /* don't cache block when released */
  135. #define    B_BAD        0x10000000    /* bad block revectoring in progress */
  136. #define B_KERNBUF    0x20000000    /* buffer is a kernel buffer */
  137. #define    B_DMA_REMAPPED    0x40000000    /* > 16MB DMA remap */
  138. #define    B_RAIO        0x80000000    /* raw disk async I/O */
  139.  
  140. /*
  141.  * Insq/Remq for the buffer hash lists (used by pageio).
  142.  */
  143. #define    bremhash(bp) { \
  144.     (bp)->b_back->b_forw = (bp)->b_forw; \
  145.     (bp)->b_forw->b_back = (bp)->b_back; \
  146. }
  147. #define    binshash(bp, dp) { \
  148.     (bp)->b_forw = (dp)->b_forw; \
  149.     (bp)->b_back = (dp); \
  150.     (dp)->b_forw->b_back = (bp); \
  151.     (dp)->b_forw = (bp); \
  152. }
  153.  
  154. /*
  155.  * Insq/Remq for the buffer free lists.
  156.  */
  157. #define    bremfree(bp) { \
  158.     (bp)->av_back->av_forw = (bp)->av_forw; \
  159.     (bp)->av_forw->av_back = (bp)->av_back; \
  160. }
  161. #define    binsheadfree(bp, dp) { \
  162.     (dp)->av_forw->av_back = (bp); \
  163.     (bp)->av_forw = (dp)->av_forw; \
  164.     (dp)->av_forw = (bp); \
  165.     (bp)->av_back = (dp); \
  166. }
  167. #define    binstailfree(bp, dp) { \
  168.     (dp)->av_back->av_forw = (bp); \
  169.     (bp)->av_back = (dp)->av_back; \
  170.     (dp)->av_back = (bp); \
  171.     (bp)->av_forw = (dp); \
  172. }
  173.  
  174. /*
  175.  *    Fast access to buffers in cache by hashing.
  176.  */
  177.  
  178. #define bhash(d, b)    ((struct buf *)&hbuf[((int)d+(int)b)&v.v_hmask])
  179.  
  180. struct    hbuf {
  181.     int    b_flags;
  182.     struct    buf    *b_forw;
  183.     struct    buf    *b_back;
  184.     int    b_pad;            /* round size to 2^n */
  185. };
  186.  
  187. extern    struct    hbuf    hbuf[];
  188.  
  189. /*
  190.  * Pick up the device's error number and pass it to the user;
  191.  * if there is an error but the number is 0 set a generalized code
  192.  */
  193. #define geterror(bp) \
  194.     (((bp)->b_flags & B_ERROR) == 0 ? 0 : \
  195.     (bp)->b_error ? (bp)->b_error : \
  196.     (bp)->b_oerror ? (bp)->b_oerror : EIO)
  197. /*
  198.  * Unlink a buffer from the available list and mark it busy.
  199.  * (internal interface)
  200.  */
  201. #define notavail(bp) \
  202. {\
  203.     register s;\
  204. \
  205.     s = spl6();\
  206.     (bp)->av_back->av_forw = (bp)->av_forw;\
  207.     (bp)->av_forw->av_back = (bp)->av_back;\
  208.     (bp)->b_flags |= B_BUSY;\
  209.     bfreelist.b_bcount--;\
  210.     splx(s);\
  211. }
  212.  
  213. struct buf    *bread();
  214. struct buf    *breada();
  215. void        bwrite();
  216. void        bdwrite();
  217. void        bawrite();
  218. void        brelse();
  219. int        incore();
  220. struct buf    *getfreeblk();
  221. struct buf    *getblk();
  222. struct buf    *ngeteblk();
  223. struct buf    *geteblk();
  224. int        iowait();
  225. void        iodone();
  226. void        clrbuf();
  227. void        bflush();
  228. void        blkflush();
  229. void        bdflush();
  230. void        bdwait();
  231. void        binval();
  232. void        binit();
  233. int        biowait();
  234. int        get_error();
  235. struct buf    *pageio_setup();
  236. void        pageio_done();
  237. void        biodone();
  238. void        buf_breakup();
  239.  
  240. #if defined(__STDC__)
  241. extern void dma_breakup(void (*)(), struct buf *);
  242. extern void dma_pageio(void (*)(), struct buf *);
  243. extern void dma_access(u_char, u_int, u_int, u_char, u_char);
  244. #else
  245. extern void dma_breakup();
  246. extern void dma_pageio();
  247. extern void dma_access();
  248. #endif
  249.  
  250. #ifdef i386
  251. #define     bimap(bp)    ((caddr_t)(paddr(bp)))
  252. #endif
  253.  
  254. #define bigetl(bp,cp) (*(long *)((paddr(bp))+cp))
  255. #endif    /* _SYS_BUF_H */
  256.