[haiku-development] Re: How checksum is calculated on BTRFS ?

  • From: Hy Che <cvghy116@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 20 Jul 2017 21:34:03 +0700

On Thu, Jul 20, 2017 at 8:31 PM, Adrien Destugues
<pulkomandy@xxxxxxxxxxxxx> wrote:

20 juillet 2017 14:01 "Hy Che" <cvghy116@xxxxxxxxx> a écrit:
Hi there,
I want to reproduce checksum number of node header
(https://btrfs.wiki.kernel.org/index.php/On-disk_Format#Header) to
test that I calculate the checksum correctly.
But I don't know what is wrong because the original checksum that is
created from linux doesn't match my calculation (I used the
calculate_crc function in btrfs code base).
I tried two ways to reproduce it:
1. The calculation take a node from disk except the checksum field in header.
2. The calculation take a node from disk but ignore bytes (use 0) that
the node not own (because they are old data) except the checksum field
in header.

A typical algorithm would be:
- Set the checksum area to 0
- Compute the checksum for the whole area, including the checksum
- Overwrite the 0s with the checksum
I don't know if btrfs is using this, only checking the Linux code (or asking 
the Linux btrfs devs) would know for sure.
Hi,
I missed not bitwise operator, so the final hash will be
~calculate_crc(....), the btrfs wiki doesn't say anything about it, or
maybe I missed it somewhere. Thanks anyway.

Hy

Other related posts: