250 likes | 576 Views
UNIX File System (UFS). Chapter Five. Topics. Background: Old System V File System On Disk Format inodes fragments block allocation Consistency Issues. Features. Traditional BSD Local File System Compatible with Berkeley 4.3 Tahoe release Digital Enhancements
E N D
UNIX File System (UFS) Chapter Five
Topics • Background: Old System V File System • On Disk Format • inodes • fragments • block allocation • Consistency Issues
Features • Traditional BSD Local File System • Compatible with Berkeley 4.3 Tahoe release • Digital Enhancements • increased file and path sizes • file block clustering • File on File Layer for STREAMS • Unified Buffer Cache Integration • Support for Enhanced File Attributes
History: The old System V File System Layout Boot Block Super Block Inode Table Data
Boot Block Super Block Alternate Super Block Cylinder Group Block Inode Table Data Data Alternate Super Block Cylinder Group Block Inode Table Data Cylinder Group 0 Cylinder Group N Partition UNIX File System Layout
UFS Block Types • bootblocks • superblocks • inodes • data blocks • cylinder group information
Inodes • State of an individual file • disk inode • stored on disk • sized to fit evenly in a disk block • incore inode • in-memory • disk inode information plus information related to being a currently open file • for UFS, vnode v_data private is an incore inode
Common to all File Systems Specific to this File System Mode Link Count UID GID Size Access Date Modify Date Create Date 15 Pointers Actual Block Count Gener- ation Number 0 127 Data Block Pointers Level of Indirection 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 (not implemented) Data Block Indirection Block Indirection Block Indirection Block Data Block Indirection Block Indirection Block Sticky SUID SGID File type User Group Other Data Block Indirection Block Data Block Disk Inode
Inode Numbers • Inodes numbered from 1 • Position #1, • originally an inode for bad data blocks, no longer used for that purpose. • Position #2 • inode for the root directory of the file system • UFS file identity is <device, inumber>
X X X X X X X X FILE 1 Small Blocks Require More Overhead X FILE 2 X X X X X X X X FILE 1 Large Blocks Waste Space X FILE 2 X X X X X X X X FILE 1 Large Blocks and Small Fragments X FILE 2 Fragments (1)
Fragments (2) • UFS Blocks are 8192 Bytes • good for modern disk drives • bad for small files • space wasted with internal fragmentation • Fragment • Subdivision of a Block • 1024 Bytes • Consecutive fragments are use for the last partial block of small files
Fragment (3) • Cylinder Group Block has one bit set for each fragment in the cylinder group 117 118 119 Block # free bits 01101011 11111111 00010000
Disk Block Allocation • Whenever Possible • First 96KB Direct Block Allocation • in cylinder containing inode • Each Additional 2 Meg • cylinder groups with "lots" of free space • Allocate consecutive disk blocks • Works well until disk reaches 90% full
Inode Allocation • Regular Files • in cylinder group of parent directory • Directories • in different cylinder group than parent directory
Directories in UFS • Collection of inode:file_name pairs • four byte inode number • two byte length of entry • two byte length of name • null terminated name • padding to next four byte boundary • Deleted entries become padding for previous • Entries must fit in a 512-byte sector so disk write is atomic
Symbolic Links • Hard Links: ln • new directory entry added referencing an existing inode • link count in existing inode incremented • Soft Links: ln -s • new directory entry added referencing a new inode • new inode is of type sym link • if link path short enough • stored in data block map area of inode • referred to as a fast link • else • link path stored in a data block
UFS Consistency • If Machine Crashes • writes to data blocks may be lost • Disaster if the lost block • is an indirect block containing the disk addresses of newly written data blocks already on disk. • is a directory block containing new file references newly created files with written inodes. • contains free list information about newly allocated blocks.
UFS Solution • Some Writes are Synchronous • Any changed block that refers to other blocks • 30 second update process sync's all mounted file systems • Directory entries are not written across sector boundaries • fsck utility after reboot • must know usual order of UFS synchronous writes
Source References • kernel/ufs/fs.h • definitions of super block (struct fs) and cylinder groups (struct csum) • kernel/ufs/dinode.h • definition on disk inode (struct dinode) • kernel/ufs/inode.h • definition of in-memory inode (struct inode) • kernel/ufs/ufs_vnops.c • implementation of vnode ops for ufs • kernel/ufs/ufsmount.h • definition of the ufs mount structure • kernel/ufs/ufs_vfsops.c • implementation of the ufs vfs ops.