[thin_check (rust)] factor out device detail

This commit is contained in:
Joe Thornber 2020-09-25 09:59:16 +01:00
parent 66b6a1ba48
commit a88ae3ca18
4 changed files with 58 additions and 33 deletions

View File

@ -549,6 +549,8 @@ pub trait NodeVisitor<V: Unpack> {
keys: &[u64],
values: &[V],
) -> Result<()>;
fn end_walk(&self) -> Result<()>;
}
#[derive(Clone)]
@ -758,6 +760,7 @@ impl BTreeWalker {
path.push(b.loc);
let r = self.walk_node_(path, visitor, kr, b, is_root);
path.pop();
visitor.end_walk()?;
r
}
@ -843,8 +846,9 @@ where
V: Unpack,
{
path.push(b.loc);
let r = walk_node_threaded_(w, path, pool, visitor, kr, b, is_root);
let r = walk_node_threaded_(w, path, pool, visitor.clone(), kr, b, is_root);
path.pop();
visitor.end_walk()?;
r
}
@ -992,6 +996,10 @@ impl<V: Unpack + Copy> NodeVisitor<V> for ValueCollector<V> {
Ok(())
}
fn end_walk(&self) -> Result<()> {
Ok(())
}
}
pub fn btree_to_map<V: Unpack + Copy>(
@ -1051,6 +1059,10 @@ impl<V: Unpack + Clone> NodeVisitor<V> for ValuePathCollector<V> {
Ok(())
}
fn end_walk(&self) -> Result<()> {
Ok(())
}
}
pub fn btree_to_map_with_path<V: Unpack + Copy>(

View File

@ -1,5 +1,4 @@
use anyhow::{anyhow, Result};
use nom::{number::complete::*, IResult};
use std::collections::BTreeMap;
use std::io::Cursor;
use std::path::Path;
@ -14,6 +13,7 @@ use crate::pdata::space_map::*;
use crate::pdata::unpack::*;
use crate::report::*;
use crate::thin::block_time::*;
use crate::thin::device_detail::*;
use crate::thin::superblock::*;
//------------------------------------------
@ -58,38 +58,9 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
data_sm.inc(start, len).unwrap();
Ok(())
}
}
//------------------------------------------
#[derive(Clone, Copy)]
pub struct DeviceDetail {
pub mapped_blocks: u64,
pub transaction_id: u64,
pub creation_time: u32,
pub snapshotted_time: u32,
}
impl Unpack for DeviceDetail {
fn disk_size() -> u32 {
24
}
fn unpack(i: &[u8]) -> IResult<&[u8], DeviceDetail> {
let (i, mapped_blocks) = le_u64(i)?;
let (i, transaction_id) = le_u64(i)?;
let (i, creation_time) = le_u32(i)?;
let (i, snapshotted_time) = le_u32(i)?;
Ok((
i,
DeviceDetail {
mapped_blocks,
transaction_id,
creation_time,
snapshotted_time,
},
))
fn end_walk(&self) -> btree::Result<()> {
Ok(())
}
}
@ -126,6 +97,10 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
Ok(())
}
fn end_walk(&self) -> btree::Result<()> {
Ok(())
}
}
//------------------------------------------

37
src/thin/device_detail.rs Normal file
View File

@ -0,0 +1,37 @@
use crate::pdata::unpack::*;
use nom::{number::complete::*, IResult};
//------------------------------------------
#[derive(Clone, Copy)]
pub struct DeviceDetail {
pub mapped_blocks: u64,
pub transaction_id: u64,
pub creation_time: u32,
pub snapshotted_time: u32,
}
impl Unpack for DeviceDetail {
fn disk_size() -> u32 {
24
}
fn unpack(i: &[u8]) -> IResult<&[u8], DeviceDetail> {
let (i, mapped_blocks) = le_u64(i)?;
let (i, transaction_id) = le_u64(i)?;
let (i, creation_time) = le_u32(i)?;
let (i, snapshotted_time) = le_u32(i)?;
Ok((
i,
DeviceDetail {
mapped_blocks,
transaction_id,
creation_time,
snapshotted_time,
},
))
}
}
//------------------------------------------

View File

@ -1,4 +1,5 @@
pub mod block_time;
pub mod device_detail;
pub mod superblock;
pub mod check;
pub mod xml;