xv6, line by line
kernel/buf.h

kernel/buf.h

C header · 11 lines · annotated 100% · kernel · upstream

Included by 4 fileskernel/bio.c, kernel/fs.c, kernel/log.c, kernel/virtio_disk.c
About this file

Defines struct buf, one slot of the buffer cache: an in-memory copy of one 1024-byte disk block plus the bookkeeping the cache, the disk driver and the log need.

kernel/bio.c owns the NBUF buffers and hands them out; kernel/virtio_disk.c fills or drains data and uses disk; kernel/fs.c and kernel/log.c read and modify data between bread and brelse.

The file includes nothing itself, so any file that includes it must first include kernel/fs.h (for BSIZE) and kernel/sleeplock.h.

1struct buf {
2 int valid; // has data been read from disk?
3 int disk; // does disk "own" buf?
6 struct sleeplock lock;
8 struct buf *prev; // LRU cache list
9 struct buf *next;
11};