I would like to obtain the BTRFS checksums related to the specific file, but unfortunately I have not found appropriate ioctl to perform this action. Is it possible to do? If so, how to do that? I need stored checksums to try to reduce CPU load in cases similar to rsync behaviour.
Asked
Active
Viewed 1,253 times
10
-
3BTW, btrfs generates checksums for *blocks*, not for *files* (AFAIK). – gavv Sep 24 '15 at 14:48
-
2That is exactly what I want: a list of checksums for blocks of the given file. – 0x2207 Sep 24 '15 at 17:31
-
1I've been skimming through the source code and I don't see any interface to get the checksum values. – rodrigo Sep 24 '15 at 17:47
-
1Maybe this helps: search for `BTRFS_CSUM_TREE_OBJECTID` in `btrfs-debug-tree` sources: https://github.com/linsomniac/btrfs-progs/blob/17459dcc8cc9d54963cbfd844006340315b73e86/debug-tree.c I have no btrfs support on my kernel, so I can't check what it actually prints. – gavv Sep 24 '15 at 17:53
1 Answers
4
Just now pushed this messy code into my github repo. https://github.com/Lakshmipathi/btrfs-progs/tree/dump_csum Its not official code. I tested for files between size 100K to 50GB. They seem to match.
Usage:
./btrfs-debug-tree -f /path/to/file /btrfs/partition
will create csumdump file at destination.
Example:
sudo ./btrfs-debug-tree -f /btrfs/50gbfile1 /dev/sda4
will create an output file-named '/btrfs/50gbfile1.csumdump' with csum of file blocks.
Note: I was trying this out for educational/learning purpose,so it comes with all usual disclaimers. Planning to cleanup this code sometime this week.
If you plan to use, I would recommend you to test with following cases:
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.
Update after almost 5 years!
New location: https://github.com/Lakshmipathi/dduper

webminal.org
- 44,948
- 37
- 94
- 125