S5FS Help Session

S5FS Help Session
CS169 Spring 2015
Overview
●
●
Implements lower-level parts of filesystem
operations (read(), write(), etc)
Replaces ramfs (which was just for testing VFS)
S5FS
User Land!
VM
System Calls
open, close, read, write, lseek, getdents
fork, wait
TTY driver
Virtual device
drivers
Terminal driver
Dispatche
r
Disk
File
system
(ramfs)
mmap
Scheduler
File
system
(S5FS)
Process Management
VFS
yield
TLB
Page Tables
Page Frames
0xBEEF
0xF00D
/dev/null /dev/zero
CPU
Memory
TLB
The Code
●
s5fs.c: syscall implementations and some
supporting functions
■ do_read(), do_write(), do_link(),
do_mkdir(), etc.
● Lock vnodes from within these functions
○ See comments in code for more
details
■ fillpage(), dirtypage(),
cleanpage()
The Code (cont.)
●
s5fs_subr.c: lower-level filesystem operations
○ seek_to_block() (allocates sparse blocks)
○ s5_link(), s5_find_dirent(),
s5_remove_dirent(), etc.
The Code (cont.)
●
●
●
●
The lecture slides on S5FS in Weenix will be very
helpful
○ Slides XV-8 through XV-14
Make sure you know the calling order
It is essential that you understand how
s5_seek_to_block() gets called following a call
to s5_write_file()
It is essential that you understand how
blockdev_fillpage() gets called following a
call to s5_seek_to_block()
Inodes
●Filesystem
counterpart to vnodes
●Includes:
○
○
○
○
○
Type of inode (data, directory, or unused)
Number (a unique identifier)
Link count (see “Refcounts” slide)
Direct block pointers
Indirect block pointer
Inodes (cont.)
●Note:
On disk struct fields have fixed sizes and do
not contain any pointers
○ This allows them to be written to/read from disk
●Represented by s5_inode_t struct
●See lecture slides for more details
Disk blocks
●
●
●
Data blocks
○ Store S5_BLOCK_SIZE bytes
Files
○ data blocks specified by the order of blocks in
the inode
○ 0 block pointers in the indirect block indicate
sparse blocks (blocks filled with 0’s)
Directories
○ Data is a sequence of s5_dirent_t’s, which
have just a name and inode number
Block Free List
Superblock #MAGIC
free block n
free block n+1
…
free block 2n-1
first free block
free block 1
free block 2
…
free block n-1
free block 2n
free block 2n+1
…
free block 3n-1
free block 3n
free block 3n+1
…
free block 4n-1
Block Free List (more general)
Superblock #MAGIC
free block n
free block n+1
…
free block n-1
first free block
block 1 (used)
block 2 (used)
...
free block i
free block i+1
…
free block n-1
free block 2n
free block 2n+1
…
free block 3n-1
free block 3n
free block 3n+1
…
free block 4n-1
Page Management
●
●
Use the pframe subsystem to acquire pages from
the disk
○ pframe_get(): obtain a page from the disk
○ You write this!
pframe_dirty(): make sure a page is written
out before being removed from memory
○ This does not mean that the page is
immediately written to disk
Page Management (cont.)
●
pframe_(un)pin(): ensure that a page doesn’t
get paged out while it’s still being used
○ Pinned pages will not be removed from memory
○ Be sure to unpin pages when they no longer
need to be pinned
■ Otherwise, data won’t get written to disk
○ Ex: When initializing a vnode, we pin the page
which contains the corresponding inode (why?)
Refcounts
●
●
●
vnode refcounts
inode refcounts (link counts)
○ One for each hard link to a file
○ Plus one while VFS is using it
Pin counts
○ Number of times a page is pinned
○ Page can only be paged out when the pin count
is zero
Tips and tools
●
●
●
●
●
Check for error conditions
○ Make sure you know when to KASSERT and
when to return an error
Use cscope to learn about the code
Header files contain many useful macros
Disk is saved to user/disk0.img
Binary file viewers
○ xxd, ghex2, etc.
Tips and tools (cont.)
●
●
fsmaker
○ Examine your disk without running weenix
○ Run with ./fsmaker -h to see usage
instructions
○ Very helpful
Use ./weenix -n to start weenix with a new disk
○ Useful after you’ve accidentally left the disk in
an invalid state or deleted the files we give you
Testing
●
●
●
●
●
●
Finish testing VFS
○ Before testing S5FS
Use the kshell
Check that data persists after shutdown
There are some useful files on the disk
○ Hamlet
Testing section (6.6) of the Weenix PDF
vfstest is still useful
○ Beware: may pass even if S5FS is not working