[haiku-development] Re: xfs crc checksums

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 12 Jun 2022 14:36:44 +0200

Also ensure you dont include the CRC bytes themself when calculating the
buffer’s CRC result. They’re typically never used in the checksum loop, or
on the odd occassion where these bytes are needed, they must be zeroed
beforehand. That should be common knowledge, but decades ago when I started
out and was inexperienced I probably made a similar mistake. There are also
different endian issues to consider, different CRC algoritms/factors, so
having a sample dump of a valid buffer’s CRC will help you get it right.

Good luck.



On Sun, 12 Jun 2022 at 1:54 pm, <pulkomandy@xxxxxxxxxxxxx> wrote:

If I understood correctly the procedure is going to be :

Yes, this one looks correct to me.


1. Declare buffer char buf[512] .

2. Read 512 bytes of data to this buffer, something like :
 read_pos(fdevice,0,buf,512) and remove that superblock read_pos we
have as of now.

3. perform checksum verification :
 xfs_verify_cksum(buf,512,offsetof(XfsSuperBlock,sb_crc))

 Is it correct to use offsetof without reading superblock?

Yes, the CRC will be at the same position regardless, so this will still
work.


4. if checksum verification passes copy buffer first
sizeof(XfsSuperBlock) data to superblock structure using memcpy.

--
Adrien.


Other related posts: