Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


To ensure filesystem portability between systems, the designers of the Ext2 filesystem decided to store
all numerical values of the superblock structure in little endian arrangement on the hard disk. When
data are read into memory, the kernel is therefore responsible for converting this format into the native
format of the CPU. The two filesbyteorder/big_endian.handbyteorder/little_endian.hprovide
routines for converting between the individual CPU types. Because the data of Ext2 filesystems are
stored in little endian format by default, no conversion is necessary on CPU types such as IA-32 and
AMD64. This delivers a slight speed advantage over systems such as Sparc that are forced to swap the
order of the bytes for types with more than 8 bits.^8

The superblock structure itself consists of an extensive collection of numbers to characterize the general
properties of the filesystem. Its size is always 1,024 bytes. This is achieved by padding the end of the
structure with a filler element (s_reserved).

Because the meaning of most entries is clear from the element name or associated comment, only those
that are of interest and not self-explanatory are discussed.

❑ s_log_block_sizeis the binary logarithm of the block size used divided by 1,024. Currently,
the three values 0, 1, and 2 are used, giving block sizes of 2^0 ×1,024=1,024, 2^1 ×1,024=2,048,
and 2^2 ×1,024=4,096 bytes. Minimum and maximum block sizes are currently limited to
1024 and 4096 , respectively, by means of the kernel constantsEXT2_MIN_BLOCK_SIZEand
EXT2_MAX_BLOCK_SIZE.^9
The desired block size must be specified during filesystem creation withmke2fs. It cannot be
changed during current operation as it representsa fundamental filesystem constant. The system
administrator must decide on a reasonable block size commensurate with the anticipated use of
the filesystem. A balance must be struck betweenwasted storage space and costly administration
effort — no simple undertaking. Nevertheless, nearly all distributions relieve the administrator
from this burden and provide reasonable default settings based on heuristic experience.
❑ s_blocks_per_groupands_inodes_per_groupdefine the number of blocks and inodes in each
block group. These values must also be fixed when the filesystem is created because they can-
not be modified thereafter. In most cases, it is advisable to use the default settings selected by
mke2fs.
❑ A magic number is stored in thes_magicfield. This number ensures that a filesystem to be
mounted really is of type Ext2. It is stored with the value0xEF53inEXT2_SUPER_MAGIC(in
ext2_fs.h). Thes_rev_levelands_minor_rev_levelfields accept a revision number to
differentiate between filesystem versions.

Even though a Second Extended Filesystem may be uniquely identifiable by this
number, there is still no guarantee that the kernel can really mount it in Read/Write
mode (or even in Read mode). Because Ext2 supports a series of optional and/or
incompatible extensions (as you will see shortly), it is necessary to check several
other fields in addition to the magic number field before a filesystem can be
mounted.

(^8) The endianness of a CPU has no effect on file contents if files are interpreted byte-by-byte as is the case, for example, with text files
(in files of this kind, numbers are stored as a text string, thus avoiding the problem of endianness). Sound files, on the other hand,
must often be converted between different representations using appropriate tools —sox, for example — because the arrangement
of bits is of relevance for binary interpretation of the data.
(^9) Note that the upper limit is currently not checked by the kernel.

Free download pdf