Download presentation
1
UNIX File System (UFS) Chapter Five
2
Topics Background: Old System V File System On Disk Format
inodes fragments block allocation Consistency Issues
3
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 Notes: V4.0 Release Notes Limits Supported Theoretical file size 128 GB 1 TB
4
History: The old System V File System Layout
Boot Block Super Block Inode Table Data Notes: File names are limited to 14 characters. Each file has an on-disk inode structure including: Mode and type of file Link count - number of directory entries that point to this inode Owner - user ID and group ID Size (bytes) Disk map - an array of direct pointers to the data blocks for the file The System V file system uses a simple but inefficient layout: Bootblock - used on some systems to contain a bootstrap program Superblock - describes the file system: total size, size of inode list, head of free block list, list of free inodes, flags, number of free blocks and inodes Inode table - area for allocating inodes for files Data region - remainder of the file system is for data blocks and indirect pointer blocks
5
UNIX File System Layout
Alternate Super Block Boot Cylinder Group Inode Table Data Cylinder Group 0 Cylinder Group N Partition Notes: The figure above illustrates UNIX file system layout. The figure is not drawn to scale. The data area is the largest by far. File system space is divided into cylinder groups, providing: Less head movement between inode table and data blocks, for faster performance Duplication of file system structure for increased reliability Cylinder groups require more overhead for storing extra structure, but provide greater performance. The superblock is replicated in a different position in each cylinder group to prevent loss of critical data in case an entire cylinder or surface is damaged.
6
UFS Block Types bootblocks superblocks inodes data blocks
cylinder group information Notes: The file system subdivides a disk partition into one or more cylinder groups. A cylinder group is comprised of one or more consecutive cylinders on the disk. Associated with each cylinder group is some book keeping that includes a redundant copy of the superblock, space for inodes, a bit map describing available blocks in cylinder group. For each cylinder group a static number of inodes is allocated at file creation time. Cylinder group information begins a floating offset from the beginning from the cylinder group. This prevents a single platter, track or cylinder failure from destroying all superblocks.
7
Inodes State of an individual file disk inode incore 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 Notes: Disk Inode: Information that must be saved permanently; Modes (Permissions) Link Count Owner and Group IDs Access Times File Size Generation Number Pointers to data blocks or sym link info (fastlink) Incore Inode: Additional information needed when the file is referenced; Pointers to inode lists Device Inode number Pointer to mount structure Offset of last entry found if a directory Disk inode
8
Disk Inode 1 2 3 Mode Link Count UID GID Size Access Date Modify
Create 15 Pointers Actual Block Gener- ation Number 1 2 3 Data Block Pointers Level of Indirection Data (not implemented) SUID SGID Sticky File type User Group Other 127 Common to all File Systems Specific to this File System Notes: A disk inode (struct dinode) is defined in kernel/ufs/dinode.h and is 128 bytes in size. The disk address pointers it contains are each 4 bytes.
9
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> Notes:
10
Fragments (1) Small Blocks Require More Overhead Large Blocks Waste
X FILE 1 FILE 2 Large Blocks Waste Space X FILE 1 FILE 2 X X X X X X X X Notes: The UNIX file system: Uses a large block size (such as 8192 bytes) to maximize data transfer Allows blocks to be split into fragments to reduce wasted space The above figures illustrate the differences using different block sizes. The Xs represent data and the boxes represent block size. In the first two figures, we see file systems with only one block size, no fragment size. A small block size requires more overhead and more time to handle large files. A large block size wastes space when files are small. UFS does not bother allocating fragments from file > 96 KB assuming they will grow larger. Large Blocks and Small Fragments FILE 1 FILE 2 X X X X X X X X X
11
Fragments (2) UFS Blocks are 8192 Bytes Fragment
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 Notes: When the size of a file is increased; If the file is empty, block size units are allocated and any remainder placed in a fragment(s) If the existing fragment or block can contain the new data it is placed their If the file already has fragments allocated, a new block is allocated and the existing fragment is copied into it an then the new data added at the end.
12
Fragment (3) Cylinder Group Block has one bit set for each fragment in the cylinder group 117 118 119 Block # Notes: free bits
13
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 Notes: Data blocks of a file are placed in the same cylinder group when possible. A limit is placed on the percentage of a cylinder group that an individual file is allowed to consume before its additional blocks are allocated from a different cylinder group.
14
Inode Allocation Regular Files Directories
in cylinder group of parent directory Directories in different cylinder group than parent directory Notes: Regular files of a directory are placed in the same cylinder group as the directory when possible to minimize rotational delays for applications that try to modify all the files of a directory at the same time. Directories are allocated in the cylinder group with the fewest number of directories already and greater than average free inode count.
15
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 Notes:
16
Symbolic Links Hard Links: ln Soft Links: ln -s
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 Notes: A symbolic link is created in BSD systems by writing a pathname into the data blocks of a file and marking the file (vnode) type as VLNK. The pathname translation mechanism checks for this type and reads the data as part of the pathname. This requires extra disk operations. Digital UNIX UFS contains an optimization for symbolic links to reduce I/O called fast symbolic links.
17
UFS Consistency If Machine Crashes Disaster if the lost block
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. Notes:
18
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 Notes:
19
Source References kernel/ufs/fs.h kernel/ufs/dinode.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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.