Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


The data block in which the superblock is located is then read bysb_bread.Thisisawrapperforthe
__breadfunction described in Chapter 16. A simple typecast converts the raw data returned by the
function into an instance of typeext2_super_block.^15

A check is now made to establish whether the partitionused actually contains a Second Extended Filesys-
tem. The magic number stored in the superblock holds the required information. Its value must match
that of theEXT2_SUPER_MAGICconstant. If the check fails, the mount operation is aborted, and an error
message indicates that an attempt wasmade to mount a non-Ext2 filesystem.

parse_optionsanalyzes the parameters passed to specify mount options (such as the use of access
control lists or enhanced attributes). All values are set to their defaults before this is done to ensure that
not specifying an option is equivalent to specifying the default value.

A check of the filesystem features reveals whether the kernel is able to mount the filesystem at all, in Read
and Write mode, or in Read mode only (the enhancement features of Ext2 are discussed in Section 9.2.2).
The bit strings stored ins_feature_ro_compatands_feature_incompatare compared with the corre-
sponding kernel constants. Two constants are defined for this purpose:EXT2_FEATURE_INCOMPAT_SUPP
contains all incompatible features together, whileEXT2_FEATURE_RO_COMPATcontains all bits for compat-
ible features that can only be handled Read Only. Filesystem mounting is rejected if bits are set whose
meaning is not clear to the kernel or if any incompatible bits are set. Mounting is also rejected if any of
the bits inEXT2_FEATURE_RO_COMPATare set and the mount options do not specify the Read Only flag.

If the filesystem block size stored ins_blocksizedoes not match the initially specified minimum value,
the hard disk is set to this value usingset_blocksize, and the superblock is read again. The work of the
kernel is simplified if the same block size is used in the filesystem and for data transfer because filesystem
blocks can then be read in a single step.

Meta-information on the filesystem that should always reside in memory is held in theext2_sb_info
data structure (described in Section 9.2.2), which is now filled. Generally, this information comprises
simple value allocations that copy data from the hard disk into the corresponding elements of the data
structure.

The group descriptors are then read in block-by-block and checked for consistency by
ext2_check_descriptors.

The last steps when filling superblock information are performed byext2_count_free_blocks,
ext2_count_free_inodes,andext2_count_dirs, which count the number of free blocks, the number
of free inodes, and the number of directories, respectively. These numbers are needed by the Orlov
allocator discussed in Section 9.2.4, for instance. Note that the values are stored in an approximative
counter that starts with correct initial values, but can deviate slightly from the proper count during
operation.

Control is now transferred toext2_setup_super, which runs several final checks and outputs appro-
priate warnings (if, e.g., a filesystem is mounted in an inconsistent state, or if the maximum number
of mounts without a consistency check has been exceeded). As a final step,ext2_write_superwrites
the contents of the superblock back to the underlying storage medium. This is necessary because some
superblock values are modified during the mount operation — the mount count and date of last mount,
for example.

(^15) An offset must be added if the superblock doesn’t start at a hardware sector boundary.

Free download pdf