首页 > *nix技术, 文件系统 > Xfs文件系统磁盘布局之十三:普通文件数据结构(续)

Xfs文件系统磁盘布局之十三:普通文件数据结构(续)

2012年1月7日 发表评论 阅读评论 4,854 次浏览

仍然按照我的习惯,先弄出一B+tree的“extents”,采用的方法就先把磁盘给填满,然后随机删除一些文件,然后再写一个超大文件,由于前面两步操作使得磁盘上的free block很碎并且不连续,所以这个大文件占用的磁盘空间也都不连续,所以需要更多的“extent”来标记这些block块,上一篇提到当“extent”数目大于9时,Xfs文件系统就只能使用B+tree来对它们进行管理了:

[root@localhost loop]# mount /dev/loop0 inode.256
[root@localhost loop]# cp -fr /usr/src/linux-2.6.36/ inode.256
...
[root@localhost loop]# cd inode.256
[root@localhost inode.256]# find . -name "*a*" | xargs rm
...
[root@localhost inode.256]# find . -name "*c*" | xargs rm
...
[root@localhost inode.256]# find . -name "*e*" | xargs rm
...
[root@localhost inode.256]# dd if=/dev/zero of=bigfile
[root@localhost inode.256]# ls -lai
total 79008
     128 drwxr-xr-x  4 root root       51 Jan  7 05:46 .
32800854 drwxr-xr-x  4 root root     4096 Jan  6 07:11 ..
     137 -rw-r--r--  1 root root 80859136 Jan  7 05:46 bigfile
 1045632 drwxr-xr-x 51 root root    20480 Jan  7 05:46 lib64
     134 drwxr-xr-x  6 root root       81 Jan  7 05:43 linux-2.6.36
[root@localhost inode.256]# cd ..
[root@localhost loop]# umount inode.256
[root@localhost loop]# /home/lenky/xfs/xfsprogs/db/xfs_db /dev/loop0 
xfs_db> inode 137
xfs_db> p
core.magic = 0x494e
core.mode = 0100644
core.version = 1
core.format = 3 (btree)
...
core.size = 80859136
core.nblocks = 19742
core.extsize = 0
core.nextents = 63
core.naextents = 0
...
core.gen = 4
next_unlinked = null
u.bmbt.level = 1
u.bmbt.numrecs = 1
u.bmbt.keys[1] = [startoff] 1:[0]
u.bmbt.ptrs[1] = 1:4147
xfs_db> q
[root@localhost loop]# 

core.format = 3 (btree),达到了我们想要的结果。这颗B+tree的根节点存放在data fork内,所以根节点最大只能占有156字节,正因为如此,所以这棵树的节点布局要把根节点单独出来,所以就有三种。
根节点:

xfs_bmdr_block_t的起始位置偏移inode节点的100字节处,xfs_bmbt_key_t紧跟在xfs_bmdr_block_t之后,而xfs_bmbt_ptr_t的起始位置如前面介绍的B+tree类似,并不会紧接在xfs_dfiloff_t br_startoff[n-1]元素之后,而是会预留出足够的空闲空间用以存放xfs_bmbt_key_t元素可能的增长,具体的值当然可以计算出来:(256-100-4)/(8+8)*8+100+4=176=0xB0(注意其中的整型计算),即相对当前inode节点起始地址偏移的176字节处,可以验证(其中的35072是inode 137的起始地址,即是137*256=35072):

