diff --git a/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp b/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp index 3b16ecdba3..7c3e42b380 100644 --- a/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/CRCTable.cpp @@ -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) diff --git a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp index 311a001c51..fd180878be 100644 --- a/src/add-ons/kernel/file_systems/btrfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/btrfs/Volume.cpp @@ -15,6 +15,7 @@ #include "BTree.h" #include "CachedBlock.h" #include "Chunk.h" +#include "CRCTable.h" #include "DebugSupport.h" #include "ExtentAllocator.h" #include "Inode.h" @@ -656,7 +657,14 @@ Volume::FindBlock(off_t logical, off_t& physical) status_t Volume::WriteSuperBlock() { - // TODO(lesderid): Calculate checksum + uint32 checksum = calculate_crc((uint32)~1, + (uint8 *)(&fSuperBlock + sizeof(fSuperBlock.checksum)), + sizeof(fSuperBlock) - sizeof(fSuperBlock.checksum)); + + fSuperBlock.checksum[0] = (checksum >> 0) & 0xFF; + fSuperBlock.checksum[1] = (checksum >> 8) & 0xFF; + fSuperBlock.checksum[2] = (checksum >> 16) & 0xFF; + fSuperBlock.checksum[3] = (checksum >> 24) & 0xFF; if (write_pos(fDevice, BTRFS_SUPER_BLOCK_OFFSET, &fSuperBlock, sizeof(btrfs_super_block))