8

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.

  • 2
    BTW, btrfs generates checksums for blocks, not for files (AFAIK). – gavv Sep 24 '15 at 14:48
  • 2
    That is exactly what I want: a list of checksums for blocks of the given file. – 0x2207 Sep 24 '15 at 17:31
  • 1
    I'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
  • 1
    Maybe this helps: search for BTRFS_CSUM_TREE_OBJECTID in btrfs-debug-tree sources: github.com/linsomniac/btrfs-progs/blob/… 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

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. 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.