ch7文件操作
ch7文件操作
In the imap, bits are stored linearly from low to high address. The first 16 bits
(from low to high) are b’11111111 11100000’, but they are printed as ff 07 in
HEX, which is not very informative since the bits are printed in reverse order,
i.e. from high to low address.
7.5.3 Display root Inode
In an EXT2 file system, the number 2 (count from 1) inode is the inode
of the root directory /.
The program in Example 7.3 displays the INODE information of the
root directory of an EXT2 file system.
7.5.4 Display Directory Entries
Each data block of a directory INODE contains dir_entries, which are
struct ext2_dir_entry_2 {
u32 inode; // inode number; count from 1, NOT 0
u16 rec_len; // this entry’s length in bytes
u8 name_len; // name length in bytes
u8 file_type; // not used
char name[EXT2_NAME_LEN]; // name: 1-255 chars, no
ending NULL
};
Thus, the contents of each data block of a directory has the form
[inode rec_len name_len NAME] [inode rec_len name_len NAME] ......
where NAME is a sequence of name_len chars (without a terminating
NULL).
The following algorithm shows how to step through the dir_entries in a
directory data block.