Linux File Systems

advertisement
Linux File Systems
One of the most important features of Linux is its support for many different file systems. It
accomplishes this through the implementation a feature known as the Virtual File System
(VFS).
5.1 Virtual File System
VFS allows Linux to support many, often very different, file systems. Each of these file
systems are presented to the VFS through a common software interface. The details of the
individual file systems are translated by software making the file systems appear identical to
the rest of the Linux kernel and to all of the other processes in the system. Through this VFS
layer, Linux allows you to transparently mount the many different file systems at the same
time. Consider the diagram in Figure 1 - File System Layers:
Figure 1 - File System Layers
The Linux VFS supports more then 15 file systems. Among PC and server files systems are:
ext, ext2, NTFS, FAT16, FAT 32, HPFA (IBM’s High Performance File System).
Linux is similar to Unix in the sense that the separate file systems are not accessed by device
identifiers (such as a drive number or a drive name). They are combined into a single
hierarchical tree structure that represents the file system as one complete entity. All of the
different file systems, are mounted onto their own separate directory. This directory is known
as the mount directory or mount point.
5.2 Individual File Systems
Devices, such as hard drives, that can contain file systems are known as block devices. The
Linux virtual file system regards these block devices as linear collections of blocks and does
not know or care about the underlying physical disk's geometry. For example, an IDE disk
partition /dev/hda1, the first partition of the first IDE disk drive in the system, is a block
device. The individually mounted file systems look, feel and operate in the same way no
matter where (locally or remotely over a network) or what physical device is implementing it.
5.3 Linux’s Native File System
The Second Extended File system (EXT2) is Linux’s native and most successful file system
and is the basis for all of the currently shipping Linux distributions. The Ext2 file system is
designed on the BSD Fast File System. A disk (or disk partition) is formatted to contain a set
of block groups (i.e. groups of sector clusters called blocks, each group can be n blocks in
length, each block can be up to 4KB), each of which contains a superblock (1 block), group
descriptor information (n blocks), a data block bitmap (1 block), inode bitmap (1 block), a
table of inodes (information nodes, each of which is a data record of 128 bytes in length) for
the files in the block group (n blocks), and the data blocks (n blocks or clusters of sectors).
Block groups are like logical sub-partitions that are used to reduce file fragmentation as Linux
stores individual files within a block group.
A superblock contains the following information:

The number of inodes

Number of free inodes

Block details

Allocation limits

Last mount and write times

Errors and Status
A block descriptor holds of descriptions of blocks within a block group. Block sizes may be
512-4096 bytes. A single block may contain descriptions for up to 8,192 blocks.
The EXT2 file system, like many other file systems, uses a data block (sector/cluster) as its
basic unit. Low-level formatted hard drives with 512 byte sectors are formatted to up to 4KB
blocks. The data blocks are all of the same length (e.g. 512 bytes or 1 disk sector, to 4KB or 8
sectors), although that length can vary.
EXT2 defines the file system by describing each file in the system with an inode data
structure. An inode is a data record in the inode table that describes which blocks on the
device are occupied by a particular file, as well as the access rights, modification times, and
type of the file. Every file in the EXT2 file system is represented by a single inode (an entry
in the block group’s inode table). Each inode is referenced by a single unique identifying
number, called the inode number, which is used to link the a file’s name/entry in a directory
file, to the inode structure in the inode table in the group block.
Each inode is 128 bytes in length and contains information such as file mode (a 16 bit entry
that indicates the file type (regular, directory, character, et.) owner/group/other
read/write/execute permissions) owner ID, Group ID, file size, time/date last modified,
time/date last accessed, and the file (block) addresses, which consist of 15 pointers to the data
blocks. 12 file data blocks are referenced directly by the inode, and the remainder (up to
1074791424) indirectly by data blocks acting as index pointers. Consider the diagram in
Figure 2 - EXT2 Inode. Here the inode uses an index allocation scheme that employ 12 direct
block pointers (to the block addresses to blocks 0-11): these are the physical block addresses
of the data blocks that actually contain the file data. Three indirect block entries (blocks 1214) hold pointers to index blocks, which contain the block addresses of the data blocks of
large files. The size of the blocks will dictate the number of indirect pointers, i.e. data block
addresses. For example, a 32 bit (4 byte) addressing scheme is used to locate individual
blocks. Thus, with 4KB blocks, a first indirect inode pointer references an index block that
contains the block addresses of 1024 data blocks (1024*4KB (4.096) = 4 MB of data, really
4,194,304 bytes). A file that uses 12 direct block pointers and 3 indirect pointers, with a
maximum size of 4,402,349,916,160 bytes or approx 4,000 GB. Table 1 indicates the
addressing/data storage features of EXT2FS. Please note that standard Unix file systems use
10 direct and three indirect pointers, with block sizes up to 1 KB (UNIX System V). This
gives over 16GB per file. In addition, data block/index addresses are just 24 bit (3 bytes). This
gives a smaller overall file size and inode data size.
Table 1 File Size and File Block Addressing using Inode File Structures
Inode Address Pointers
Data Blocks Addressed
File Size (4KB block)
12 Direct
12
48 KB
First Indirect
1024 (1*1024)
4,194,304 (4MB)
Second Indirect
1,048,576 (1*1024*1024)
4,294,967,296 (4GB)
Third Indirect
1,073,741,824
(1*1024*1024*1024)
4,398,046,511,104
GB)
(4,000
Figure 2 - EXT2 Inode Structure
The EXT2 file system is similar to many other file systems in the sense that the block devices
are simply a series of blocks that can be read from and written to. A file system does not care
where on the physical media a block resides. This is the job of the device's driver. When any
file system needs to read or write information or data on the block device, the supporting
device driver reads or writes the appropriate integral number of blocks containing the data.
Directories
EXT2 directories are simply special files (also represented by inodes) which contain pointers
to the inodes of their directory entries. Directories are structured in a hierarchical tree. Each
directory can contain files and subdirectories. Actually, a directory is simply a file containing
a list of entries. Each entry contains an inode number and a file name. When a process uses a
pathname, the kernel code searches in the directories to find the corresponding inode number.
After the name has been converted to an inode number, the inode is loaded into memory and
is used by subsequent requests.
Figure 3 Directory Entry Mapping to Inode Tables
Download