<chapter id="fsfilesysappx-94408"><title>UFS File System (Reference)</title><highlights><para>This is a list of the reference information in this chapter.</para><itemizedlist><listitem><para><olink targetptr="fsfilesysappx-23724" remap="internal">Structure of Cylinder
Groups for UFS File Systems</olink></para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-20581" remap="internal">Customizing UFS File
System Parameters</olink></para>
</listitem>
</itemizedlist>
</highlights><sect1 id="fsfilesysappx-23724"><title>Structure of Cylinder Groups for UFS
File Systems</title><para>When you create a UFS file system, the disk slice is divided into cylinder
groups. A <emphasis>cylinder group</emphasis> 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.</para><informaltable frame="topbot"><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="colspec0" colwidth="36.36*"/><colspec colname="colspec1" colwidth="63.64*"/><thead><row rowsep="1"><entry><para>Block Type </para>
</entry><entry><para>Type of Information Stored</para>
</entry>
</row>
</thead><tbody><row><entry><para>Boot block</para>
</entry><entry><para>Information used when the system is booted</para>
</entry>
</row><row><entry><para>Superblock</para>
</entry><entry><para>Detailed information about the file system</para>
</entry>
</row><row><entry><para>Inode</para>
</entry><entry><para>All information about a file</para>
</entry>
</row><row><entry><para>Storage or data block</para>
</entry><entry><para>Data for each file</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>The following sections provide additional information about the organization
and function of these blocks.</para><sect2 id="fsfilesysappx-2"><title>Boot Block</title><para>The <emphasis>boot block</emphasis> 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 Kbytes in a slice.</para>
</sect2><sect2 id="fsfilesysappx-3"><title>Superblock</title><para>The <emphasis>superblock</emphasis> stores much of the information about
the file system, which includes the following:</para><itemizedlist><listitem><para>Size and status of the file system</para>
</listitem><listitem><para>Label, which includes the file system name and volume name</para>
</listitem><listitem><para>Size of the file system logical block</para>
</listitem><listitem><para>Date and time of the last update </para>
</listitem><listitem><para>Cylinder group size</para>
</listitem><listitem><para>Number of data blocks in a cylinder group</para>
</listitem><listitem><para>Summary data block</para>
</listitem><listitem><para>File system state</para>
</listitem><listitem><para>Path name of the last mount point</para>
</listitem>
</itemizedlist><para>Because the superblock contains critical data, multiple superblocks
are made when the file system is created.</para><para>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.</para>
</sect2><sect2 id="fsfilesysappx-4"><title>Inodes</title><para>An <emphasis>inode</emphasis> 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: </para><itemizedlist><listitem><para>The type of the file:</para><itemizedlist><listitem><para>Regular</para>
</listitem><listitem><para>Directory</para>
</listitem><listitem><para>Block special</para>
</listitem><listitem><para>Character special</para>
</listitem><listitem><para>FIFO, also known as named pipe</para>
</listitem><listitem><para>Symbolic link</para>
</listitem><listitem><para>Socket</para>
</listitem><listitem><para>Other inodes &ndash; Attribute directory and shadow (used
for ACLs)</para>
</listitem>
</itemizedlist>
</listitem><listitem><para>The mode of the file (the set of read-write-execute permissions)</para>
</listitem><listitem><para>The number of hard links to the file</para>
</listitem><listitem><para>The user ID of the owner of the file</para>
</listitem><listitem><para>The group ID to which the file belongs</para>
</listitem><listitem><para>The number of bytes in the file</para>
</listitem><listitem><para>An array of 15 disk-block addresses</para>
</listitem><listitem><para>The date and time the file was last accessed</para>
</listitem><listitem><para>The date and time the file was last modified</para>
</listitem><listitem><para>The date and time the inode was changed</para>
</listitem>
</itemizedlist><para>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.</para><figure id="fsfilesysappx-fig-5"><title id="fsfilesysappx-44569">Address Chain
for a UFS File System</title><mediaobject><imageobject><imagedata entityref="fig3183.epsi"/>
</imageobject><textobject><simpara>Graphic of relationship between the address array of
a UFS inode and the indirect and double indirect pointers to a file's storage
blocks.</simpara>
</textobject>
</mediaobject>
</figure>
</sect2><sect2 id="fsfilesysappx-6"><title>Data Blocks</title><para><emphasis>Data blocks</emphasis>, also called <emphasis>storage blocks</emphasis>,
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-Kbyte logical block size, and
a 1-Kbyte fragment size.</para><para>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.</para>
</sect2><sect2 id="fsfilesysappx-7"><title>Free Blocks</title><para>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.</para><para>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.</para><figure id="fsfilesysappx-fig-8"><title id="fsfilesysappx-34155">A Typical
UFS File System</title><mediaobject><imageobject><imagedata entityref="fig3184.epsi"/>
</imageobject><textobject><simpara>Graphic of UFS cylinder groups with boot blocks (8 Kbytes
in cylinder group 0 only), superblock, cylinder group map, inodes, and storage
blocks.</simpara>
</textobject>
</mediaobject>
</figure>
</sect2>
</sect1><sect1 id="fsfilesysappx-20581"><title>Customizing UFS File System Parameters</title><para>Before you alter the default file system parameters that are assigned
by the <command>newfs</command> command, you need to understand them. This
section describes these parameters:</para><itemizedlist><listitem><para><olink targetptr="fsfilesysappx-9" remap="internal">Logical Block Size</olink></para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-10" remap="internal">Fragment Size</olink></para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-11" remap="internal">Minimum Free Space</olink></para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-12" remap="internal">Rotational Delay</olink> (Obsolete)</para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-13" remap="internal">Optimization Type</olink></para>
</listitem><listitem><para><olink targetptr="fsfilesysappx-14" remap="internal">Number of Inodes (Files)</olink></para>
</listitem>
</itemizedlist><para>For a description of the command options that customize these parameters,
see <olink targetdoc="refman1m" targetptr="newfs-1m" remap="external"><citerefentry><refentrytitle>newfs</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink> and <olink targetdoc="refman1m" targetptr="mkfs-ufs-1m" remap="external"><citerefentry><refentrytitle>mkfs_ufs</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink>.</para><sect2 id="fsfilesysappx-9"><title>Logical Block Size</title><para>The <emphasis>logical block size</emphasis> is the size of the blocks
that the <trademark class="registered">UNIX</trademark> 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.</para><para>Logical block size is set to the page size of the system by default.
The default logical block size is 8192 bytes (8 Kbytes) for UFS file systems.
The UFS file system supports block sizes of 4096 or 8192 bytes (4 or 8 Kbytes).
The recommended logical block size is 8 Kbytes.</para><note arch="sparc"><para>You can specify only the 8192-byte block size on
the <trademark>sun-4u</trademark> platform.</para>
</note><para>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-Kbyte file system provides the best performance, offering a good balance
between disk performance and the use of space in primary memory and on disk.</para><para>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 <command>quot -c</command> <replaceable>filesystem</replaceable> command
on a file system to display a complete report on the distribution of files
by block size.</para><para>However, the page size set when the file system is created is probably
the best size in most cases.</para>
</sect2><sect2 id="fsfilesysappx-10"><title>Fragment Size</title><para>As files are created or expanded, they are allocated disk space in either
full logical blocks or portions of logical blocks called <emphasis>fragments</emphasis>.
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.</para><para>The ability to allocate fragments of blocks to files, rather than just
whole blocks, saves space by reducing <emphasis>fragmentation</emphasis> of
disk space that results from unused holes in blocks.</para><para>You define the <emphasis>fragment size</emphasis> when you create a
UFS file system. The default fragment size is 1 Kbyte. 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-Kbyte file systems only). The lower bound is actually
tied to the disk sector size, typically 512 bytes.</para><para>For multiterabyte file systems, the fragment size must be equal to the
file system block size.</para><note><para>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.</para>
</note><para>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.</para>
</sect2><sect2 id="fsfilesysappx-11"><title>Minimum Free Space</title><para>The <emphasis>minimum free space</emphasis> is the percentage of the
total disk space that is held in reserve when you create the file system.
The default reserve is ((64 Mbytes/partition size) * 100), rounded down to
the nearest integer and limited between 1 percent and 10 percent, inclusively. </para><para>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.</para><para>Commands such as <command>df</command> 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.</para><para>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 <command>tunefs</command> command.</para>
</sect2><sect2 id="fsfilesysappx-12"><title>Rotational Delay</title><para>This parameter is obsolete. The value is always set to 0, regardless
of the value you specify.</para>
</sect2><sect2 id="fsfilesysappx-13"><title>Optimization Type</title><para>The <emphasis>optimization type</emphasis> parameter is set to either <emphasis>space</emphasis> or <emphasis>time</emphasis>.</para><itemizedlist><listitem><para><emphasis role="strong">Space &ndash;</emphasis> When you
select space optimization, disk blocks are allocated to minimize fragmentation
and disk use is optimized. </para>
</listitem><listitem><para><emphasis role="strong">Time &ndash;</emphasis> 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 <replaceable>time</replaceable>.</para><para>You can change
the value of the optimization type parameter for an existing file system by
using the <command>tunefs</command> command.</para>
</listitem>
</itemizedlist><para>For more information, see <olink targetdoc="refman1m" targetptr="tunefs-1m" remap="external"><citerefentry><refentrytitle>tunefs</refentrytitle><manvolnum>1M</manvolnum></citerefentry></olink>.</para>
</sect2><sect2 id="fsfilesysappx-14"><title>Number of Inodes (Files)</title><para>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.</para><para>The default number of bytes per inode is 2048 bytes (2 Kbytes) if the
file system is less than 1 Gbyte. If the file system is larger than 1 Gbyte,
the following formula is used:</para><informaltable frame="topbot"><tgroup cols="2" colsep="0" rowsep="0"><colspec colname="colspec0" colwidth="50*"/><colspec colname="colspec1" colwidth="50*"/><thead><row rowsep="1"><entry><para>File System Size</para>
</entry><entry><para>Number of Bytes Per Inode</para>
</entry>
</row>
</thead><tbody><row><entry><para>Less than or equal to 1 Gbyte</para>
</entry><entry><para>2048</para>
</entry>
</row><row><entry><para>Less than 2 Gbytes</para>
</entry><entry><para>4096</para>
</entry>
</row><row><entry><para>Less than 3 Gbytes</para>
</entry><entry><para>6144</para>
</entry>
</row><row><entry><para>3 Gbytes up to 1 Tbyte</para>
</entry><entry><para>8192</para>
</entry>
</row><row><entry><para>Greater than 1 Tbyte or created with <option>T</option> option</para>
</entry><entry><para>1048576</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>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.</para>
</sect2><sect2 id="fsfilesysappx-8"><title>Maximum UFS File and File System Size</title><para>The maximum size of a UFS file system is about 16 Tbytes of usable space,
minus about one percent overhead. A <emphasis>sparse</emphasis> 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 Tbyte because
of the file system overhead.</para>
</sect2><sect2 id="fsfilesysappx-5"><title>Maximum Number of UFS Subdirectories</title><para>The maximum number of subdirectories per directory in a UFS file system
is 32,767. This limit is predefined and cannot be changed.</para>
</sect2>
</sect1>
</chapter>