Upload
denis-palmer
View
215
Download
0
Embed Size (px)
Citation preview
Digital UNIX Internals II 5 - 1 UFS
UNIX File System (UFS)
Chapter Five
Digital UNIX Internals II 5 - 2 UFS
Topics
• Background: Old System V File System• On Disk Format
– inodes– fragments– block allocation
• Consistency Issues
Digital UNIX Internals II 5 - 3 UFS
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 - 4 UFS
History: The old System V File System Layout
DataInodeTable
SuperBlock
BootBlock
Digital UNIX Internals II 5 - 5 UFS
UNIX File System Layout
AlternateSuperBlock
BootBlock
SuperBlock
CylinderGroupBlock
InodeTable
Data DataAlternate
SuperBlock
CylinderGroupBlock
InodeTable
Data
Cylinder Group 0 Cylinder Group N
Partition
Digital UNIX Internals II 5 - 6 UFS
UFS Block Types
• bootblocks• superblocks• inodes• data blocks• cylinder group information
Digital UNIX Internals II 5 - 7 UFS
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 - 8 UFS
Disk Inode
ModeLink
CountUID GID Size
AccessDate
ModifyDate
CreateDate
15 Pointers
ActualBlockCount
Gener-ation
Number
0 0 0 0 0 0 0 0 0 0 0 0 1 2 3
Data Block PointersLevel of
Indirection
DataBlock
IndirectionBlock
IndirectionBlock
IndirectionBlock
(not implemented)
DataBlock
IndirectionBlock
IndirectionBlock
DataBlock
SUID
SGID
StickyFile type User Group Other
0 127
Common to all File Systems Specific to this File System
DataBlock
IndirectionBlock
Digital UNIX Internals II 5 - 9 UFS
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 - 10 UFS
Small Blocks Require More Overhead
X X X X X X X X
X
FILE 1
FILE 2
Large Blocks Waste SpaceX
FILE 1
FILE 2
X X X X X X X X
Large Blocks and Small Fragments
FILE 1
FILE 2
X X X X X X X X
X
Fragments (1)
Digital UNIX Internals II 5 - 11 UFS
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 - 12 UFS
Fragment (3)
• Cylinder Group Block has one bit set for each fragment in the cylinder group
Block #
free bits 01101011 11111111 00010000
117 118 119
Digital UNIX Internals II 5 - 13 UFS
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
Digital UNIX Internals II 5 - 14 UFS
Inode Allocation
• Regular Files– in cylinder group of parent directory
• Directories– in different cylinder group than parent directory
Digital UNIX Internals II 5 - 15 UFS
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 - 16 UFS
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 - 17 UFS
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 - 18 UFS
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 - 19 UFS
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.