From 511ae9e90815d1f85b82d648ff5e3e26e0fa6b18 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 19 May 2021 17:11:58 +0800 Subject: [PATCH] [checksum] Support cache and era superblock --- src/checksum.rs | 18 +++++++++++++----- src/pack/toplevel.rs | 4 +++- src/thin/superblock.rs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/checksum.rs b/src/checksum.rs index 01d8063..f2aaa72 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -5,8 +5,9 @@ use crc32c::crc32c; use std::io::Cursor; const BLOCK_SIZE: u64 = 4096; -#[allow(dead_code)] -const SUPERBLOCK_CSUM_XOR: u32 = 160774; +const THIN_SUPERBLOCK_CSUM_XOR: u32 = 160774; +const CACHE_SUPERBLOCK_CSUM_XOR: u32 = 9031977; +const ERA_SUPERBLOCK_CSUM_XOR: u32 = 146538381; const BITMAP_CSUM_XOR: u32 = 240779; const INDEX_CSUM_XOR: u32 = 160478; const BTREE_CSUM_XOR: u32 = 121107; @@ -18,8 +19,11 @@ fn checksum(buf: &[u8]) -> u32 { #[derive(Debug, PartialEq)] #[allow(clippy::upper_case_acronyms)] +#[allow(non_camel_case_types)] pub enum BT { - SUPERBLOCK, + THIN_SUPERBLOCK, + CACHE_SUPERBLOCK, + ERA_SUPERBLOCK, NODE, INDEX, BITMAP, @@ -39,7 +43,9 @@ pub fn metadata_block_type(buf: &[u8]) -> BT { let btype = csum ^ sum_on_disk; match btype { - SUPERBLOCK_CSUM_XOR => BT::SUPERBLOCK, + THIN_SUPERBLOCK_CSUM_XOR => BT::THIN_SUPERBLOCK, + CACHE_SUPERBLOCK_CSUM_XOR => BT::CACHE_SUPERBLOCK, + ERA_SUPERBLOCK_CSUM_XOR => BT::ERA_SUPERBLOCK, BTREE_CSUM_XOR => BT::NODE, BITMAP_CSUM_XOR => BT::BITMAP, INDEX_CSUM_XOR => BT::INDEX, @@ -55,7 +61,9 @@ pub fn write_checksum(buf: &mut [u8], kind: BT) -> Result<()> { use BT::*; let salt = match kind { - SUPERBLOCK => SUPERBLOCK_CSUM_XOR, + THIN_SUPERBLOCK => THIN_SUPERBLOCK_CSUM_XOR, + CACHE_SUPERBLOCK => CACHE_SUPERBLOCK_CSUM_XOR, + ERA_SUPERBLOCK => ERA_SUPERBLOCK_CSUM_XOR, NODE => BTREE_CSUM_XOR, BITMAP => BITMAP_CSUM_XOR, INDEX => INDEX_CSUM_XOR, diff --git a/src/pack/toplevel.rs b/src/pack/toplevel.rs index 98b4dcf..d4adf7d 100644 --- a/src/pack/toplevel.rs +++ b/src/pack/toplevel.rs @@ -205,7 +205,9 @@ where fn pack_block(w: &mut W, kind: BT, buf: &[u8]) -> Result<()> { match kind { - BT::SUPERBLOCK => pack_superblock(w, buf).context("unable to pack superblock")?, + BT::THIN_SUPERBLOCK | BT::CACHE_SUPERBLOCK | BT::ERA_SUPERBLOCK => { + pack_superblock(w, buf).context("unable to pack superblock")? + } BT::NODE => pack_btree_node(w, buf).context("unable to pack btree node")?, BT::INDEX => pack_index(w, buf).context("unable to pack space map index")?, BT::BITMAP => pack_bitmap(w, buf).context("unable to pack space map bitmap")?, diff --git a/src/thin/superblock.rs b/src/thin/superblock.rs index f066032..43c2e6f 100644 --- a/src/thin/superblock.rs +++ b/src/thin/superblock.rs @@ -137,7 +137,7 @@ pub fn write_superblock(engine: &dyn IoEngine, _loc: u64, sb: &Superblock) -> Re } // calculate the checksum - write_checksum(b.get_data(), BT::SUPERBLOCK)?; + write_checksum(b.get_data(), BT::THIN_SUPERBLOCK)?; // write engine.write(&b)?;