Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


9.2.2 Data Structures


Now that we have considered the structural principles underlying the Ext2 filesystem, let’s take a closer
look at the data structures used to implement and store data on the hard disk. As noted above, the struc-
tures on the hard disk have counterparts in memory. These are used in addition to the virtual filesystem
structures, first to support communication with the filesystem and to simplify the management of impor-
tant data, and second to buffer metadata to speed up work with the filesystem.

Superblock


Thesuperblockis the central structure in which all characteristic data of the filesystem are kept. Its contents
are the first thing the kernel sees when mounting a filesystem. Data are read using theext2_read_super
routine (located infs/ext2/super.c) invoked by means of theread_superfunction pointer in the
file_system_typestructure discussed in Chapter 8. The actions performed by this routine are analyzed
in Section 9.2.4. The structure and layout of the superblock on the hard disk concern us here.

The relatively extensiveext2_super_blockstructure is used to define the superblock as follows:

<ext2_fs.h>
struct ext2_super_block {
__le32 s_inodes_count; /* Inodes count */
__le32 s_blocks_count; /* Blocks count */
__le32 s_r_blocks_count; /* Reserved blocks count */
__le32 s_free_blocks_count; /* Free blocks count */
__le32 s_free_inodes_count; /* Free inodes count */
__le32 s_first_data_block; /* First Data Block */
__le32 s_log_block_size; /* Block size */
__le32 s_log_frag_size; /* Fragment size */
__le32 s_blocks_per_group; /* # Blocks per group */
__le32 s_frags_per_group; /* # Fragments per group */
__le32 s_inodes_per_group; /* # Inodes per group */
__le32 s_mtime; /* Mount time */
__le32 s_wtime; /* Write time */
__le16 s_mnt_count; /* Mount count */
__le16 s_max_mnt_count; /* Maximal mount count */
__le16 s_magic; /* Magic signature */
__le16 s_state; /* File system state */
__le16 s_errors; /* Behaviour when detecting errors */
__le16 s_minor_rev_level; /* minor revision level */
__le32 s_lastcheck; /* time of last check */
__le32 s_checkinterval; /* max. time between checks */
__le32 s_creator_os; /* OS */
__le32 s_rev_level; /* Revision level */
__le16 s_def_resuid; /* Default uid for reserved blocks */
__le16 s_def_resgid; /* Default gid for reserved blocks */
/*
* These fields are for EXT2_DYNAMIC_REV superblocks only.
*
* Note: the difference between the compatible feature set and
* the incompatible feature set is that if there is a bit set
* in the incompatible feature set that the kernel doesn’t
* know about, it should refuse to mount the filesystem.
*
* e2fsck’s requirements are more strict; if it doesn’t know
Free download pdf