UNIX File System UFS Chapter Five Digital UNIX

  • Slides: 19
Download presentation
UNIX File System (UFS) Chapter Five Digital UNIX Internals II 5 -1 UFS

UNIX File System (UFS) Chapter Five Digital UNIX Internals II 5 -1 UFS

Topics • Background: Old System V File System • On Disk Format – inodes

Topics • Background: Old System V File System • On Disk Format – inodes – fragments – block allocation • Consistency Issues Digital UNIX Internals II 5 -2 UFS

Features • Traditional BSD Local File System • Compatible with Berkeley 4. 3 Tahoe

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 Digital UNIX Internals II 5 -3 UFS

History: The old System V File System Layout Boot Super Block Digital UNIX Internals

History: The old System V File System Layout Boot Super Block Digital UNIX Internals II Inode Table Data 5 -4 UFS

UNIX File System Layout Boot Super Block Alternate Cylinder Inode Super Group Data Table

UNIX File System Layout Boot Super Block Alternate Cylinder Inode Super Group Data Table Block Cylinder Group 0 Alternate Cylinder Inode Super Group Data Table Block Cylinder Group N Partition Digital UNIX Internals II 5 -5 UFS

UFS Block Types • • • bootblocks superblocks inodes data blocks cylinder group information

UFS Block Types • • • bootblocks superblocks inodes data blocks cylinder group information Digital UNIX Internals II 5 -6 UFS

Inodes • State of an individual file • disk inode – stored on disk

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 Digital UNIX Internals II 5 -7 UFS

Disk Inode Common to all File Systems Mode Link Count UID GID Size Specific

Disk Inode Common to all File Systems Mode Link Count UID GID Size Specific to this File System Actual Gener. Access Modify Create 15 Block ation Date Pointers Count Number 0 127 Data Block Pointers 0 0 0 1 2 3 Level of Indirection (not implemented) Data Block File type S S UG I I DD S t User i c k y Group Other Indirection Block Data Block Indirection Block Data Block Digital UNIX Internals II 5 -8 UFS

Inode Numbers • Inodes numbered from 1 – Position #1, • originally an 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> Digital UNIX Internals II 5 -9 UFS

Fragments (1) FILE 1 XXXX FILE 2 X FILE 1 XXXX FILE 2 Large

Fragments (1) FILE 1 XXXX FILE 2 X FILE 1 XXXX FILE 2 Large Blocks Waste Space X FILE 1 XXXX FILE 2 X Digital UNIX Internals II Small Blocks Require More Overhead Large Blocks and Small Fragments 5 - 10 UFS

Fragments (2) • UFS Blocks are 8192 Bytes – good for modern disk drives

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 Digital UNIX Internals II 5 - 11 UFS

Fragment (3) • Cylinder Group Block has one bit set for each fragment in

Fragment (3) • Cylinder Group Block has one bit set for each fragment in the cylinder group Block # free bits Digital UNIX Internals II 117 01101011 118 1111 5 - 12 119 00010000 UFS

Disk Block Allocation • Whenever Possible – First 96 KB Direct Block Allocation •

Disk Block Allocation • Whenever Possible – First 96 KB 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 Digital UNIX Internals II 5 - 13 UFS

Inode Allocation • Regular Files – in cylinder group of parent directory • Directories

Inode Allocation • Regular Files – in cylinder group of parent directory • Directories – in different cylinder group than parent directory Digital UNIX Internals II 5 - 14 UFS

Directories in UFS • Collection of inode: file_name pairs – – – four byte

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 Digital UNIX Internals II 5 - 15 UFS

Symbolic Links • Hard Links: ln – new directory entry added referencing an existing

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 Digital UNIX Internals II 5 - 16 UFS

UFS Consistency • If Machine Crashes – writes to data blocks may be lost

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. Digital UNIX Internals II 5 - 17 UFS

UFS Solution • Some Writes are Synchronous – Any changed block that refers to

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 Digital UNIX Internals II 5 - 18 UFS

Source References • kernel/ufs/fs. h – definitions of super block (struct fs) and cylinder

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_vnops. c – implementation of vnode ops for ufs • kernel/ufsmount. h – definition of the ufs mount structure • kernel/ufs_vfsops. c – implementation of the ufs vfs ops. Digital UNIX Internals II 5 - 19 UFS