[root@localhost loop]# hexdump -C -s 35072 -n 256 /dev/loop0
00008900  49 4e 81 a4 01 03 00 01  00 00 00 00 00 00 00 00  |IN..............|
00008910  00 00 00 01 00 00 00 00  00 00 00 00 00 00 00 0c  |................|
00008920  4f 08 22 8e 25 ca 11 ec  4f 08 22 90 32 6c ee ec  |O.".%...O.".2l..|
00008930  4f 08 22 90 32 6c ee ec  00 00 00 00 04 d1 d0 00  |O.".2l..........|
00008940  00 00 00 00 00 00 4d 1e  00 00 00 00 00 00 00 3f  |......M........?|
00008950  00 00 00 02 00 00 00 00  00 00 00 00 00 00 00 04  |................|
00008960  ff ff ff ff 00 01 00 01  00 00 00 00 00 00 00 00  |................|
00008970  10 00 00 20 00 00 00 00  00 00 00 00 00 00 00 00  |... ............|
00008980  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000089b0  00 00 00 00 00 00 10 33  00 00 00 00 00 00 00 00  |.......3........|
000089c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00008a00
[root@localhost loop]# 

00008960 ff ff ff ff 00 01 00 01 00 00 00 00 00 00 00 00 |…………….|
00008970 10 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 |… …………|
00008980 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
000089b0 00 00 00 00 00 00 10 33 00 00 00 00 00 00 00 00 |…….3……..|
000089c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…………….|
*
00008a00
叶子节点占用一整的block块,其布局图示如下:

实例,具体就不一个个字段对比了,数据如下:

