32 bit checksums

This commit is contained in:
Florian Stecker 2024-03-06 22:23:50 -05:00
parent 053a8ff77f
commit e87a7fba2c

View File

@ -1,6 +1,5 @@
use btrfs_parse_derive::AllVariants; use btrfs_parse_derive::AllVariants;
use btrfs_parse_derive::ParseBin; use btrfs_parse_derive::ParseBin;
use std::any::TypeId;
use std::fmt; use std::fmt;
use std::error; use std::error;
use std::ffi::CString; use std::ffi::CString;
@ -97,6 +96,7 @@ pub enum Value {
ExtentData(ExtentDataItem), ExtentData(ExtentDataItem),
Ref(Vec<RefItem>), Ref(Vec<RefItem>),
RootRef(Vec<RootRefItem>), RootRef(Vec<RootRefItem>),
Checksum(Vec<u32>),
Unknown(Vec<u8>), Unknown(Vec<u8>),
} }
@ -482,7 +482,7 @@ impl From<&str> for ParseError {
} }
} }
pub trait ParseBin where Self: Sized { pub trait ParseBin: Sized {
fn parse_len(bytes: &[u8]) -> Result<(Self, usize), ParseError>; fn parse_len(bytes: &[u8]) -> Result<(Self, usize), ParseError>;
fn parse(bytes: &[u8]) -> Result<Self, ParseError> { fn parse(bytes: &[u8]) -> Result<Self, ParseError> {
@ -692,6 +692,13 @@ impl ParseBin for Node {
} }
Value::RootRef(result) Value::RootRef(result)
}, },
ItemType::ExtentCsum => {
let mut checksums: Vec<u32> = Vec::new();
for i in 0..data_slice.len()/4 {
checksums.push(u32::from_le_bytes(data_slice[i*4 .. (i+1)*4].try_into().unwrap()));
}
Value::Checksum(checksums)
},
_ => _ =>
Value::Unknown(Vec::from(data_slice)), Value::Unknown(Vec::from(data_slice)),
}; };