The inode information is kept in
the cylinder information block.
An inode contains all the information about a file except
its name, which is kept in a directory.
An inode is 128 bytes long.
One inode is created for every 2K of storage available in
the filesystem.
This parameter can be changed
when
mkfs(1M)
is used to create the filesystem.
What does a ufs inode contain?
A ufs inode contains the following:
type and mode of the file--the type can be regular,
directory, block, character,
symbolic link, or FIFO, also known as named pipe;
the mode is the set of read-write-execute permissions
The heart of the inode is two arrays that, together,
comprise 15 disk-block addresses.
The first array contains 12 direct addresses,
that is, addresses that point directly to
the first 12 logical storage blocks
of the contents of the file (addresses 0-11).
If the file is larger than 12 logical blocks,
the first address of the second array (address 0)
points to an indirect block, which
contains direct addresses instead of file contents.
The second address (1)
points to a double indirect block,
which contains addresses of indirect blocks.
The third address (2) points to a triple indirect block,
which contains addresses of double indirect blocks.
The following figure illustrates
this chaining of address blocks stemming from the inode.
The address chain in a ufs filesystem
The following table shows
the number of bytes addressable by
the different levels of indirection in
the inode address array for ufs filesystems.
These numbers are calculated using
the logical block size of the filesystem
and the number of bytes used to hold an address.
Maximum number of bytes addressable by
Logical
Block Size
Direct
Blocks
Single
Indirect
Blocks
Double
Indirect
Blocks
2048 bytes
24KB
1MB
512MB
4096 bytes
48KB
4MB
4GB
8192 bytes
96KB
16MB
32GB
The table shows
the number of bytes addressable using the level of
indirection in the column header
plus all lower levels of addressing.
For example, the table values
for single indirect blocks also
include bytes addressable by direct blocks;
and the table values for indirect blocks include
bytes addressable by direct blocks
and single indirect blocks.
In a filesystem with a 2048-byte block size,
files larger than 512MB use triple indirect blocks.
The theoretical maximum size of
a ufs filesystem is the same as the size
of a file addressable with triple indirection.
In practice, however, file size is limited by
the size field in the inode.
This is a signed 32-bit field, so file sizes are limited
to 2GB.
Because of the large size of ufs logical blocks,
double indirect blocks rarely appear
in ufs filesystems.
The result is that data retrieval in large files
is much quicker than it would otherwise be.