home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / include / sys / buf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-26  |  5.2 KB  |  164 lines

  1. /*    Copyright (c) 1984, 1986, 1987, 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8. /*    Copyright (c) 1987, 1988 Microsoft Corporation    */
  9. /*      All Rights Reserved    */
  10.  
  11. /*    This Module contains Proprietary Information of Microsoft  */
  12. /*    Corporation and should be treated as Confidential.       */
  13.  
  14. #ident    "@(#)head.sys:buf.h    1.5.1.4"
  15.  
  16. /*
  17.  *    Each buffer in the pool is usually doubly linked into 2 lists:
  18.  *    the device with which it is currently associated (always)
  19.  *    and also on a list of blocks available for allocation
  20.  *    for other use (usually).
  21.  *    The latter list is kept in last-used order, and the two
  22.  *    lists are doubly linked to make it easy to remove
  23.  *    a buffer from one list when it was found by
  24.  *    looking through the other.
  25.  *    A buffer is on the available list, and is liable
  26.  *    to be reassigned to another disk block, if and only
  27.  *    if it is not marked BUSY.  When a buffer is busy, the
  28.  *    available-list pointers can be used for other purposes.
  29.  *    Most drivers use the forward ptr as a link in their I/O active queue.
  30.  *    A buffer header contains all the information required to perform I/O.
  31.  *    Most of the routines which manipulate these things are in bio.c.
  32.  *
  33.  *      WARNING:  do not change size of the buf structure (sys/buf.h) without 
  34.  *    making a corresponding size change in the rbuf structure (sys/rbuf.h), 
  35.  *      and vice versa).  The two structures define the two possible formats 
  36.  *    of the buffer header (the format used depends on whether the buffer 
  37.  *    contains local data or RFS data).  
  38.  *
  39.  *      This overlay of the two structures is an interim solution
  40.  *    that is expected to change in a future release.  Users
  41.  *    should be aware that the rbuf structure will probably go
  42.  *    away at that time.
  43.  */
  44. typedef struct    buf
  45. {
  46.     int    b_flags;        /* see defines below */
  47.     struct    buf *b_forw;        /* headed by d_tab of conf.c */
  48.     struct    buf *b_back;        /*  "  */
  49.     struct    buf *av_forw;        /* position on free list, */
  50.     struct    buf *av_back;        /*     if not BUSY*/
  51.     dev_t    b_dev;            /* major+minor device name */
  52.     unsigned b_bcount;        /* transfer count */
  53.     union {
  54.         caddr_t b_addr;        /* low order core address */
  55.         int    *b_words;        /* words for clearing */
  56.         daddr_t *b_daddr;        /* disk blocks */
  57.     } b_un;
  58.  
  59. #define paddr(X)    (paddr_t)(X->b_un.b_addr)
  60.  
  61.     daddr_t    b_blkno;        /* block # on device */
  62.     char    b_error;        /* returned after I/O */
  63.     char    b_res;            /* XENIX Compatibility  */
  64.     ushort  b_cylin;        /* XENIX Compatibility  */
  65.     unsigned int b_resid;        /* words not transferred after error */
  66.     daddr_t b_sector;        /* physical sector of disk request */
  67.     time_t    b_start;        /* request start time */
  68.     struct  proc  *b_proc;        /* process doing physical or swap I/O */
  69.     unsigned long    b_reltime;      /* previous release time */
  70. } buf_t;
  71.  
  72. extern    struct    buf    buf[];        /* The buffer pool itself */
  73. extern    struct    buf    bfreelist;    /* head of available list */
  74. struct    pfree    {
  75.     int    b_flags;
  76.     struct    buf    *av_forw;
  77. };
  78. extern    struct    pfree    pfreelist;
  79. extern    int        pfreecnt;
  80. extern    struct    buf    pbuf[];
  81. #ifndef BUFDEFINE
  82. extern    char        *buffers[];
  83. #endif
  84.  
  85. extern  int    s52khash;        /* 2k buffer structures */
  86. extern struct buf s52kbuf[];
  87. extern struct buf s52kflist;
  88. #ifndef BUFDEFINE
  89. extern char    *s52kbuffers[];
  90. #endif
  91. extern struct    hbuf    s52khbuf[];
  92.  
  93.  
  94. /*
  95.  *    These flags are kept in b_flags.
  96.  */
  97. #define B_WRITE   0x0000    /* non-read pseudo-flag */
  98. #define B_READ    0x0001    /* read when I/O occurs */
  99. #define B_DONE    0x0002    /* transaction finished */
  100. #define B_ERROR   0x0004    /* transaction aborted */
  101. #define B_BUSY    0x0008    /* not on av_forw/back list */
  102. #define B_PHYS    0x0010    /* Physical IO potentially using UNIBUS map */
  103. #define B_MAP     0x0020    /* This block has the UNIBUS map allocated */
  104. #define B_WANTED  0x0040    /* issue wakeup when BUSY goes off */
  105. #define B_AGE     0x0080    /* delayed write for correct aging */
  106. #define B_ASYNC   0x0100    /* don't wait for I/O completion */
  107. #define B_DELWRI  0x0200    /* delayed write - wait until buffer needed */
  108. #define B_OPEN    0x0400    /* open routine called */
  109. #define B_STALE   0x0800
  110. #define B_VERIFY  0x1000
  111. #define B_FORMAT  0x2000
  112. #define B_REMOTE  0x4000    /* buffer contains remote (RFS) data */
  113. #define B_S52K      0x8000    /* 2k buffer flag */
  114. #define B_PRIVLG  0xf000    /* privileged operation (internal dirver use) */
  115.  
  116. /*
  117.  *    Fast access to buffers in cache by hashing.
  118.  */
  119.  
  120. #define bhash(d,b)    ((struct buf *)&hbuf[((int)d+(int)b)&v.v_hmask])
  121.  
  122. struct    hbuf
  123. {
  124.     int    b_flags;
  125.     struct    buf    *b_forw;
  126.     struct    buf    *b_back;
  127.     int    b_pad;            /* round size to 2^n */
  128. };
  129.  
  130. extern    struct    hbuf    hbuf[];
  131.  
  132. /*
  133.  * Pick up the device's error number and pass it to the user;
  134.  * if there is an error but the number is 0 set a generalized code
  135.  */
  136. #define geterror(bp) \
  137. {\
  138. \
  139.     if ((bp)->b_flags&B_ERROR)\
  140.         if ((u.u_error = (bp)->b_error)==0)\
  141.             u.u_error = EIO;\
  142. }
  143. /*
  144.  * Unlink a buffer from the available list and mark it busy.
  145.  * (internal interface)
  146.  */
  147. #define notavail(bp) \
  148. {\
  149.     register s;\
  150. \
  151.     s = spl6();\
  152.     bp->av_back->av_forw = bp->av_forw;\
  153.     bp->av_forw->av_back = bp->av_back;\
  154.     bp->b_flags |= B_BUSY;\
  155.     bfreelist.b_bcount--;\
  156.     splx(s);\
  157. }
  158.  
  159. #ifdef i386
  160. #define    bimap(bp)    ((caddr_t)(paddr(bp)))
  161. #endif
  162.  
  163. #define bigetl(bp,cp) (*(long *)((paddr(bp))+cp))
  164.