This is a list of the reference information in this chapter.
When you create a UFS file system, the disk slice is divided into cylinder groups. A cylinder group is comprised of one or more consecutive disk cylinders. Cylinder groups are then further divided into addressable blocks to control and organize the structure of the files within the cylinder group. Each type of block has a specific function in the file system. A UFS file system has these four types of blocks.
Block Type |
Type of Information Stored |
---|---|
Boot block |
Information used when the system is booted |
Superblock |
Detailed information about the file system |
Inode |
All information about a file |
Storage or data block |
Data for each file |
The following sections provide additional information about the organization and function of these blocks.
The boot block stores objects that are used in booting the system. 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 8 KB in a slice.
The superblock stores much of the information about the file system, which includes the following:
Size and status of the file system
Label, which includes the file system name and volume name
Size of the file system 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
Path name of the last mount point
Because the superblock contains critical data, multiple superblocks are made when the file system is created.
A summary information block is kept within the superblock. The summary information block is not replicated, but is grouped with the primary superblock, usually in cylinder group 0. The summary block records changes that take place as the file system is used. In addition, the summary block lists the number of inodes, directories, fragments, and storage blocks within the file system.
An inode contains all the information about a file except its name, which is kept in a directory. 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
FIFO, also known as named pipe
Symbolic link
Socket
Other inodes – Attribute directory and shadow (used for ACLs)
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 owner of the file
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 inode was changed
The array of 15 disk-block addresses (0 to 14) points to the data blocks that store the contents of the file. The first 12 are direct addresses. That is, they point directly to the first 12 logical storage blocks of the file contents. If the file is larger than 12 logical blocks, the 13th address points to an indirect block, which contains direct-block addresses instead of file contents. The 14th address points to a double indirect block, which contains addresses of indirect blocks. The 15th address is for triple indirect addresses. The following figure shows this chaining of address blocks starting from the inode.
Data blocks, also called storage blocks, contain the rest of the space that is allocated to the file system. The size of these data blocks is determined when a file system is created. By default, data blocks are allocated in two sizes: an 8-KB logical block size, and a 1-KB fragment size.
For a regular file, the data blocks contain the contents of the file. For a directory, the data blocks contain entries that give the inode number and the file name of the files in the directory.
Blocks that are not currently being used as inodes, as indirect address blocks, or as 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.
To give you an idea of the structure of a typical UFS file system, the following figure shows a series of cylinder groups in a generic UFS file system.
Before you alter the default file system parameters that are assigned by the newfs command, you need to understand them. This section describes these parameters:
Rotational Delay (Obsolete)
For a description of the command options that customize these parameters, see newfs(1M) and mkfs_ufs(1M).
The logical block size is the size of the blocks that the UNIX kernel uses to read or write files. The logical block size is usually different from the physical block size. The physical block size is usually 512 bytes, which is the size of the smallest block that the disk controller can read or write.
Logical block size is set to the page size of the system by default. The default logical block size is 8192 bytes (8 KB) for UFS file systems. The UFS file system supports block sizes of 4096 or 8192 bytes (4 or 8 KB). The recommended logical block size is 8 KB.
You can specify only the 8192-byte block size on the sun-4u platform.
To choose the best logical block size for your system, consider both the performance you want and the available space. For most UFS systems, an 8-KB file system provides the best performance, offering a good balance between disk performance and the use of space in primary memory and on disk.
As a general rule, to increase efficiency, use a larger logical block size for file systems when most of the files are very large. Use a smaller logical block size for file systems when most of the files are very small. You can use the quot -c filesystem command on a file system to display a complete report on the distribution of files by block size.
However, the page size set when the file system is created is probably the best size in most cases.
As files are created or expanded, they are allocated disk space in either full logical blocks or portions of logical blocks called fragments. When disk space is needed for a file, full blocks are allocated first, and then one or more fragments of a block are allocated for the remainder. For small files, allocation begins with fragments.
The ability to allocate fragments of blocks to files, rather than just whole blocks, saves space by reducing fragmentation of disk space that results from unused holes in blocks.
You define the fragment size when you create a UFS file system. The default fragment size is 1 KB. Each block can be divided into 1, 2, 4, or 8 fragments, which results in fragment sizes from 8192 bytes to 512 bytes (for 4-KB file systems only). The lower bound is actually tied to the disk sector size, typically 512 bytes.
For multiterabyte file systems, the fragment size must be equal to the file system block size.
The upper bound for the fragment is the logical block size, in which case the fragment is not a fragment at all. This configuration might be optimal for file systems with very large files when you are more concerned with speed than with space.
When choosing a fragment size, consider the trade-off between time and space: A small fragment size saves space, but requires more time to allocate. As a general rule, to increase storage efficiency, use a larger fragment size for file systems when most of the files are large. Use a smaller fragment size for file systems when most of the files are small.
The minimum free space is the percentage of the total disk space that is held in reserve when you create the file system. The default reserve is ((64 MB/partition size) * 100), rounded down to the nearest integer and limited between 1 percent and 10 percent, inclusively.
Free space is important because file access becomes less and less efficient as a file system gets full. As long as an adequate amount of free space exists, UFS file systems operate efficiently. When a file system becomes full, using up the available user space, only root can access the reserved free space.
Commands such as df report the percentage of space that is available to users, excluding the percentage allocated as the minimum free space. When the command reports that more than 100 percent of the disk space in the file system is in use, some of the reserve has been used by root.
If you impose quotas on users, the amount of space available to them does not include the reserved free space. You can change the value of the minimum free space for an existing file system by using the tunefs command.
This parameter is obsolete. The value is always set to 0, regardless of the value you specify.
The optimization type parameter is set to either space or time.
Space – When you select space optimization, disk blocks are allocated to minimize fragmentation and disk use is optimized.
Time – When you select time optimization, disk blocks are allocated as quickly as possible, with less emphasis on their placement. When sufficient free space exists, allocating disk blocks is relatively easy, without resulting in too much fragmentation. The default is time.
You can change the value of the optimization type parameter for an existing file system by using the tunefs command.
For more information, see tunefs(1M).
The number of bytes per inode specifies the density of inodes in the file system. The number is divided into the total size of the file system to determine the number of inodes to create. Once the inodes are allocated, you cannot change the number without re-creating the file system.
The default number of bytes per inode is 2048 bytes (2 KB) if the file system is less than 1 GB. If the file system is larger than 1 GB, the following formula is used:
File System Size |
Number of Bytes Per Inode |
---|---|
Less than or equal to 1 GB |
2048 |
Less than 2 GB |
4096 |
Less than 3 GB |
6144 |
3 GB up to 1 TB |
8192 |
Greater than 1 TB or created with -T option |
1048576 |
If you have a file system with many symbolic links, they can lower the average file size. If your file system is going to have many small files, you can give this parameter a lower value. Note, however, that having too many inodes is much better than running out of inodes. If you have too few inodes, you could reach the maximum number of files on a disk slice that is practically empty.
The maximum size of a UFS file system is about 16 TB of usable space, minus about one percent overhead. A sparse file can have a logical size of one terabyte. However, the actual amount of data that can be stored in a file is approximately one percent less than 1 TB because of the file system overhead.
The maximum number of subdirectories per directory in a UFS file system is 32,767. This limit is predefined and cannot be changed.