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 <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
brjhaiku
2019-10-24 19:28:03 +00:00
committed by Adrien Destugues
parent 175e599a66
commit caf05af5dd
2 changed files with 4 additions and 2 deletions
@@ -66,7 +66,7 @@ static uint32 kCrcTable[256] = {
\param data Pointer to the byte stream. \param data Pointer to the byte stream.
\param length Length of the byte stream in bytes. \param length Length of the byte stream in bytes.
\return The crc checksum, or 0 if an error occurred. \return The crc checksum.
*/ */
uint32 uint32
calculate_crc(uint32 crc, uint8* data, uint16 length) calculate_crc(uint32 crc, uint8* data, uint16 length)
@@ -656,7 +656,9 @@ Volume::FindBlock(off_t logical, off_t& physical)
status_t status_t
Volume::WriteSuperBlock() 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, if (write_pos(fDevice, BTRFS_SUPER_BLOCK_OFFSET, &fSuperBlock,
sizeof(btrfs_super_block)) sizeof(btrfs_super_block))