[haiku-development] Re: xfs crc checksums

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 12 Jun 2022 08:40:23 +0000

Here is my work in progress patch https://review.haiku-os.org/c/haiku/+/5350

This is the documentation for metadata checksums for linux
https://github.com/torvalds/linux/blob/master/Documentation/filesystems/xfs-self-describing-metadata.rst

Then we have implementation for checksums function here
https://elixir.bootlin.com/linux/latest/source/fs/xfs/libxfs/xfs_cksum.h

One difference I could find is that crc verification is done through
buffer and not directly through on disk header like I am doing for
superblock, but that should not make any difference as buffer should
give the same data stored in disk, as on disk header.

Still here is how it is getting checked for superblock
https://elixir.bootlin.com/linux/latest/source/fs/xfs/libxfs/xfs_sb.c#L748

Do let me know if all links above are not working fine.

Your patch is computing the CRC of only the used data in the superblock 
(sizeof(XfsSuperBlock)), while the Linux code computes the CRC of the whole 
superblock. It's not immediately clear to me if they use 512 bytes, or a block 
defined by the superblock sb_blocksize. But you can try both and see if one of 
the two matches with what Linux does. They do it this way because if in a later 
version they add more fields to the superblock, these will already be taken 
into account by the CRC computation.

If they use only 512 bytes, the code is very easy to adjust:
- In Volume::Indentify: hqve q 512 byte buffer allocated on the stack
- Read 512 bytes of data from there
- Do the validation on this buffer
- Then copy this data (only the first sizeof(XfsSuperBlock) bytes) into the 
XfsSuperBlock structure passed as a parameter

If they use a value depending on the block size, it's a bit more complicated:
- Read just the block size from disk,
- Allocate a buffer corresponding to that block size
- Read the complete superblock block to that buffer
- Check the CRC of the buffer
- Finally copy the data to the XfsSuperBlock passed as parameter to Identify

-- 
Adrien.

Other related posts: