code:struct buf - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

4500 /*

4501  * Each buffer in the pool is usually doubly linked into two

4502  * lists: for the device with which it is currently associat-

4503  * ed (always) and also for a list of blocks available for

4504  * allocation for other use (usually).

4505  * The latter list is kept in last-used order, and the two

4506  * lists are doubly linked to make it easy to remove

4507  * a buffer from one list when it was found by

4508  * looking through the other.

4509  * A buffer is on the available list, and is liable

4510  * to be reassigned to another disk block, if and only

4511  * if it is not marked BUSY. When a buffer is busy, the

4512  * available-list pointers can be used for other purposes.

4513  * Most drivers use the forward ptr as a link in their I/O

4514  * active queue.

4515  * A buffer header contains all the information required

4516  * to perform I/O.

4517  * Most of the routines which manipulate these things

4518  * are in bio.c.

4519  */

4520 struct buf

4521 {

4522     int b_flags; /* see defines below */

  • 标志位
  • 标志常量定义参见 buf.h
4523     struct buf *b_forw; /* headed by devtab of b_dev */

4524     struct buf *b_back; /* " */

4525     struct buf *av_forw; /* position on free list, */

4526     struct buf *av_back; /* if not BUSY*/

4527     int b_dev; /* major+minor device name */
  • 设备号
  • 主设备号 + 从设备号
4528     int b_wcount; /* transfer count (usu. words) */
  • 缓存块与磁盘进行I/O时的待传输字数
4529     char *b_addr; /* low order core address */
  • 一般使用时,指向对应的缓存块
  • 作为交换区缓存管理块使用时,为对应缓存块内存起始地址的低16位
4530     char *b_xmem; /* high order core address */
  • 作为交换区缓存管理块使用时,对应缓存块内存起始地址的高6位,在pdp11/40中,只有最后两位有效
4531     char *b_blkno; /* block # on device */
  • 该缓存在设备上对应的块号
4532     char b_error; /* returned after I/O */
  • 该缓存块的I/O错误号
4533     char *b_resid; /* words not transferred after

4534                                    error */

4535 } buf[NBUF];

4536 /* ------------------------- */

|ref =

Caller

⚠️ **GitHub.com Fallback** ⚠️