Components of a UFS file system
When you create a UFS file system, the disk slice is divided into cylinder groups. The slice is then divided into blocks to control and organize the structure of the files within the cylinder group. Each block performs a specific function in the file system. A UFS file system has the following four types of blocks:
- Boot block Stores information used when booting the system
- Superblock Stores much of the information about the file system
- Cylinder Group File systems are divided into cylinder groups to improve disk access.
- Inode Stores all information about a file except its name
- Storage or data block Stores data for each file
The Boot Block
The boot block stores the code used in booting the system. Without a boot block, the system does not boot. Each file system has 15 sectors of space (sectors 115) allocated at the beginning for a boot block; however, if a file system is not to be used for booting, the boot block is left blank. The boot block appears only in the first cylinder group (cylinder group 0) and is the first 8KB in a slice.
The superblock resides in the 16 sectors (sectors 1631) following the boot block and stores much of the information about the file system. Following are a few of the more important items contained in a superblock:
- Size and status of the file system
- Label (file system name and volume name)
- Size of the file system's logical block
- Date and time of the last update
- Cylinder group size
- Number of data blocks in a cylinder group
- Summary data block
- File system state (clean, stable, or active)
- Pathname of the last mount point
Without a superblock, the file system becomes unreadable. Because it contains critical data, the superblock is replicated in each cylinder group and multiple superblocks are made when the file system is created.
A copy of the superblock for each file system is kept up-to-date in memory. If the system gets halted before a disk copy of the superblock gets updated, the most recent changes are lost and the file system becomes inconsistent. The sync command saves every superblock in memory to the disk. The file system check program fsck can fix problems that occur when the sync command hasn't been used before a shutdown.
A summary information block is kept with the superblock. It is not replicated but is grouped with the first superblock, usually in cylinder group 0. The summary block records changes that take place as the file system is used, listing the number of inodes, directories, fragments, and storage blocks within the file system.
Each file system is divided into cylinder groups with a minimum default size of 16 cylinders per group. Cylinder groups improve disk access. The file system constantly optimizes disk performance by attempting to place a file's data into a single cylinder group, which reduces the distance a head has to travel to access the file's data.
An inode contains all the information about a file except its name, which is kept in a directory. A filename is associated with an inode, and the inode provides access to data blocks. An inode is 128 bytes. The inode information is kept in the cylinder information block and contains the following:
- The type of the file (regular, directory, block special, character special, link, and so on)
- The mode of the file (the set of read/write/execute permissions)
- The number of hard links to the file
- The user ID of the file's owner
- The group ID to which the file belongs
- The number of bytes in the file
- An array of 15 disk-block addresses
- The date and time the file was last accessed
- The date and time the file was last modified
- The date and time the file was created
inodes are numbered and each file system maintains its own list of inodes. inodes are created for each file system when the file system is created. The maximum number of files per UFS file system is determined by the number of inodes allocated for a file system.
The number of inodes depends on the amount of disk space that is allocated for each inode and the total size of the file system. The following table displays the default number of inodes created by the newfs command based on the size of the file system.
|Less than 1GB
|Less than 2GB
|Less than 3GB
|3GB to 1 Tbyte
|Greater than 1 Tbyte or file systems created with the
You can change the default allocation by using the
-i option of the
newfs command. Also, the number of inodes will increase if a file system is expanded with the
The Storage Block
Storage blocks, also called data blocks, occupy the rest of the space allocated to the file system. The size of these storage blocks is determined at the time a file system is created. Storage blocks are allocated, by default, in two sizes: an 8KB logical block size and a 1KB fragmentation size.
For a regular file, the storage blocks contain the contents of the file. For a directory, the storage blocks contain entries that give the inode number and the filename of the files in the directory.
Blocks not currently being used as inodes, indirect address blocks, or storage blocks are marked as free in the cylinder group map. This map also keeps track of fragments to prevent fragmentation from degrading disk performance.