[C Linux 内核] 文件系统(以ext2为例)
ext2文件系统的总体结构
每一个文件系统, 由若干个块组构成, 文件系统的最前面是大小固定(大小不能由用户指定,PC标准规定启动块大小为1KB)的一个启动快(Boot Block) 然后是若干块组, 每个块组内含有的信息为:
- 超级块(Super Block)
- 块组描述符表(Group Descriptor Table GDT)
- 块位图(Block Bitmap)
- inode位图(inode Bitmap)
- inode表(inode Table)
- 数据块(Data Block)
其中, 超级块是描述该文件系统(注意,不是该块)的基本信息,如 块大小, 文件系统版本号 等信息, 可以通过 dumpe2fs
的头部信息查看到superblock信息, 在该文件系统中,每一个块组的头部, 都有一份Superblock信息的copy
块组描述符表, 存储该块组的基本信息,每一个Block group一个
块位图, 每一个bit代表该块组中的一个块, 如果这个块被使用了, 则该bit为1 否则为0
inode位图, 和楼上类似,只不过这次每一个bit代表的是该inode块中的一个块, inode位图单独占一个块
inode表: 存储文件的基本描述信息, 如 文件类型, 权限, 大小, 文件的时间戳信息等, 都存储在inode块内, 多个inode块构成inode表, 而且特殊的, 一些不占用磁盘空间的文件 ,如 /dev/tty 这种设备文件, 内存映象文件等, 都只占用inode block,而不占用Data block
数据块: 数据块内数据的存储根据不同filetype有不同的情况:
- 对于regular file, 文件的数据存储在数据块中
- 对于目录文件, 该目录下的所有文件名和目录名存在数据块中, 注意, 一个 regular file的文件名不保存在他的数据块中, 而是保存在他目录的数据块中
- 对于符号链接, 如果目标路径短,则存在inode中, 否则, 要分配一个数据块来保存这个符号链接名
- 设备文件, FIFO socket等特殊文件没有数据块,只有inode块, 可以通过 ls -l /dev/tty 以及 对比 ls -l /etc/shadow 发现二者信息的不同
#ls -lh /dev/tty crw-rw-rw- 1 root tty 5, 0 May 8 16:01 /dev/tty #ls -lh /etc/shadow -rw------- 1 root root 1.6K Apr 26 09:15 /etc/shadow
下面我们就通过一个例子, 来演示一下, ext2文件系统的具体构成
首先, 在你的Linux下新建一个空的 1M大小的文件, 并把他做成一个 ext2 filesystem 具体做法参考下面的代码, 都是基本的命令, 不做解释
#create an empty file dd if=/dev/zero of=sample_fs bs=4K count=256 #format it to ext2 mkfs.ext2 sample_fs
这样之后, 你便得到了一个崭新的ext2文件系统, 它可以像普通的磁盘设备一样被挂载, 下面挂载一下这个文件系统, 看看里面有什么东西
mkdir mountpoint sudo mount sample_fs mountpoint
ls -l 看看信息, 然后umount 这个磁盘 我这里给出我改动过后(touch了一个biu 文件之后)的ls -al信息
total 17 drwxr-xr-x 3 root root 1024 May 7 22:14 . drwxr-xr-x 3 void001 void001 4096 May 8 17:06 .. -rw-r--r-- 1 root root 0 May 7 22:14 biu drwx------ 2 root root 12288 May 7 16:02 lost+found
你们看到的应该没有 biu 这个文件, 现在 我们umount掉这个磁盘, 看看这个磁盘的信息在sample_fs这一个二进制文件中是如何存储的
我们使用 od -tx1 -Ax sample_fs 来dump出整个ext2 filesystem的信息, 然后 对照着 dumpe2fs sample_fs 以及debugfs sample_fs 的信息,来一个byte一个byte的对应查看
首先 前面的1024个Byte是Boot block, 因为这不是一个可以启动的文件系统, 所以数据没有意义, 然后是superblock ,然后是 GDT 我们按照这个顺序给出相应的分析 在下面的分析文件中, 每一个数据域用” | |” 分割, 对它的解释用 逗号”,”分割
000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # Frist Position is Boot Block * 000400 |80 00 00 00|00 04 00 00|33 00 00 00|da 03 00 00| # Start of Super Block inode count = 0x80(128), block count = 0x0400(1024) reserved block count = 0x33(51) free blocks = 0x03da(986) 000410 |75 00 00 00|01 00 00 00|00 00 00 00 00 00 00 00| free inodes = 0x75(117), first block = 0x01(1), for log use(unused) 000420 |00 20 00 00|00 20 00 00|80 00 00 00|ea a3 2d 57 blocks = 0x2000(8192), fragments = 0x2000(8192), inodes/group = 0x80(128), lastmounttime = 0x572da3ea 000430 |45 a4 2d 57|02 00|ff ff|53 ef|01 00|01 00|00 00| last write time = 0x572da445, mount count = 0x03(2), max count = 0xffff, magic = 0xEF53, fs_state = 0x01(clean), err behavior = continue, minor rev = 0 000440 |1c a1 2d 57|00 00 00 00|00 00 00 00|01 00 00 00| last checked 0x572da11c, check interval = 0x00, os_type = 0x00(Linux), major rev = 0x01 000450 |00 00|00 00|0b 00 00 00|80 00|00 00|38 00 00 00| reserved blocks uid = 0x00, reserved blocks gid = 0x00, first nonreserved inode = 11 (So there are 128 -11 = 117 free inodes at this time (clean and new fs)), inode size = 0x80, block group = 0, compatible features= (0x38) 000460 |02 00 00 00 03 00 00 00|54 75 23 b2 e0 e2 41 3f compatible features, UUID = (这个不用管little endian) 547523b2-e0e2-413f-9982-579d7a986dc9 000470 99 82 57 9d 7a 98 6d c9| 00 00 00 00 00 00 00 00 UUID, continued, volumn name = NULL 000480 00 00 00 00 00 00 00 00|00 00 00 00|00|00|00 00 last mounted on = NULL, alogrithm usage bitmap, pre_alloc , prealloc, padding * 0004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 0004d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0004e0 00 00 00 00 00 00 00 00 00 00 00 00 61 eb 9a 73 0004f0 78 b3 41 27 98 04 5a 9f 4b b0 75 2b 01 00 00 00 000500 0c 00 00 00 00 00 00 00 1c a1 2d 57 00 00 00 00 000510 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 000560 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 000570 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 000800 |06 00 00 00|07 00 00 00|08 00 00 00|da 03|75 00| # Group Description Table(For this sample_fs only one block to store) block bitmap at 0x6, inode bitmap at 0x7, inode table at 0x8, freeblocks = 0x3da(986), free inodes = 0x75(117) 000810 |02 00|04 00 00 00 00 00 00 00 00 00 00 00 00 00| directories = 0x2, padding 000820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 001800 ff ff ff ff 1f 00 00 00 00 00 00 00 00 00 00 00 # Block Bitmap 001810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 001870 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 001880 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff * 001c00 ff 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # This line is Inode Bitmap (128 Bit already) ff 07 = 1111 1111 0000 0111 , That is 11 inodes (10 for fs reserve, one(inode no = 11) for lost+found directory, one (inode no = 2) for root directory) 001c10 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff * 002000 00 00 00 00 00 00 00 00 1c a1 2d 57 1c a1 2d 57 002010 1c a1 2d 57 00 00 00 00 00 00 00 00 00 00 00 00 002020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002080 |ed 41|00 00|00 04 00 00|40 a1 2d 57|1c a1 2d 57| # This is the inode block for root dir "/" (Inode 2) st_mode = 0x41ed = 040755(st_mode contains filetype & permission), user = 0, size = 1024, atime, ctime 002090 |1c a1 2d 57|00 00 00 00|00 00|03 00|02 00 00 00| mtime, dtime, group = 0000, links = 3("/", and ".", and".."), block_count = 2(512(Sector size = 512) * 2) 0020a0 |00 00 00 00|00 00 00 00|18 00 00 00|00 00 00 00| flags = 0x00, OS_Information, blocks[0] = 0x18(24)[This means the Block No.24 Contains data for this inode, and we can get the address for Block No.24(0x400 * 24 = 0x6000)], blocks[1] = 0 0020b0 |00 00 00 00|00 00 00 00|00 00 00 00|00 00 00 00| blocks[2] = 0, [3], [4], [5],... * 002300 80 81 00 00 00 30 04 04 1c a1 2d 57 1c a1 2d 57 002310 1c a1 2d 57 00 00 00 00 00 00 01 00 08 00 00 00 002320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002350 00 00 00 00 00 00 00 00 00 00 00 00 25 00 00 00 002360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002500 |c0 41|00 00|00 30 00 00|1c a1 2d 57|1c a1 2d 57| 002510 |1c a1 2d 57|00 00 00 00|00 00|02 00|18 00 00 00| 002520 |00 00 00 00|00 00 00 00|19 00 00 00|1a 00 00 00| 002530 |1b 00 00 00|1c 00 00 00|1d 00 00 00|1e 00 00 00| 002540 |1f 00 00 00|20 00 00 00|21 00 00 00|22 00 00 00| 002550 |23 00 00 00|24 00 00 00|00 00 00 00 00 00 00 00 002560 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006000 [|02 00 00 00|0c 00|01|02|2e 00 00 00|][02 00 00 00 # This is the data block for rootfs "/"( inode no 2, block no 24, type+permission 040755) [inode = 2, record len = 12(Len(inBytes) of one record, hereis 02 00 00 00 0c 00 01 02 2e 00 00 00), namelen = 1, filetype = 2(directory), content of the file (".")], [Next has the same format as prev record, only present the data:2,12,2,2(dir),".."] 006010 |0c 00|02|02|2e 2e 00 00|][|0b 00 00 00|e8 03|0a|02 006020 6c 6f 73 74 2b 66 6f 75 6e 64 00 00 00 00 00 00 006030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006400 [0b 00 00 00|0c 00|01|02|2e 00 00 00|][02 00 00 00| 006410 f4 03|02|02|2e 2e 00 00 00 00 00 00 00 00 00 00 006420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 006810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 006c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007400 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008400 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 009000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 009010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 009400 00 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 009410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 100000
在分析 superblock相应信息的时候, 对照 dumpe2fs 的信息来看, 这里给出一个样例
Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: 547523b2-e0e2-413f-9982-579d7a986dc9 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: ext_attr resize_inode dir_index filetype sparse_super large_file Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 128 Block count: 1024 Reserved block count: 51 Free blocks: 986 Free inodes: 117 First block: 1 Block size: 1024 Fragment size: 1024 Reserved GDT blocks: 3 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 128 Inode blocks per group: 16 Filesystem created: Sat May 7 16:02:36 2016 Last mount time: Sat May 7 16:14:34 2016 Last write time: Sat May 7 16:16:05 2016 Mount count: 2 Maximum mount count: -1 Last checked: Sat May 7 16:02:36 2016 Check interval: 0 (<none>) Lifetime writes: 3 kB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128 Default directory hash: half_md4 Directory Hash Seed: 61eb9a73-78b3-4127-9804-5a9f4bb0752b Group 0: (Blocks 1-1023) Primary superblock at 1, Group descriptors at 2-2 Reserved GDT blocks at 3-5 Block bitmap at 6 (+5), Inode bitmap at 7 (+6) Inode table at 8-23 (+7) 986 free blocks, 117 free inodes, 2 directories Free blocks: 38-1023 Free inodes: 12-128
在查看相应的文件的inode, data block的信息的时候, 对照 debugfs 的信息来看 (使用 debugfs 的 stat 命令)
上面只给出了Superblock GDT, block & inode bitmap, 以及 “/”的 inode, 和 datablock的分析, 下面请试着通过上述信息分析lost+found目录的inode, datablock (参考答案在下面)
000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # Frist Position is Boot Block * 000400 |80 00 00 00|00 04 00 00|33 00 00 00|da 03 00 00| # Start of Super Block inode count = 0x80(128), block count = 0x0400(1024) reserved block count = 0x33(51) free blocks = 0x03da(986) 000410 |75 00 00 00|01 00 00 00|00 00 00 00 00 00 00 00| free inodes = 0x75(117), first block = 0x01(1), for log use(unused) 000420 |00 20 00 00|00 20 00 00|80 00 00 00|ea a3 2d 57 blocks = 0x2000(8192), fragments = 0x2000(8192), inodes/group = 0x80(128), lastmounttime = 0x572da3ea 000430 |45 a4 2d 57|02 00|ff ff|53 ef|01 00|01 00|00 00| last write time = 0x572da445, mount count = 0x03(2), max count = 0xffff, magic = 0xEF53, fs_state = 0x01(clean), err behavior = continue, minor rev = 0 000440 |1c a1 2d 57|00 00 00 00|00 00 00 00|01 00 00 00| last checked 0x572da11c, check interval = 0x00, os_type = 0x00(Linux), major rev = 0x01 000450 |00 00|00 00|0b 00 00 00|80 00|00 00|38 00 00 00| reserved blocks uid = 0x00, reserved blocks gid = 0x00, first nonreserved inode = 11 (So there are 128 -11 = 117 free inodes at this time (clean and new fs)), inode size = 0x80, block group = 0, compatible features= (0x38) 000460 |02 00 00 00 03 00 00 00|54 75 23 b2 e0 e2 41 3f compatible features, UUID = (这个不用管little endian) 547523b2-e0e2-413f-9982-579d7a986dc9 000470 99 82 57 9d 7a 98 6d c9| 00 00 00 00 00 00 00 00 UUID, continued, volumn name = NULL 000480 00 00 00 00 00 00 00 00|00 00 00 00|00|00|00 00 last mounted on = NULL, alogrithm usage bitmap, pre_alloc , prealloc, padding * 0004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 0004d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0004e0 00 00 00 00 00 00 00 00 00 00 00 00 61 eb 9a 73 0004f0 78 b3 41 27 98 04 5a 9f 4b b0 75 2b 01 00 00 00 000500 0c 00 00 00 00 00 00 00 1c a1 2d 57 00 00 00 00 000510 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 000560 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 000570 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 000800 |06 00 00 00|07 00 00 00|08 00 00 00|da 03|75 00| # Group Description Table(For this sample_fs only one block to store) block bitmap at 0x6, inode bitmap at 0x7, inode table at 0x8, freeblocks = 0x3da(986), free inodes = 0x75(117) 000810 |02 00|04 00 00 00 00 00 00 00 00 00 00 00 00 00| directories = 0x2, padding 000820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 001800 ff ff ff ff 1f 00 00 00 00 00 00 00 00 00 00 00 # Block Bitmap 001810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 001870 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 001880 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff * 001c00 ff 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 # This line is Inode Bitmap (128 Bit already) ff 07 = 1111 1111 0000 0111 , That is 11 inodes (10 for fs reserve, one(inode no = 11) for lost+found directory, one (inode no = 2) for root directory) 001c10 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff * 002000 00 00 00 00 00 00 00 00 1c a1 2d 57 1c a1 2d 57 002010 1c a1 2d 57 00 00 00 00 00 00 00 00 00 00 00 00 002020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002080 |ed 41|00 00|00 04 00 00|40 a1 2d 57|1c a1 2d 57| # This is the inode block for root dir "/" (Inode 2) st_mode = 0x41ed = 040755(st_mode contains filetype & permission), user = 0, size = 1024, atime, ctime 002090 |1c a1 2d 57|00 00 00 00|00 00|03 00|02 00 00 00| mtime, dtime, group = 0000, links = 3("/", and ".", and".."), block_count = 2(512(Sector size = 512) * 2) 0020a0 |00 00 00 00|00 00 00 00|18 00 00 00|00 00 00 00| flags = 0x00, OS_Information, blocks[0] = 0x18(24)[This means the Block No.24 Contains data for this inode, and we can get the address for Block No.24(0x400 * 24 = 0x6000)], blocks[1] = 0 0020b0 |00 00 00 00|00 00 00 00|00 00 00 00|00 00 00 00| blocks[2] = 0, [3], [4], [5],... * 002300 80 81 00 00 00 30 04 04 1c a1 2d 57 1c a1 2d 57 002310 1c a1 2d 57 00 00 00 00 00 00 01 00 08 00 00 00 002320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002350 00 00 00 00 00 00 00 00 00 00 00 00 25 00 00 00 002360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 002500 |c0 41|00 00|00 30 00 00|1c a1 2d 57|1c a1 2d 57|# This is the inode block for "lost+found" dir (Inode 12) st_mode = 0x41c0(040700), user = 0, size = 0x3000(12288), atime, ctime 002510 |1c a1 2d 57|00 00 00 00|00 00|02 00|18 00 00 00| mtime, dtime, group = 0, links = 2, block_count = 0x18(size 512 * 0x18 = 12288) (actual block = 0x18 / 2 = 0xc) 002520 |00 00 00 00|00 00 00 00|19 00 00 00|1a 00 00 00| flags = 0x00, OS_info, Blocks[0] = 0x19(25), [1] = 0x1a, 002530 |1b 00 00 00|1c 00 00 00|1d 00 00 00|1e 00 00 00| [2],[3],[4], ... 002540 |1f 00 00 00|20 00 00 00|21 00 00 00|22 00 00 00| , ... 002550 |23 00 00 00|24 00 00 00|00 00 00 00 00 00 00 00 ,... 002560 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006000 [|02 00 00 00|0c 00|01|02|2e 00 00 00|][02 00 00 00 # This is the data block for rootfs "/"( inode no 2, block no 24, type+permission 040755) [inode = 2, record len = 12(Len(inBytes) of one record, hereis 02 00 00 00 0c 00 01 02 2e 00 00 00), namelen = 1, filetype = 2(directory), content of the file (".")], [Next has the same format as prev record, only present the data:2,12,2,2(dir),".."] 006010 |0c 00|02|02|2e 2e 00 00|][|0b 00 00 00|e8 03|0a|02 006020 6c 6f 73 74 2b 66 6f 75 6e 64 00 00 00 00 00 00 006030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006400 [0b 00 00 00|0c 00|01|02|2e 00 00 00|][02 00 00 00| # This is the datablock (Block 25) for "lost+found" [inode no = 0x0b(11), record len = 12, namelen = 1, filetype = 2(dir), content = "."] 006410 f4 03|02|02|2e 2e 00 00 00 00 00 00 00 00 00 00 [inode no = 0x02, record len = 0x0400 - 0xc = 0x03f4( This record use the whole space left in the block ), namelen = 2, filetype = 2, content = "..\0\0\0\.....\0"] 006420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 006810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 006c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 006c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007400 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 007c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 007c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008400 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008800 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 008c00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 008c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 009000 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 009010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 009400 00 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 009410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 * 100000
注:这个文件系统只有一个块组 , 每个块大小为1KB, 文件系统总共1024个块, 除去Boot block还有1023 块, 这些都属于
Group 0, 其中 Block 1是 超级块, 接下来的块由GDT给出, 通过GDT知道 BlockBitmap是 Block 6,Inode bitmap是block7, inode总共有128个(超级块的信息给出), 另外在读上面数据的时候,注意要用小端序来阅读(little endin)
One thought on “[C Linux 内核] 文件系统(以ext2为例)”
到此一游,立贴为证!