btrfs ioctl:从用户空间获取文件校验和

时间:2015-09-24 12:26:41

标签: linux btrfs

我想获取与特定文件相关的BTRFS校验和,但遗憾的是我没有找到合适的ioctl来执行此操作。有可能吗?如果是这样,怎么办?我需要存储的校验和,以尝试在类似于rsync行为的情况下减少CPU负载。

1 个答案:

答案 0 :(得分:1)

刚才把这个凌乱的代码推到了我的github repo中。 https://github.com/Lakshmipathi/btrfs-progs/tree/dump_csum 它不是官方代码。我测试了100K到50GB之间的文件。他们似乎匹配。

用法:

./btrfs-debug-tree -f /path/to/file /btrfs/partition

将在目的地创建 csumdump 文件。

示例:

sudo ./btrfs-debug-tree -f /btrfs/50gbfile1 /dev/sda4

将创建一个名为' /btrfs/50gbfile1.csumdump '的输出文件。用csum的文件块。

注意:我出于教育/学习的目的尝试这一点,因此它附带所有通常的免责声明。计划在本周的某个时候清理这段代码。

如果您打算使用,我建议您测试以下情况:

1) Create 20GB (or any file with size > 1KB) on /tmp/ 
2) mount your btrfs partition on /btrfs and copy file /tmp/file /btrfs/f1
3) Now dump the csum it will produce /btrfs/f1.csumdump
4) cp /tmp/file /btrfs/f2 and dump f2's csum.
5) Now compare f1.csumdump with f2.csumdump If they match, it seems to be 
working. If they didn't match something went wrong.