相关链接:ext2/ext3文件系统原理
漫谈Linux标准的文件系统(Ext2/Ext3/Ext4)
首先通过创建一个64M虚拟磁盘,在对该虚拟磁盘格式化成ext3文件系统,分析里面的数据
dd if=/dev/zero of=./test.img bs=1M count=64
将磁盘格式化为block size=1024,卷标为“HelloFs”,ext3文件系统
mkfs.ext3 -L HelloFs -b 1024 /dev/loop1
dumpe2fs /dev/loop1命令可查看更详细的磁盘信息
[root@centos7 file]# dumpe2fs /dev/loop1
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: HelloFs
Last mounted on: /mnt
Filesystem UUID: 6f99977c-cfa5-4007-945f-75f524db865e
Filesystem magic number: 0xEF53
... ...
Inode count: 16384
Block count: 65536
Reserved block count: 3276
Free blocks: 58056
Free inodes: 16371
First block: 1
Block size: 1024
Fragment size: 1024
Reserved GDT blocks: 255
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 2048
Inode blocks per group: 256
... ...
First inode: 11
Inode size: 128 ///Inode size可能是128/256
Journal inode: 8
... ...
Group 0: (Blocks 1-8192)
主 superblock at 1, Group descriptors at 2-2
保留的GDT块位于 3-257
Block bitmap at 258 (+257), Inode bitmap at 259 (+258)
Inode表位于 260-515 (+259)
7660 free blocks, 2035 free inodes, 2 directories
可用块数: 530, 532-1028, 1030-1536, 1538-8192
可用inode数: 12, 15-2048
Group 1: (Blocks 8193-16384)
备份 superblock at 8193, Group descriptors at 8194-8194
保留的GDT块位于 8195-8449
Block bitmap at 8450 (+257), Inode bitmap at 8451 (+258)
Inode表位于 8452-8707 (+259)
7677 free blocks, 2048 free inodes, 0 directories
可用块数: 8708-16384
可用inode数: 2049-4096
mount /dev/loop1 /mnt/ 挂载磁盘到/mnt目录,创建 test.fs 和 hello.c测试文件
Inode表位于 260-515 (+259)
dd if=/dev/loop1 bs=1024 count=1 skip=1537 | xxd | less
0000000: 0000 0000 0000 0000 cdae b162 cdae b162 ...........b...b
0000010: cdae b162 0000 0000 0000 0000 0000 0000 ...b............
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000080: ed41 0000 0004 0000 3baf b162 39af b162 .A......;..b9..b
0000090: 39af b162 0000 0000 0000 0300 0200 0000 9..b............
00000a0: 0000 0000 0e00 0000 0402 0000 0000 0000 ................
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000100: 0000 0000 0000 0000 0000 0000 0000 0000 ................
Inode2分析:0x204(516)
0000000: 0200 0000 0c00 0102 2e00 0000 0200 0000 ................
0000010: 0c00 0202 2e2e 0000 0b00 0000 2800 0a02 ............(...
0000020: 6c6f 7374 2b66 6f75 6e64 0000 0c00 0000 lost+found......
0000030: 1400 0c01 2e68 656c 6c6f 2e63 2e73 7770 .....hello.c.swp
0000040: 0d00 0000 1000 0701 7465 7374 2e66 7373 ........test.fss
0000050: 0e00 0000 b003 0701 6865 6c6c 6f2e 6363 ........hello.cc
0000060: 2e73 7778 0000 0000 0000 0000 0000 0000 .swx............
Inode13分析:(13 -1 ) * 128 = 1536 ,1536 - 1024 = 512(0x200),
Inode13,14都是block是260+1=261,偏移分别为0x200,0x280
dd if=/dev/loop1 bs=1024 count=1 skip=261 | xxd | less
0000200: a481 0000 1a00 0000 2eaf b162 2eaf b162 ...........b...b
0000210: 2eaf b162 0000 0000 0000 0100 0400 0000 ...b............
0000220: 0000 0000 0100 0000 0106 0000 0000 0000 ................
0000230: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000240: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000250: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000260: 0000 0000 dd9b 4097 1302 0000 0000 0000 ......@.........
0000270: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000280: a481 0000 1700 0000 39af b162 39af b162 ........9..b9..b
0000290: 39af b162 0000 0000 0000 0100 0400 0000 9..b............
00002a0: 0000 0000 0100 0000 0504 0000 0000 0000 ................
00002b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00002e0: 0000 0000 e19b 4097 1302 0000 0000 0000 ......@.........
00002f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
Inode13 0x601(1537)
Inode14 0x405 (1029)
dd if=/dev/loop1 bs=1024 count=1 skip=1537 | xxd | less
0000000: 3132 3334 3536 3738 3961 6263 6465 6565 123456789abcdeee
0000010: 6565 6565 6565 6565 650a 0000 0000 0000 eeeeeeeee.......
dd if=/dev/loop1 bs=1024 count=1 skip=1029 | xxd | less
0000000: 6865 6c6c 6f68 656c 6c6f 2d2d 2d2d 2d2d hellohello------
0000010: 2d2d 2d2d 2d2d 0a00 0000 0000 0000 0000 ------..........
[root@centos7 file]# debugfs /dev/loop1
debugfs 1.42.9 (28-Dec-2013)
debugfs:
debugfs:
debugfs: ls
2 (12) . 2 (12) .. 11 (40) lost+found 13 (16) test.fs
14 (944) hello.c
debugfs: cat test.fs
123456789abcdeeeeeeeeeeee
debugfs: cat hello.c
hellohello------------
debugfs:
参考文档:ext3文件系统分析