btrfs: update superblock checksum on write

Change-Id: I8a2bcf8f462440568d9b3e2d9fbdb7208723bfb9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1596
Reviewed-by: Chế Vũ Gia Hy <ugen@cinnamon.is>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
brjhaiku 2019-07-16 09:45:31 +05:30 committed by Adrien Destugues
parent 175e599a66
commit caf05af5dd
2 changed files with 4 additions and 2 deletions

View File

@ -66,7 +66,7 @@ static uint32 kCrcTable[256] = {
\param data Pointer to the byte stream.
\param length Length of the byte stream in bytes.
\return The crc checksum, or 0 if an error occurred.
\return The crc checksum.
*/
uint32
calculate_crc(uint32 crc, uint8* data, uint16 length)

View File

@ -656,7 +656,9 @@ Volume::FindBlock(off_t logical, off_t& physical)
status_t
Volume::WriteSuperBlock()
{
// TODO(lesderid): Calculate checksum
fSuperBlock.checksum = calculate_crc((uint32)~1,
(uint8 *)(*(&fSuperBlock + sizeof(fSuperBlock.checksum))),
sizeof(fSuperBlock) - sizeof(fSuperBlock.checksum));
if (write_pos(fDevice, BTRFS_SUPER_BLOCK_OFFSET, &fSuperBlock,
sizeof(btrfs_super_block))