13-FileSystemImplementation
13-FileSystemImplementation
• Required Readings
• Chapter 40 – File System Implementation
• http://pages.cs.wisc.edu/~remzi/OSTEP/file-implementation.pdf
• Reference
• Chapter 42 – Crash Consistency: FSCK and Journaling
• http://pages.cs.wisc.edu/~remzi/OSTEP/file-journaling.pdf
• What kinds of on-disk structures are used by the file system to organize
files’ data and its metadata?
• Superblock (for Windows, similar set of info can be located via Master File Table)
• Inode table (for Windows – Master File Table)
• Data block bitmap (for Windows – Cluster Bitmap)
• Inode bitmap
• Inode bitmap
• When a file is created, one inode will be allocated from the inode table for this new file
• When a file is deleted, the inode will be released back to the inode table
• Thus, the system needs a mechanism to easily check which inodes in the inode table are free or
in used
• A inode bitmap is a simple structure with each bit is used to indicate whether the corresponding
inode is free or in-use in the inode table
• It stores virtually all of the information about a file, including its type, its size,
ownerships, permissions, . . ., and location of file contents
• One important design decision of the inode is that how can the inode keep track on
the data blocks of a file
• The data content of the file is stored in data disk block(s)
• Thus, inode needs to have some way to tell us which data blocks are associated to this file in the
disk
• The adopt mechanism may limit the max size a single file can have in such file system
Other attributes
• Disadvantages
• To locate a data item in the file
• The chain must be searched from the beginning to locate the data;
search process can be slow as block-to-block seeks occur
• Reliability issue – if the linked list is broken
• Disk blocks used by a file may be scattered all over the disk
• Disadvantage 19
20
NULL
23
• For large disks, the block allocation table can become quite large 21 FREE
22 18
• Example: Microsoft’s FAT file system 23 19
• Advantage
• Can determine if contiguous blocks are available at certain locations on disk
• Disadvantage
• May need to search the entire bitmap to find a free block
• Free linked-list
• Keep a pointer points to the first free block
• Each block contains a pointer to the next free block, and so
on
• Blocks are allocated from the beginning of the free list
• Newly freed blocks are appended to the end of the list
• Disadvantage
• Every disk block allocation results in a disk read to locate the next
free block for updating the pointer
• Free block-list
• A disk block has n entries which stores addresses of n-1 free disk blocks; the
last entry stores a pointer to the next block in the free block-list
• Faster to find a large number of free blocks
• Advantage
• Both free block list and free linked list have low overhead to perform free list
maintenance operations
• Disadvantage
• Files are likely to be allocated in noncontiguous blocks
• Every file open would require at least two reads (disk I/O) for every level in the directory
hierarchy
• One to read the inode of the directory in question, and at least one to read the data of the directory
• 2 reads for "/"
• 2 reads for "home"
• 2 reads for "c3230a"
• 1 read for the inode of "overview.txt”
• The process could only access the file via this index
• The right to access must still be checked on every access
• The open-file-table entry has a capability only for the allowed operations
• For example, if the file is opened for read only, an attempt to have write operation on the file
will be denied even the user has the write access right
• Consistency checking
• Compares data in directory structure with data blocks on disk, and tries to
fix inconsistencies
• Example: Unix command: fsck or DOS command: chkdsk
• FSCK
• checking superblock to find suspect corruption
• scan all inodes’ state
• scan all inodes’ direct and indirect block pointers to build a correct Free block bitmap
• scan all inodes to build the Free inode bitmap