Lecture: on-disk data structures
recap from last lecture
- xv6’s I/O stack
- per-process
fd
→ struct file
→ fs layers (fs.c
)
→ block I/O (bio.c
) → disk driver (ide.c
)
- example:
sys_write
in sysfile.c
- what does
argfd()
do?
- how does
filewrite
call different functions depending on the fd type?
- block device
- terminology: block vs sector
- API
data ← read(blockno)
write(blockno, data)
flush
trim
overview
- xv6 disk layout:
[ ... | superblock | log | inode blocks | free bit map | data blocks ]
- superblock
- see
struct superblock
in fs.h
- metadata about the entire file system
- often located at a pre-defined location (xv6: block 1)
- contain pointers to other parts of the file system.
- free bit map
- see
balloc
/bfree
in fs.c
- track free/in-use blocks
- inode
- see
struct dinode
in fs.h
- file metadata: type, size, (permission, time, …)
- contain pointers to data blocks: 12 direct blocks and 1 (single) indirect block
- goal: map (inode number, offset) to disk block number
- why indirect blocks? compare to two-level paging
- quiz
- does inode have a “name” field? why not?
- what’s the maximum file size
- given a file’s inode, how to read its n-th block - see
readi
/bmap
in fs.c
- file: inode + data blocks
- directory: a special “file”
- content:
struct dirent
s - (inode number, name) pairs
- map name to inode number
- questions
- how to locate
/d/f
- how to write “
hello
” to /d/f
(overwrite vs. append)
- how to create a new file