[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs

File System Layout

A file system is a set of files, directories, and other structures. File systems maintain information and identify where a file or directory's data is located on the disk. In addition to files and directories, file systems contain a boot block, a superblock, bitmaps, and one or more allocation groups. An allocation group contains disk i-nodes and fragments. Each file system occupies one logical volume.

Boot Block

The boot block occupies the first 4096 bytes of the file system starting at byte offset 0 on the disk. The boot block is available to start the operating system.

Superblock

The superblock is 4096 bytes in size and starts at byte offset 4096 on the disk. The super- block maintains information about the entire file system and includes the following fields:

Allocation Bitmaps

The file system contains two allocation bitmaps. The fragment allocation map records the allocation state of each fragment. The disk i-node allocation map records the status of each i-node.

Fragments

Many file systems have disk blocks or data blocks. These blocks divide the disk into units of equal size to store the data in a file or directory's logical blocks. The disk block may be further divided into fixed-size allocation units called fragments. Some systems do not allow fragment allocations to span the boundaries of the disk block. In other words, a logical block cannot be allocated fragments from different disk blocks.

The journaled file system (JFS), however, provides a view of the file system as a contiguous series of fragments. JFS fragments are the basic allocation unit and the disk is addressed at the fragment level. Thus, fragment allocations can span the boundaries of what might otherwise be a disk block. The default JFS fragment size is 4096 bytes, although you can specify smaller sizes. In addition to containing data for files and directories, fragments also contain disk addresses and data for indirect blocks. "File Space Allocation" explains how the operating system allocates fragments.

Disk I-Nodes

A logical block contains a file or directory's data in units of 4096 bytes. Each logical block is allocated fragments for the storage of its data. Each file and directory has an i-node that contains access information such as file type, access permissions, owner's ID, and number of links to that file. These i-nodes also contain "addresses" for finding the location on the disk where the data for a logical block is stored.

Each i-node has an array of numbered sections. Each section contains an address for one of the file or directory's logical blocks. These addresses indicate the starting fragment and the total number of fragments included in a single allocation. For example, a file with a size of 4096 bytes has a single address on the i-node's array. Its 4096 bytes of data are contained in a single logical block. A larger file with a size of 6144 bytes has two addresses. One address contains the first 4096 bytes and a second address contains the remaining 2048 bytes (a partial logical block). If a file has a large number of logical blocks, the i-node does not contain the disk addresses. Instead, the i-node points to an indirect block which contains the additional addresses.

Allocation Groups

The set of fragments making up the file system are divided into one or more fixed-sized units of contiguous fragments. Each unit is an allocation group. The first of these groups begins the file system and contains a reserved area occupying the first 32 x 4096 bytes of the group. The first 4096 bytes of this area hold the boot block and the second 4096 bytes hold the file system superblock.

Each allocation group contains a static number of contiguous disk i-nodes which occupy some of the group's fragments. These fragments are set aside for the i-nodes at file system creation and extension time. For the first allocation group, the disk i-nodes occupy the fragments immediately following the reserved block area. For subsequent groups, the disk i-nodes are found at the start of each group. Disk i-nodes are 128 bytes in size and are identified by a unique disk i-node number or i-number. The i-number maps a disk i-node to its location on the disk or to an i-node within its allocation group.

A file system's allocation groups are described by three sizes. The fragment allocation group size and the disk i-node allocation group size are specified as the number of fragments and disk i-nodes that exist in each allocation group. The default allocation group size is 8 MB. However, beginning in Version 4.2, it can be as large as 64 MB. These three values are stored in the file system superblock, and they are set at file system creation.

Allocation groups allow the JFS resource allocation policies to use effective methods for achieving good file system I/O performance. These allocation policies try to cluster disk blocks and disk i-nodes for related data to achieve good locality for the disk. Files are often read and written sequentially and files within a directory are often accessed together. Also, these allocation policies try to distribute unrelated data throughout the file system in an attempt to minimize free space fragmentation.

Using File System Subroutines

The most used file system subroutines are:

fscntl Controls file system control operations.
getfsent, getfsspec, getfsfile, getfstype, setfsent, or endfsent
Obtains information about a file system.
lseek Moves the read-write pointer.
mntctl Returns mount status information.
vmount or mount Makes a file system ready for use.
statfs, fstsfs, or ustat Reports file system statistics.
sync Updates file systems to disk.

Other subroutines are designed for use on virtual file systems (VFS):

getvfsent, getvfsbytype, getvfsbyname, getvfsbyflag, sevfsent, or endvfsent
Retrieves a virtual file system (vfs) entry.
umount or uvmount Removes vfs from the file tree.

Related Information

The mkfs command.

Working with JFS i-nodes describes the internal representation of files and lists the contents of the disk i-nodes and active (main memory) i-nodes.

Files, Directories, and File Systems for Programmers provides overview and orientation information for these topics.

Logical Volume Programming Overview.

How to Add a Journaled File System on a New Logical Volume

Creating New File System Types.

File Space Allocation


[ Previous | Next | Contents | Glossary | Home | Search ]