Chapter 11: File System Implementation Joe McCarthy CSS 430: Operating Systems - File System Implementation1
File System Implementation File-System Structure File-System Implementation Directory Implementation Allocation Methods Free-Space Management Efficiency and Performance Recovery NFS Example: WAFL File System CSS 430: Operating Systems - File System Implementation2 Material derived, in part, from Operating Systems Concepts with Java, 8 th Ed. © 2009 Silberschatz, Galvin & Gagne
File-System Structure CSS 430: Operating Systems - File System Implementation3 File system interface provides applications with various system calls and commands such as open, write, read, seek, etc.. File system maintains disk space in blocks and allocates available blocks to each stream-oriented file. Basic file system (BIOS) maintains data in physical blocks Device driver reads / writes disk blocks which consists of one (or more) sector(s). Disk maintains physical block locations indexed by drive#, cylinder#, track# and sector# track sector cylinder
Layered File System 4CSS 430: Operating Systems - File System Implementation
File-System Implementation Boot control block contains info needed by system to boot OS from that volume Volume control block contains volume details – # blocks, block size, free block count/pointers Directory structure organizes the files Per-file File Control Block (FCB) contains many details about the file CSS 430: Operating Systems - File System Implementation5
In-Memory File System Structures CSS 430: Operating Systems - File System Implementation6
Allocation Methods An allocation method refers to how disk blocks are allocated for files: – Contiguous allocation – Linked allocation – Indexed allocation 7CSS 430: Operating Systems - File System Implementation
Contiguous Allocation CSS 430: Operating Systems - File System Implementation8 Each file occupies a set of contiguous blocks on the disk Advantage(s): Disadvantage(s):
Contiguous Allocation CSS 430: Operating Systems - File System Implementation9 Each file occupies a set of contiguous blocks on the disk Advantage(s): Simple: start, length Fast Supports direct access Disadvantage(s): External fragmentation What if file grows?
Extent-Based Systems Some file systems use a modified contiguous allocation scheme Extent-based file systems allocate disk blocks in extents – Contiguous sequence of blocks – Allows more space for files to grow CSS 430: Operating Systems - File System Implementation10
Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. Advantage(s): Disadvantage(s): CSS 430: Operating Systems - File System Implementation11 pointer Block =
Linked Allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. Advantage(s): – Simple: start, end – No external fragmentation Disadvantage(s): – No direct access – Slow – Reliability CSS 430: Operating Systems - File System Implementation12 pointer Block =
File-Allocation Table FAT has an entry for each disk block. FAT entries rather than blocks themselves are linked. Example: – MS-DOS and OS/2 Advantage(s): Disadvantage(s): CSS 430: Operating Systems - File System Implementation13
File-Allocation Table FAT has an entry for each disk block. FAT entries rather than blocks themselves are linked. Example: – MS-DOS and OS/2 Advantage(s): – Save disk block space – Faster direct access Disadvantage(s): – A significant number of disk head seeks CSS 430: Operating Systems - File System Implementation14
Indexed Allocation CSS 430: Operating Systems - File System Implementation15 Index block Need index table Advantage(s): Disadvantage(s):
Indexed Allocation CSS 430: Operating Systems - File System Implementation16 Index block Need index table Advantage(s): – Direct access – No external fragmentation Disadvantage(s): – Internal fragmentation – Determining optimal index block size Too small: can’t fit a file Too large: wasted space
Indexed Allocation CSS 430: Operating Systems - File System Implementation17 outer-index index table file
Combined Scheme: UNIX UFS CSS 430: Operating Systems - File System Implementation18 4K bytes per block
Free Space Management CSS 430: Operating Systems - File System Implementation19 Bit vector (n blocks) … 012n-1 bit[i] = 0 block[i] free 1 block[i] occupied Linked free space list
Free Space Management CSS 430: Operating Systems - File System Implementation20 Bit vector (n blocks) … 012n-1 bit[i] = 0 block[i] free 1 block[i] occupied Linked free space list
css430 file-system implementation21 ThreadOS Superblock & Inodes Superblock int totalBlocks; int totalInodes; int freeList; Inode #032bytes Inode #1 Inode #15 Inode #inodeBlocks -1 Block #0 Block #1 Block #2 Block #(totalBlocks – 1) Free Block #x Free Block #y Free Block #z / root directory
css430 file-system implementation22 ThreadOS Root Directory (“/”) Directory() – Initialize “/” directory bytes2directory( byte data[]) – Initialize directory with byte[] which have been retrieved from disk directory2bytes() – Converts directory information into byte[] ialloc( String filename ) – Allocate an iNumber for filename ifree( short iNumber ) – Deallocate the iNumber namei( String filename ) – Return filename’s iNumber Entry[] fsizes fnames (iNumber) inodeBlock / init fsck clri motd mount mknod passwd umount checklist fsdblb config getty
css430 file-system implementation23 CSS430 ThreadOS File System int fd = SysLib.open(“fileA”, mode); SysLib.read(fd, …); stdin stdout stderr User file Descriptor table TCB struct file: count 1 inode File Table Inode: length count 1 direct[11] indirect Inode Disk Thread A simplified structure of Unix file system