Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


source\0 \0

12 1 2. \0 \0 \0
12 22
16 84
32 57
16 62
16 61
16 7 2

..h\0 \0
hardd isk
linux \0 \0 \0
deldi r \0 \0
sampl e \0 \0

inode rec_lenname_lenfile_typename

Figure 9-6: Representation offiles and directories in the

Second Extended Filesystem


The first two entries are always.and..to point to the current and parent directory. The meaning of the
rec_lenfield in Figure 9-6 is also clear. It indicates the number of bytes to be skipped after the end of
therec_lenfield to get to the start of the next entry, beginning withname_len.

The filesystem code makes use of this information when deleting entries from a directory. To make it
unnecessary to shift the contents of the entire inode,rec_lenof the entrybeforethe entry to be deleted is
set to a value that points to the entryafterthe entry to be deleted. The preceding list of directory contents
does not include an entry for thedeldirdirectory shown in Figure 9-6 because this directory was deleted.
The value of therec_lenfield in the entry beforedeldiris 32, and this directs the filesystem code to the
next but one entry (sample) when it scans the directory contents. The detailed mechanisms used to delete
files/inodes are described in Section 9.2.4.

Naturally, files are also represented by inodes. It is clear how regular data files are represented, but there
are a number of file types where the filesystem must exercise special care. These include symbolic links,
device files, named pipes, and sockets.

Thetypeofafileisnotdefinedintheinodeitselfbutinthefile_typefield of the parent directory entry.
Nevertheless, the contents of an inode differ according to the file type it represents. It should be noted
that only directories and regular files^11 occupy data blocks on the hard disk. All other types are fully
described by the information in the inode.

❑ Symbolic linksare saved in their entirety in the inode if the name of the link target is less than 60
characters long. Because the inode itself does not provide a field for the target name of symbolic
links (this would, in fact, be a massive waste of space), a trick is used. Thei_blockstructure
normally used to hold the addresses of file blocks consists of 15 32-bit entries (a total of 15× 4 =
60 bytes), is assigned a new role and stores the target name of symbolic links.
If the target name comprises more than 60 characters, the filesystem allocates a data block to
store the string.

(^11) And also links with targets comprising more than 60 characters.

Free download pdf