Filesystem Implementation
Tom Kelliher, CS42
Nov. 22, 1996
For Monday: Chapter 13, Protection.
Layered design:
- Raw devices: floppies, Hard disks (IDE, SCSI, ...), CD-ROM, ...
- Device drivers.
- Block I/O system.
- Filesystem.
- Applications.
Design Strategies
- Part of kernel; privileged, trusted code.
- User-level task; unprivileged, untrusted. User-replaceable
- Block cache.
- Directory entry table (information for finding a file's blocks).
- System open file table (current position within file)
- Process open file table.
- Free list.
Consider: open, read, write (delayed disk updates).
- Disk, partition.
- DOS format.
- Does the OS automatically see the filesystem?
- Filesystem tree: hierarchical mounts:
keystone:~
% mount
/dev/wd0a on / (local)
/dev/wd0h on /home1 (NFS exported, local, with quotas)
/dev/sd0g on /home2 (NFS exported, local, with quotas)
/dev/sd0h on /usr (NFS exported, local)
mfs:84 on /tmp (asynchronous, local)
- Filesystem trees: drive letters.
Sector, block correspondence:
- Sector: 512 bytes.
- Original sector pointer (FAT) in DOS: 12 bits. Maximum disk size?
- ``Improved'' sector pointer: 16 bits. Max disk size?
- How do we use DOS with a 1 GB disk?
Lesson learned: technology growth.
- All blocks of file are allocated in one contiguous group.
- Initial placement: best-, worst- first-fit.
- Pre-declaration of maximum size. Wrong guess?
- External, internal fragmentation. Compaction.
- Overhead? Sequential-access files? Direct-access files?
Reliability? Performance?
- Blocks of file may be scattered over disk.
- Each data block contains a pointer to the next data block.
- Fragmentation?
- Pointer overhead. Clustering blocks.
- Sequential-access files? Direct-access files?
Reliability?
Table of block, next block pairs at beginning of partition. Redundancy.
- Collect all block pointers into an index table.
- Pointer overhead. Unix's solution
- Very large files and multiple index blocks. How are they linked?
- Sequential-access files? Direct-access files?
Reliability?
- Bit vector.
- Free list. A block on the free list contains a pointer to the next
block, etc.
Variations:
- Grouping. A free list block contains multiple pointers.
- Counting. Free list blocks are ``clustered.''
- List.
- Sorted list.
- Hashed.
- LRU replacement from block cache.
- Free-behind, read-ahead for sequential access.
- AI for predicting head movements.
- Maintain consistency at all costs by updating data structures before
data.
- Lazy writes from block cache. Update and sync.
- Inconsistencies caught by fsck at start-up:
- Unreferenced inodes.
- Link counts in inodes too large.
- Missing blocks in the free map.
- Blocks in the free map also in files.
- Counts in the super-block wrong.
Thomas P. Kelliher
Fri Nov 22 11:04:26 EST 1996
Tom Kelliher