[root@localhost loop]# /home/lenky/xfs/xfsprogs/db/xfs_db /dev/loop0
xfs_db> fsblock 4147
xfs_db> type inobt
xfs_db> p
magic = 0x424d4150
level = 0
numrecs = 63
leftsib = null
rightsib = null
recs[1-63] = [startino,freecount,free] 1:[0,0,0xd66400c00] 2:[0,1572864,0x1abc600a1d] 3:[0,2898432,0x12f3400866] 4:[0,3999232,0x656e00417] 5:[0,4535296,0x179da00313] 6:[0,4938240,0x1195c002f1] 7:[0,5323776,0xa6d6002a0] 8:[0,5667840,0xcd400025a] 9:[0,5976064,0xb1c600259] 10:[0,6283776,0x162e00235] 11:[0,6573056,0x1d1a0001cf] 12:[0,6810112,0x12226001c1] 13:[0,7040000,0x1dcf4001b6] 14:[0,7264256,0x1ec88001ac] 15:[0,7483392,0xf1fa00176] 16:[0,7674880,0x756c00123] 17:[0,7823872,0x1c7960011b] 18:[0,7968768,0x8aa400112] 19:[0,8109056,0x8ee0000dc] 20:[0,8221696,0x94ac000ca] 21:[0,8325120,0xad58000bc] 22:[0,8421376,0xaf54000ba] 23:[0,8516608,0xc14a000a6] 24:[0,8601600,0xa58c000a0] 25:[0,8683520,0xf5660009f] 26:[0,8764928,0x1418a00099] 27:[0,8843264,0x1430200095] 28:[0,8919552,0x18b3c00092] 29:[0,8994304,0xc6fe00073] 30:[0,9053184,0xf09000071] 31:[0,9111040,0x1f63800065] 32:[0,9162752,0x7cda00064] 33:[0,9213952,0x85d000063] 34:[0,9264640,0xb68e00061] 35:[0,9314304,0x1da3c0005d] 36:[0,9361920,0x1447e0005c] 37:[0,9409024,0x1c5c200056] 38:[0,9453056,0xc30e0004e] 39:[0,9492992,0x1e9040004d] 40:[0,9532416,0xa1a200046] 41:[0,9568256,0x1f0a80003c] 42:[0,9598976,0x23140003c] 43:[0,9629696,0x436a0003c] 44:[0,9660416,0xc0bc00039] 45:[0,9689600,0x1f91a00038] 46:[0,9718272,0x886200038] 47:[0,9746944,0x18fc800037] 48:[0,9775104,0x3ea800036] 49:[0,9802752,0xc29a00036] 50:[0,9830400,0xfea400033] 51:[0,9856512,0x1f1f600031] 52:[0,9881600,0xff8a0002f] 53:[0,9905664,0x12a9a0002f] 54:[0,9929728,0x20680002e] 55:[0,9953280,0x3e140002d] 56:[0,9976320,0x114100002d] 57:[0,9999360,0x127fe0002a] 58:[0,10020864,0x1e8840002a] 59:[0,10042368,0x7ec60002a] 60:[0,10063872,0x7fb000004] 61:[0,10065920,0x935a0002a] 62:[0,10087424,0xa07000026] 63:[0,10106880,0xa0f600001]
xfs_db> q
[root@localhost loop]# hexdump -C -s 16986112 -n 4096 /dev/loop0
01033000  42 4d 41 50 00 00 00 3f  ff ff ff ff ff ff ff ff  |BMAP...?........|
01033010  ff ff ff ff ff ff ff ff  00 00 00 00 00 00 00 00  |................|
01033020  00 00 00 0d 66 40 0c 00  00 00 00 00 00 18 00 00  |....f@..........|
01033030  00 00 00 1a bc 60 0a 1d  00 00 00 00 00 2c 3a 00  |.....`.......,:.|
01033040  00 00 00 12 f3 40 08 66  00 00 00 00 00 3d 06 00  |.....@.f.....=..|
01033050  00 00 00 06 56 e0 04 17  00 00 00 00 00 45 34 00  |....V........E4.|
01033060  00 00 00 17 9d a0 03 13  00 00 00 00 00 4b 5a 00  |.............KZ.|
01033070  00 00 00 11 95 c0 02 f1  00 00 00 00 00 51 3c 00  |.............Q<.|
01033080  00 00 00 0a 6d 60 02 a0  00 00 00 00 00 56 7c 00  |....m`.......V|.|
01033090  00 00 00 0c d4 00 02 5a  00 00 00 00 00 5b 30 00  |.......Z.....[0.|
010330a0  00 00 00 0b 1c 60 02 59  00 00 00 00 00 5f e2 00  |.....`.Y....._..|
010330b0  00 00 00 01 62 e0 02 35  00 00 00 00 00 64 4c 00  |....b..5.....dL.|
010330c0  00 00 00 1d 1a 00 01 cf  00 00 00 00 00 67 ea 00  |.............g..|
010330d0  00 00 00 12 22 60 01 c1  00 00 00 00 00 6b 6c 00  |...."`.......kl.|
010330e0  00 00 00 1d cf 40 01 b6  00 00 00 00 00 6e d8 00  |.....@.......n..|
010330f0  00 00 00 1e c8 80 01 ac  00 00 00 00 00 72 30 00  |.............r0.|
01033100  00 00 00 0f 1f a0 01 76  00 00 00 00 00 75 1c 00  |.......v.....u..|
01033110  00 00 00 07 56 c0 01 23  00 00 00 00 00 77 62 00  |....V..#.....wb.|
01033120  00 00 00 1c 79 60 01 1b  00 00 00 00 00 79 98 00  |....y`.......y..|
01033130  00 00 00 08 aa 40 01 12  00 00 00 00 00 7b bc 00  |.....@.......{..|
...

其它中间节点也是占用一整的block块,所以其内部布局虽然和根节点有点类似,但开始的一部分有点不同,得换成xfs_btree_block结构体,另外xfs_bmbt_ptr_t的起始地址当然也不是176了,不过也可以计算出来,这里都不累述。最后,看它的图示如下:

转载请保留地址:http://www.lenky.info/archives/2012/01/834http://lenky.info/?p=834


备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。

法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以Email或书面等方式告知,本站将及时删除相关内容或链接。

  1. 123
    2015年12月22日17:37 | #1

    recs[1-63] = [startino,freecount,free] 1:[0,0,0xd66400c00] 2:[0,1572864,0x1abc600a1d]

    你好 请问上面这个是什么意思 startino为什么是从0开始 然后后面freecount,free具体是什么意思?求详解或者留个联系方式私聊 谢谢

  2. bsmao
    2015年4月11日23:11 | #2

    非常感谢,很好的学习资料!

  1. 本文目前尚无任何 trackbacks 和 pingbacks.