Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


the representation of a 32-bit wide user and group identifier so that 2^32 =4,294,967,296 users can
be supported.
❑ i_sizeandi_blocksspecify the file size in bytes and blocks, where 512 bytes is always assumed
as the block size (this unit has nothing to do with the low-level block size of the filesystem and
is always constant). At first glance, it would be easy to suppose thati_blockscan always be
derived fromi_size. However, owing to optimization of the Ext2 filesystem, this is not the case.
Thefile holesmethod is used to ensure that files with longer empty sections do not waste space. It
keeps the space used by holes to a minimum and requires two fields to store the byte and block
length of a file.
❑ The pointers to the data blocks of a file are held in thei_blockarray that comprises
EXT2_N_BLOCKS. By default, this value is set to 12 + 3. The first 12 elements are used for direct
block addressing and the last three for implementing simple, double, and triple indirection.
Although theoretically this value can be changed at compilation time, this is not advisable
because it produces incompatibility with all other standard formats of Ext2.
❑ i_links_countis a counter to specify the number of hard links that point to an inode.
❑ i_file_aclandi_dir_aclsupport implementation ofaccess control liststhat permit
finer-grained control of access rights than is possible with the classicUnixapproach.
❑ Some elements of the inode are already defined but not yet in use. They are available for future
enhancements. For example,i_faddr,l_i_fsizeandl_i_fsizeare provided to store fragmen-
tation data so that the contents of several small files can be allocated to a single block.

How many inodes are there in each block group? The answer depends on the settings at filesystem
creation time. The number of inodes per block group can be set to any (reasonable) value when the
filesystem is created. This number is held in thes_inodes_per_groupfield. Because the inode structure
has a constant size of 120 bytes, this information and the block size can be used to determine the number
of blocks with inode structures. Regardless of the block size, the default setting is 128 inodes per block
group, an acceptable value for most scenarios.

Directories andFiles


Now that the principal aspects of infrastructure have been explained, let’s discuss the representation of
directories that define the topology of filesystems.As noted in Chapter 8, directories — as in classicUnix
filesystems — are nothing more than special files with pointers to inodes and their filenames to represent
files and subdirectories in the current directory. This is also true in the Second Extended Filesystem. Each
directory is represented by an inode to which data blocks are assigned. The blocks contain structures to
describe the directory entries. The data structure needed to do this is defined as follows in the kernel
sources:

<ext2_fs.h>
struct ext2_dir_entry_2 {
__le32 inode; /* Inode number */
__le16 rec_len; /* Directory entry length */
__u8 name_len; /* Name length */
__u8 file_type;
char name[EXT2_NAME_LEN]; /* File name */
};

typedef struct ext2_dir_entry_2 ext2_dirent;
Free download pdf