ext2-walkthrough
ext2-walkthrough
Two links were placed in mydir: a symbolic link to hello.txt, and a hard link to goodbye.txt
00001000 ff 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00001020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
*
only data block, which is 25 (hex, of course) __le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
__le32 i_generation; /* File version (for NFS) */
__le32 i_file_acl; /* File ACL */
__le32 i_dir_acl; /* Directory ACL */
00001480 ed 41 f4 03 00 04 00 00 ef 21 3c 44 9d 21 3c 44 |.A.......!<D.!<D| __le32 i_faddr; /* Fragment address */
00001490 9d 21 3c 44 00 00 00 00 f4 03 04 00 02 00 00 00 |.!<D............| union {
000014a0 00 00 00 00 00 00 00 00 25 00 00 00 00 00 00 00 |........%.......| struct {
000014b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| __u8 l_i_frag; /* Fragment number */
* __u8 l_i_fsize; /* Fragment size */
__u16 i_pad1;
__le16 l_i_uid_high; /* these 2 fields */
• Thus, the file’s data can be found at • Data block 0439 is at offset 10e400, which
offset 400 * 0438 = 10e000, and indeed should now be somewhat recognizable as an
the bytes are there! array of directory entries (note how . and ..
now refer to different inodes)
0010e400 0d 00 00 00 0c 00 01 02 2e 00 00 00 02 00 00 00 |................|
0010e410 0c 00 02 02 2e 2e 00 00 0f 00 00 00 14 00 0b 01 |................|
0010e420 67 6f 6f 64 62 79 65 2e 74 78 74 00 0e 00 00 00 |goodbye.txt.....|
0010e430 d4 03 09 07 68 65 6c 6c 6f 2e 74 78 74 00 00 00 |....hello.txt...|
0010e440 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
/*
* Ext2 directory file types. Only the • hello.txt’s directory entry lists its file type as 07, which,
* low 3 bits are used. The other bits
* are reserved for now. according to the source code, means a symbolic link
*/
enum {
EXT2_FT_UNKNOWN, /* 00 */
EXT2_FT_REG_FILE, /* 01 */
• When we look at inode e, we see that the symbolic link’s
EXT2_FT_DIR,
EXT2_FT_CHRDEV,
/* 02 */
/* 03 */
path is stored in the inode itself, where the data blocks
EXT2_FT_BLKDEV,
EXT2_FT_FIFO,
/* 04 */
/* 05 */
would normally be:
EXT2_FT_SOCK, /* 06 */
EXT2_FT_SYMLINK, /* 07 */ 00001a80 ff a1 f4 03 0c 00 00 00 d7 21 3c 44 83 21 3c 44 |.........!<D.!<D|
EXT2_FT_MAX /* 08 */ 00001a90 83 21 3c 44 00 00 00 00 f4 03 01 00 00 00 00 00 |.!<D............|
}; 00001aa0 00 00 00 00 00 00 00 00 2e 2e 2f 68 65 6c 6c 6f |........../hello|
00001ab0 2e 74 78 74 00 00 00 00 00 00 00 00 00 00 00 00 |.txt............|
00001ac0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*