• 存储介质中ext4的文件排布


    0、说明

            本文主要解析磁盘介质中,是如何排布来存储数据的。比如挂载文件系统后,在目录创建一个text.txt文件,里面存储了hello内容。

            磁盘中都有哪些信息,磁盘只存储数据吗?

            磁盘中hello的放在什么位置,如何找到它的。

            本文需要有一些文件系统基础,比如inode。

    1、分区信息验证实验

    1.1、制作小分区

            SD卡制作一个1M的小分区,然后将SD数据填充为全0,1M的一个分区,是为了方便查看里面所有内容。

    1.2、格式化分区为ext4文件系统

            把sd插入到ubuntu等中,格式化sd卡为ext4文件系统。

    mkfs.ext4 /dev/sdb1

    1.3、备份文件系统分区

            将格式化好的文件系统制作成bin文件,方便后续恢复到最初格式化的状态。

     dd if=/dev/mmcblk0p1 of=/ext4_orig.bin

    磁盘信息如下:

            下面的内容就是在格式化该分区为ext4后的所有内容。

    1. [root@OIL ~]# hexdump -C ext4_orig.bin
    2. 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    3. *
    4. 00000400 80 00 00 00 00 04 00 00 33 00 00 00 d6 03 00 00 |........3.......|
    5. 00000410 75 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 |u...............|
    6. 00000420 00 20 00 00 00 20 00 00 80 00 00 00 00 00 00 00 |. ... ..........|
    7. 00000430 69 1d 07 63 00 00 ff ff 53 ef 01 00 01 00 00 00 |i..c....S.......|
    8. 00000440 69 1d 07 63 00 00 00 00 00 00 00 00 01 00 00 00 |i..c............|
    9. 00000450 00 00 00 00 0b 00 00 00 80 00 00 00 38 00 00 00 |............8...|
    10. 00000460 c2 02 00 00 6b 04 00 00 fc 5d 80 f1 b1 46 44 10 |....k....]...FD.|
    11. 00000470 a4 0e be ec c1 01 17 c4 00 00 00 00 00 00 00 00 |................|
    12. 00000480 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    13. *
    14. 000004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 |................|
    15. 000004d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    16. 000004e0 00 00 00 00 00 00 00 00 00 00 00 00 6b ac d7 31 |............k..1|
    17. 000004f0 f4 72 4a fb 9a da db 5e ff 31 e5 79 01 00 40 00 |.rJ....^.1.y..@.|
    18. 00000500 0c 00 00 00 00 00 00 00 69 1d 07 63 00 00 00 00 |........i..c....|
    19. 00000510 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    20. *
    21. 00000560 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    22. 00000570 00 00 00 00 04 01 00 00 5a 00 00 00 00 00 00 00 |........Z.......|
    23. 00000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    24. *
    25. 000007f0 00 00 00 00 00 00 00 00 00 00 00 00 d5 1b 3e 5b |..............>[|
    26. 00000800 0a 00 00 00 1a 00 00 00 2a 00 00 00 d6 03 75 00 |........*.....u.|
    27. 00000810 02 00 00 00 00 00 00 00 aa 2f cb d5 75 00 95 4c |........./..u..L|
    28. 00000820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    29. 00000830 00 00 00 00 00 00 00 00 f3 cf b5 92 00 00 00 00 |................|
    30. 00000840 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    31. *
    32. 00002800 ff ff 7f 06 00 fe ff 01 00 00 00 00 00 00 00 00 |................|
    33. 00002810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    34. *
    35. 00002870 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 |................|
    36. 00002880 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
    37. *
    38. 00002c00 02 00 00 00 0c 00 01 02 2e 00 00 00 02 00 00 00 |................|
    39. 00002c10 0c 00 02 02 2e 2e 00 00 0b 00 00 00 dc 03 0a 02 |................|
    40. 00002c20 6c 6f 73 74 2b 66 6f 75 6e 64 00 00 00 00 00 00 |lost+found......|
    41. 00002c30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    42. *
    43. 00002ff0 00 00 00 00 00 00 00 00 0c 00 00 de 79 67 de 4c |............yg.L|
    44. 00003000 0b 00 00 00 0c 00 01 02 2e 00 00 00 02 00 00 00 |................|
    45. 00003010 e8 03 02 02 2e 2e 00 00 00 00 00 00 00 00 00 00 |................|
    46. 00003020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    47. *
    48. 000033f0 00 00 00 00 00 00 00 00 0c 00 00 de 6a 8e 73 26 |............j.s&|
    49. 00003400 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    50. 00003410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    51. *
    52. 000037f0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    53. 00003800 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    54. 00003810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    55. *
    56. 00003bf0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    57. 00003c00 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    58. 00003c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    59. *
    60. 00003ff0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    61. 00004000 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    62. 00004010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    63. *
    64. 000043f0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    65. 00004400 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    66. 00004410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    67. *
    68. 000047f0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    69. 00004800 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    70. 00004810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    71. *
    72. 00004bf0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    73. 00004c00 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    74. 00004c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    75. *
    76. 00004ff0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    77. 00005000 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    78. 00005010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    79. *
    80. 000053f0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    81. 00005400 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    82. 00005410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    83. *
    84. 000057f0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    85. 00005800 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    86. 00005810 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    87. *
    88. 00005bf0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    89. 00005c00 00 00 00 00 f4 03 00 00 00 00 00 00 00 00 00 00 |................|
    90. 00005c10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    91. *
    92. 00005ff0 00 00 00 00 00 00 00 00 0c 00 00 de 14 bf a6 d2 |................|
    93. 00006000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    94. *
    95. 00006800 ff 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    96. 00006810 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
    97. *
    98. 00006c00 00 00 00 00 03 00 00 00 04 00 00 00 05 00 00 00 |................|
    99. 00006c10 06 00 00 00 07 00 00 00 08 00 00 00 09 00 00 00 |................|
    100. 00006c20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    101. *
    102. 0000a800 00 00 00 00 00 00 00 00 69 1d 07 63 69 1d 07 63 |........i..ci..c|
    103. 0000a810 69 1d 07 63 00 00 00 00 00 00 00 00 00 00 00 00 |i..c............|
    104. 0000a820 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    105. *
    106. 0000a870 00 00 00 00 00 00 00 00 00 00 00 00 ca aa 00 00 |................|
    107. 0000a880 ed 41 00 00 00 04 00 00 69 1d 07 63 69 1d 07 63 |.A......i..ci..c|
    108. 0000a890 69 1d 07 63 00 00 00 00 00 00 03 00 02 00 00 00 |i..c............|
    109. 0000a8a0 00 00 08 00 00 00 00 00 0a f3 01 00 04 00 00 00 |................|
    110. 0000a8b0 00 00 00 00 00 00 00 00 01 00 00 00 0b 00 00 00 |................|
    111. 0000a8c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    112. *
    113. 0000a8f0 00 00 00 00 00 00 00 00 00 00 00 00 26 f3 00 00 |............&...|
    114. 0000a900 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    115. *
    116. 0000a970 00 00 00 00 00 00 00 00 00 00 00 00 3c 74 00 00 |............<t..|
    117. 0000a980 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    118. *
    119. 0000a9f0 00 00 00 00 00 00 00 00 00 00 00 00 9e 68 00 00 |.............h..|
    120. 0000aa00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    121. *
    122. 0000aa70 00 00 00 00 00 00 00 00 00 00 00 00 5e 95 00 00 |............^...|
    123. 0000aa80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    124. *
    125. 0000aaf0 00 00 00 00 00 00 00 00 00 00 00 00 ef e5 00 00 |................|
    126. 0000ab00 80 81 00 00 00 30 04 04 69 1d 07 63 69 1d 07 63 |.....0..i..ci..c|
    127. 0000ab10 69 1d 07 63 00 00 00 00 00 00 01 00 10 00 00 00 |i..c............|
    128. 0000ab20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    129. *
    130. 0000ab50 00 00 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 |................|
    131. 0000ab60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    132. 0000ab70 00 00 00 00 00 00 00 00 00 00 00 00 18 3e 00 00 |.............>..|
    133. 0000ab80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    134. *
    135. 0000abf0 00 00 00 00 00 00 00 00 00 00 00 00 ab dc 00 00 |................|
    136. 0000ac00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    137. *
    138. 0000ac70 00 00 00 00 00 00 00 00 00 00 00 00 6b 21 00 00 |............k!..|
    139. 0000ac80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    140. *
    141. 0000acf0 00 00 00 00 00 00 00 00 00 00 00 00 da 51 00 00 |.............Q..|
    142. 0000ad00 c0 41 00 00 00 30 00 00 69 1d 07 63 69 1d 07 63 |.A...0..i..ci..c|
    143. 0000ad10 69 1d 07 63 00 00 00 00 00 00 02 00 18 00 00 00 |i..c............|
    144. 0000ad20 00 00 08 00 00 00 00 00 0a f3 01 00 04 00 00 00 |................|
    145. 0000ad30 00 00 00 00 00 00 00 00 0c 00 00 00 0c 00 00 00 |................|
    146. 0000ad40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    147. *
    148. 0000ad70 00 00 00 00 00 00 00 00 00 00 00 00 90 ce 00 00 |................|
    149. 0000ad80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    150. *
    151. 00100200
    152. [root@OIL ~]#

    1.4、交叉编译dumpe2fs工具,查看文件系统信息

            更便捷的获取磁盘信息的内容,交叉编译dumpe2fs,该工具解析磁盘分区中的内容,直接展现出来,便于我们回过头去分析磁盘信息。

    • 块大小:1024B
    • 块数量:1024(正好1M)
    • inode size:128B
    • inode已使用11个,剩余117个,一共12个
    • inode从第42块开始存放
    • superblock在第1个块

            根据下面内容,可以得到上面的一些重要信息:

    1. [root@OIL ~]# dumpe2fs /dev/mmcblk0p1
    2. dumpe2fs 1.42.5 (29-Jul-2012)
    3. Filesystem volume name: <none>
    4. Last mounted on: <not available>
    5. Filesystem UUID: fc5d80f1-b146-4410-a40e-beecc10117c4
    6. Filesystem magic number: 0xEF53
    7. Filesystem revision #: 1 (dynamic)
    8. Filesystem features: ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
    9. Filesystem flags: signed_directory_hash
    10. Default mount options: user_xattr acl
    11. Filesystem state: not clean
    12. Errors behavior: Continue
    13. Filesystem OS type: Linux
    14. Inode count: 128
    15. Block count: 1024
    16. Reserved block count: 51
    17. Free blocks: 982
    18. Free inodes: 117
    19. First block: 1
    20. Block size: 1024
    21. Fragment size: 1024
    22. Reserved GDT blocks: 7
    23. Blocks per group: 8192
    24. Fragments per group: 8192
    25. Inodes per group: 128
    26. Inode blocks per group: 16
    27. Flex block group size: 16
    28. Filesystem created: Thu Aug 25 14:57:45 2022
    29. Last mount time: Thu Jan 1 08:11:00 1970
    30. Last write time: Thu Jan 1 08:11:00 1970
    31. Mount count: 1
    32. Maximum mount count: -1
    33. Last checked: Thu Aug 25 14:57:45 2022
    34. Check interval: 0 (<none>)
    35. Lifetime writes: 90 kB
    36. Reserved blocks uid: 0 (user root)
    37. Reserved blocks gid: 0 (group root)
    38. First inode: 11
    39. Inode size: 128
    40. Default directory hash: half_md4
    41. Directory Hash Seed: 6bacd731-f472-4afb-9ada-db5eff31e579
    42. Checksum: 0xcfc94b0f
    43. Group 0: (Blocks 1-1023)
    44. Primary superblock at 1, Group descriptors at 2-2
    45. Reserved GDT blocks at 3-9
    46. Block bitmap at 10 (+9), Inode bitmap at 26 (+25)
    47. Inode table at 42-57 (+41)
    48. 982 free blocks, 117 free inodes, 2 directories, 117 unused inodes
    49. Free blocks: 24-25, 28-41, 58-1023
    50. Free inodes: 12-128
    51. [root@OIL ~]#

    1.5 导出inode table信息

            根据前面查到信息,从磁盘0xa800开始的之后16个块是inode table。我们将所有inode导出到bin文件中,便于后期查看。

    1. [root@OIL ~]# dd if=/dev/mmcblk0p1 of=/inode_table.bin skip=42 count=16 bs=1024
    2. 16+0 records in
    3. 16+0 records out
    4. 16384 bytes (16.0KB) copied, 0.002334 seconds, 6.7MB/s
    5. [root@OIL ~]#
    6. [root@OIL ~]# hexdump -C inode_table.bin
    7. 00000000 00 00 00 00 00 00 00 00 69 1d 07 63 69 1d 07 63 |........i..ci..c|
    8. 00000010 69 1d 07 63 00 00 00 00 00 00 00 00 00 00 00 00 |i..c............|
    9. 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    10. *
    11. 00000070 00 00 00 00 00 00 00 00 00 00 00 00 ca aa 00 00 |................|
    12. 00000080 ed 41 00 00 00 04 00 00 69 1d 07 63 69 1d 07 63 |.A......i..ci..c|
    13. 00000090 69 1d 07 63 00 00 00 00 00 00 03 00 02 00 00 00 |i..c............|
    14. 000000a0 00 00 08 00 00 00 00 00 0a f3 01 00 04 00 00 00 |................|
    15. 000000b0 00 00 00 00 00 00 00 00 01 00 00 00 0b 00 00 00 |................|
    16. 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    17. *
    18. 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 26 f3 00 00 |............&...|
    19. 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    20. *
    21. 00000170 00 00 00 00 00 00 00 00 00 00 00 00 3c 74 00 00 |............<t..|
    22. 00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    23. *
    24. 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 9e 68 00 00 |.............h..|
    25. 00000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    26. *
    27. 00000270 00 00 00 00 00 00 00 00 00 00 00 00 5e 95 00 00 |............^...|
    28. 00000280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    29. *
    30. 000002f0 00 00 00 00 00 00 00 00 00 00 00 00 ef e5 00 00 |................|
    31. 00000300 80 81 00 00 00 30 04 04 69 1d 07 63 69 1d 07 63 |.....0..i..ci..c|
    32. 00000310 69 1d 07 63 00 00 00 00 00 00 01 00 10 00 00 00 |i..c............|
    33. 00000320 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    34. *
    35. 00000350 00 00 00 00 00 00 00 00 00 00 00 00 1b 00 00 00 |................|
    36. 00000360 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    37. 00000370 00 00 00 00 00 00 00 00 00 00 00 00 18 3e 00 00 |.............>..|
    38. 00000380 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    39. *
    40. 000003f0 00 00 00 00 00 00 00 00 00 00 00 00 ab dc 00 00 |................|
    41. 00000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    42. *
    43. 00000470 00 00 00 00 00 00 00 00 00 00 00 00 6b 21 00 00 |............k!..|
    44. 00000480 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    45. *
    46. 000004f0 00 00 00 00 00 00 00 00 00 00 00 00 da 51 00 00 |.............Q..|
    47. 00000500 c0 41 00 00 00 30 00 00 69 1d 07 63 69 1d 07 63 |.A...0..i..ci..c|
    48. 00000510 69 1d 07 63 00 00 00 00 00 00 02 00 18 00 00 00 |i..c............|
    49. 00000520 00 00 08 00 00 00 00 00 0a f3 01 00 04 00 00 00 |................|
    50. 00000530 00 00 00 00 00 00 00 00 0c 00 00 00 0c 00 00 00 |................|
    51. 00000540 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    52. *
    53. 00000570 00 00 00 00 00 00 00 00 00 00 00 00 90 ce 00 00 |................|
    54. 00000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    55. *
    56. 00004000
    57. [root@OIL ~]#

    1.6 分析目录inode信息

            格式化ext4,挂载后,默认创建了lost+found,如下

    1. [root@OIL sd]# ls
    2. lost+found/
    3. [root@OIL sd]#

            查看这个目录对应的inode信息为第11个inode

    1. [root@OIL sd]# stat lost\+found/
    2. File: lost+found/
    3. Size: 12288 Blocks: 24 IO Block: 1024 directory
    4. Device: b301h/45825d Inode: 11 Links: 2
    5. Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root)
    6. Access: 1970-01-01 08:24:40.000000000
    7. Modify: 2022-08-25 14:57:45.000000000
    8. Change: 2022-08-25 14:57:45.000000000
    9. [root@OIL sd]#

    根据inode table,和inode号,得出该inode的信息为:

    1. [root@OIL sd]# dd if=/inode_table.bin of=inode11.bin skip=10 count=1 bs=128
    2. 1+0 records in
    3. 1+0 records out
    4. 128 bytes (128B) copied, 0.000835 seconds, 149.7KB/s
    5. [root@OIL sd]# hexdump -C inode11.bin
    6. 00000000 c0 41 00 00 00 30 00 00 69 1d 07 63 69 1d 07 63 |.A...0..i..ci..c|
    7. 00000010 69 1d 07 63 00 00 00 00 00 00 02 00 18 00 00 00 |i..c............|
    8. 00000020 00 00 08 00 00 00 00 00 0a f3 01 00 04 00 00 00 |................|
    9. 00000030 00 00 00 00 00 00 00 00 0c 00 00 00 0c 00 00 00 |................|
    10. 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
    11. *
    12. 00000070 00 00 00 00 00 00 00 00 00 00 00 00 90 ce 00 00 |................|
    13. 00000080
    14. [root@OIL sd]#

    显然,找到inode结构体的定义来和上面的信息一一对应起来。ext4 inode结构体定义:

    1. struct ext4_inode {
    2. __le16 i_mode; /* File mode */
    3. __le16 i_uid; /* Low 16 bits of Owner Uid */
    4. __le32 i_size_lo; /* Size in bytes */
    5. __le32 i_atime; /* Access time */
    6. __le32 i_ctime; /* Inode Change time */
    7. __le32 i_mtime; /* Modification time */
    8. __le32 i_dtime; /* Deletion Time */
    9. __le16 i_gid; /* Low 16 bits of Group Id */
    10. __le16 i_links_count; /* Links count */
    11. __le32 i_blocks_lo; /* Blocks count */
    12. __le32 i_flags; /* File flags */
    13. union {
    14. struct {
    15. __le32 l_i_version;
    16. } linux1;
    17. struct {
    18. __u32 h_i_translator;
    19. } hurd1;
    20. struct {
    21. __u32 m_i_reserved1;
    22. } masix1;
    23. } osd1; /* OS dependent 1 */
    24. __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
    25. __le32 i_generation; /* File version (for NFS) */
    26. __le32 i_file_acl_lo; /* File ACL */
    27. __le32 i_size_high;
    28. __le32 i_obso_faddr; /* Obsoleted fragment address */
    29. union {
    30. struct {
    31. __le16 l_i_blocks_high; /* were l_i_reserved1 */
    32. __le16 l_i_file_acl_high;
    33. __le16 l_i_uid_high; /* these 2 fields */
    34. __le16 l_i_gid_high; /* were reserved2[0] */
    35. __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
    36. __le16 l_i_reserved;
    37. } linux2;
    38. struct {
    39. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
    40. __u16 h_i_mode_high;
    41. __u16 h_i_uid_high;
    42. __u16 h_i_gid_high;
    43. __u32 h_i_author;
    44. } hurd2;
    45. struct {
    46. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
    47. __le16 m_i_file_acl_high;
    48. __u32 m_i_reserved2[2];
    49. } masix2;
    50. } osd2; /* OS dependent 2 */
    51. __le16 i_extra_isize;
    52. __le16 i_checksum_hi; /* crc32c(uuid+inum+inode) BE */
    53. __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
    54. __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
    55. __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
    56. __le32 i_crtime; /* File Creation time */
    57. __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
    58. __le32 i_version_hi; /* high 32 bits for 64-bit version */
    59. };

    文件大小12288:

    access时间:

     

    1.7 查看新文件信息

    创建一个新文件

    0x18*1024 =0x6000

    总结

            通过上面的简单分析,我们可以看到磁盘中不仅存储数据信息,还要存储与该数据相关的很多信息,如大小,时间,位置等等(是一句废话,怎么可能只存储数据)。

            inode分为磁盘inode和vfs看到的内存中的inode,这俩不完全一样。磁盘inode安装文件系统来定义,vfs的inode要比磁盘inode信息要多一些。

            通过文件名确定inode编号,通过inode编号找到文件的inode信息,根据inode信息找到文件的存储位置,大小等信息。那么文件名和inode直接的关系是哪里建立的,保存在哪里?后面再分析。

  • 相关阅读:
    初识Load Runner
    c++多线程(一)线程管理
    Spring AOP以及统一处理
    MATLAB嵌套if语句
    tail -f 与 tailf 的区别
    在量化投资股票中如何正确使用MACD建立自己的交易策略?
    这一篇让你掌握 vue3.2 setup 语法糖
    【问题处理】WPS提示不能启动此对象的源应用程序如何处理?
    java计算机毕业设计汽车美容管理源码+mysql数据库+系统+lw文档+部署
    java中BigDecimal除法运算指定小数点保留位数和取舍规则
  • 原文地址:https://blog.csdn.net/fengyuwuzu0519/article/details/126525268