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

0x2*_*207 7 linux btrfs

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

web*_*org 4

刚刚把这段乱七八糟的代码推到了我的 github 仓库中。https://github.com/Lakshmipathi/btrfs-progs/tree/dump_csum 它不是官方代码。我测试了 100K 到 50GB 之间的文件。他们看起来很匹配。

用法:

./btrfs-debug-tree -f /path/to/file /btrfs/partition
Run Code Online (Sandbox Code Playgroud)

将在目的地创建csumdump文件。

例子:

sudo ./btrfs-debug-tree -f /btrfs/50gbfile1 /dev/sda4
Run Code Online (Sandbox Code Playgroud)

将创建一个名为“ /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. 
Run Code Online (Sandbox Code Playgroud)

时隔近5年更新!

新位置: https: //github.com/Lakshmipathi/dduper