Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


Thetypedefstatement allows the shorterext2_direntto be used in place ofstruct ext2_dir_entry_2
in the kernel sources.

The names of the individual fields are more or less self-explanatory because they are directly based
on the scheme introduced in Chapter 8.inodeis a pointer to the inode of the directory entry;name_len
is the length of the directory entry string. The name itself is held in thenames[]arrayandmaybeupto
EXT2_NAME_LENcharacters long (the default value is 255).

Because the length of a directory entry must always be a multiple of 4, names may
be padded with up to three zero bytes (i.e., bytes with ASCII value 0). No zero bytes
need be added if the length of the name is divisible by 4 without a remainder.

file_typespecifies the directory entry type. This variable accepts one of the values defined in the fol-
lowingenumstructure:

<ext2_fs.h>
535
enum {
EXT2_FT_UNKNOWN,
EXT2_FT_REG_FILE,
EXT2_FT_DIR,
EXT2_FT_CHRDEV,
EXT2_FT_BLKDEV,
EXT2_FT_FIFO,
EXT2_FT_SOCK,
EXT2_FT_SYMLINK,
EXT2_FT_MAX
};

EXT2_FT_REG_FILEis used most frequently because it indicates a regular file (whose contents are of
no relevance).EXT2_FT_DIRalso occurs often and represents directories. The other constants denote
character-special and block-special files (BLKDEVandCHRDEV), FIFOs (named pipes;FIFO), sockets (SOCK),
and symbolic links (SYMLINK).

rec_lenis the only field in the directory structure whose meaning is not so obvious. It is an offset pointer
indicating the number of bytes between the end of therec_lenfieldandtheendofthenextrec_lenfield.
This enables the kernel to scan directories efficiently by jumping from one name to the next. By reference
to an example, Figure 9-6 shows how different directory entries are represented on hard disk.

lslists the contents of directories as follows:

wolfgang@meitner>ls -la
total 20
drwxr-xr-x 3 wolfgang users 4096 Feb 14 12:12.
drwxrwxrwt 13 wolfgang users 8192 Feb 14 12:12 ..
brw-r--r-- 1 wolfgang users 3, 0 Feb 14 12:12 harddisk
lrwxrwxrwx 1 wolfgang users 14 Feb 14 12:12 linux -> /usr/src/linux
-rw-r--r-- 1 wolfgang users 13 Feb 14 12:12 sample
drwxr-xr-x 2 wolfgang users 4096 Feb 14 12:12 sources
Free download pdf