Operating Systems Engineering Based on MIT (2012, lec9) Recitation 5: File Systems
What Does a File System Do? Durable Storage Multiplexing Sharing Organization
Why is the FS Interesting? Critical in many aspects of the system Performance Security Fault tolerance API design User interface You will implement one for JOS
FS - The Unix (& xv6) Choices Granularity: Files vs virtual disks, databases File content: Byte array vs 80-byte records, numbers, boolean values Organization: Name hierarchy vs flat names, GUIDs Synchronization: None vs locks, transaction rollbacks
File System API fd = open("x/y", O_CREATE); write(fd, "abc", 3); link("x/y", "x/z"); unlink("x/y");
FS Abstraction is Quite Useful Pipes, Sockets Devices /dev/console, /dev/urandom Linux’s /proc Apps can regard them all the same
Implications of Unix API FD (file descriptor) needs to remain valid after name change or even deletion A file can have many (symmetrical) names Thus - a file is independent of its names It’s contained in an “inode” inodes must keep counters For links in the FS For open FDs
A bit about xv6 FS software layers: System calls Name ops or file descriptors inode ops inode cache (for active inodes) Transactions Buffer cache Disk driver
xv6 – on-disk layout Viewing disk as a 512-byte sector array: 0: unused 1: super block (size, ninodes, root, …) 2+: array of inodes X: block in-use bitmap (0=free, 1=inuse) Y: file (or dir) content blocks Z: transaction log
xv6 –inodes On-disk layout: Type (free, file, directory, device) Nlink Size addrs[12+1] Direct and indirect blocks Each inode has an i-number inode location: sector *inum
xv6 - directories Directories are much like files Except user can’t directly write the content Content is an array of dirents Dirent: i-number 14-byte file name Dirent is free if the i-number is zero
xv6 – The code Q: How does xv6 create a file? create (sheet 56) calls: ialloc (sheet 46) iupdate (sheet 46) dirlink (sheet 50) calls: readi (sheet 49) writei (sheet 49)
xv6 – The code Q: What about concurrent calls to ialloc? will they get the same inode? bread (sheet 41) calls: bget (sheet 40) brelse (sheet 41)