(感觉文件系统的代码还是挺多的 做个笔记
首先上xv6 文件系统的结构图:
disk在virtio硬盘上读写
buffer cache 如下
logging 将来自高层对几个块的更新包装成一个事务(transaction),保证发生崩溃时,块的更新具有原子性(要么都不执行,要么全部执行
inode 提供单个的文件,表现为inode,有一个独一无二的inum,一些块保存该文件的数据
directory 将目录实现为一种特殊的inode,他的内容是一系列dirent(directory entry),每个dirent包含一个文件名和一个inum
pathname 提供有层次地路径名,并使用递归地查找来解析他们
file descriptor将unix的各种资源抽象化,使其都可以通过文件描述符访问
bio.c负责的是buffer cache这一层
bio.c有最详细的注释:
Buffer cache.
The buffer cache is a linked list of buf structures holding
cached copies of disk block contents. Caching disk blocks
in memory reduces the number of disk reads and also provides a synchronization point for disk blocks used by multiple processes.可以知道:这里采用链表的形式,管理对磁盘块内容的缓存。缓存磁盘块可以让我们减少对磁盘的读,并且在多个进程读写磁盘块时提供了一个同步的点
Interface:
* To get a buffer for a particular disk block, call bread. bread用于获取一个缓存块
* After changing buffer data, call bwrite to write it to disk. bwrite将更改过的缓存块写回到磁盘
* When done with the buffer, call brelse. brelse(release)释放一个缓存块(?
* Do not use the buffer after calling brelse.
* Only one process at a time can use a buffer,
so do not keep them longer than necessary. 一个缓存块一次只能被一个进程使用,所以使用完尽早释放(?
首先看数据结