[ Content contribution] 【交流分享】xfs和zfs文件系统查看文件结构 Resolved
Tofloor
poster avatar
核桃
deepin
2024-01-23 10:59
Author

文件系统中如何查看文件结构是一个比较有趣的小技巧, 对于想深入理解文件系统的朋友很有帮助,方便大家知道一些文件结构字段信息。

首先需要知道文件结构是树形的,通常是b+ tree, 叶子节点是数据。如下所示

zfs file (1).png

接着下面来看看xfs和zfs中如何查看文件结构。第一步是构建环境

# dd if=/dev/zero  of=xfs_1g bs=1M count=1024
# mkfs.xfs /root/xfs_1g
# mkdir /mnt/xfs_test
# mount /root/xfs_1g  /mnt/xfs_test

xfs的环境搞好了,下面就是创建文件使用xdb进行查看

#cd /mnt/xfs_test
# fallocate -l 100M xfs_100m
# ls -i xfs_100m 
131 xfs_100m

记住这里的inode id是131,xdb中有用

# umount /mnt/xfs_test
# xfs_db -c "inode 131" -c "p" /root/xfs_1g 
core.magic = 0x494e
core.mode = 0100644
core.version = 3
core.format = 2 (extents)
core.nlinkv2 = 1
...
u3.bmx[0] = [startoff,startblock,blockcount,extentflag] 
0:[0,24,25600,1]

这里的字段非常多,含义可以看文档 XFS的on-disk组织结构(7)

下面来看zfs的操作,也是类似的

# dd if=/dev/zero of=zfs_1g bs=1M count=1024
# zpool create zp_1g /root/zfs_1g
# zfs create  zp_1g/ds_1g
# zfs list 
NAME          USED  AVAIL     REFER  MOUNTPOINT
zp_1g         136K   832M       24K  /zp_1g
zp_1g/ds_1g    24K   832M       24K  /zp_1g/ds_1g

zfs创建了dataset之后默认是会有挂载的,如果没有使用zfs set mountpoint就可以了。

# date >> /zp_1g/ds_1g/1.txt
# ls -i /zp_1g/ds_1g/1.txt
2 /zp_1g/ds_1g/1.txt

# zdb -ddddd zp_1g/ds_1g 2
Object  lvl   iblk   dblk  dsize  dnsize  lsize   %full  type
         2    1   128K    512    512     512    512  100.00  ZFS plain file
                                               176   bonus  System attributes
...
Indirect blocks:
               0 L0 0:8008e00:200 200L/200P F=1 B=16/16 cksum=14de747df:a30fa9979f:2824e119f8be:6a484b0b4cf9b

                segment [0000000000000000, 0000000000000200) size   512

解释一下Indirect blocks的内容,L0表示是数据块,也就是叶子节点。还可以使用命令输出文件数据,但是通常不需要。

Reply Favorite View the author
All Replies
阿尼樱奈奈
Moderator
2024-01-23 12:32
#1

like

Reply View the author
出售星辰之书的书商
Moderator
2024-01-23 15:27
#2
like
Reply View the author
库罗靡靡
deepin
2024-01-25 10:57
#3

nice 。很赞

Reply View the author