Figure 96 Representation of files 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_len field in Figure 9-6 is also clear. It indicates the number of bytes to be skipped after the end of the rec_len field to get to the start of the next entry, beginning with name_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_len of the entry before the entry to be deleted is set to a value that points to the entry after the entry to be deleted. The preceding list of directory contents does not include an entry for the deldir directory shown in Figure 9-6 because this directory was deleted. The value of the rec_len field in the entry before deldir is 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.

The type of a file is not defined in the inode itself but in the file_type field 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 files11 occupy data blocks on the hard disk. All other types are fully described by the information in the inode.

□ Symbolic links are 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. The i_block structure normally used to hold the addresses of file blocks consists of 15 32-bit entries (a total of 15 x 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.

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

□ Device files, named pipes, and persistent sockets are also fully described by the information in the inode. In memory, data also required are held in the inode structure of the VFS (i_cdev for character devices and i_rdev for block devices; all information can be reconstructed from these). On the hard disk the first element of the data pointer array i_data[0] is used to store the additional information; this does not cause any problems because device files require no data blocks; the same trick is used as with symbolic links.

Continue reading here: Data Structures in Memory

Was this article helpful?

0 0