[thin_check (rust)] auto repair space map leaks
This commit is contained in:
@@ -2,9 +2,10 @@ use anyhow::{anyhow, Result};
|
||||
use fixedbitset::FixedBitSet;
|
||||
use nom::{multi::count, number::complete::*, IResult};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use byteorder::{LittleEndian, WriteBytesExt};
|
||||
|
||||
use crate::io_engine::*;
|
||||
use crate::pdata::unpack::Unpack;
|
||||
use crate::pdata::unpack::{Pack, Unpack};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
@@ -78,7 +79,7 @@ impl Unpack for IndexEntry {
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
const MAX_METADATA_BITMAPS: usize = 255;
|
||||
pub const MAX_METADATA_BITMAPS: usize = 255;
|
||||
|
||||
pub struct MetadataIndex {
|
||||
pub indexes: Vec<IndexEntry>,
|
||||
@@ -129,6 +130,15 @@ impl Unpack for BitmapHeader {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for BitmapHeader {
|
||||
fn pack<W: WriteBytesExt>(&self, out: &mut W) -> Result<()> {
|
||||
out.write_u32::<LittleEndian>(self.csum)?;
|
||||
out.write_u32::<LittleEndian>(self.not_used)?;
|
||||
out.write_u64::<LittleEndian>(self.blocknr)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum BitmapEntry {
|
||||
Small(u8),
|
||||
@@ -175,6 +185,40 @@ impl Unpack for Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for Bitmap {
|
||||
fn pack<W: WriteBytesExt>(&self, out: &mut W) -> Result<()> {
|
||||
use BitmapEntry::*;
|
||||
BitmapHeader::pack(&self.header, out)?;
|
||||
|
||||
for chunk in self.entries.chunks(32) {
|
||||
let mut w = 0u64;
|
||||
for e in chunk {
|
||||
w >>= 2;
|
||||
match e {
|
||||
Small(0) => {
|
||||
},
|
||||
Small(1) => {
|
||||
w |= 0x2 << 62;
|
||||
},
|
||||
Small(2) => {
|
||||
w |= 0x1 << 62;
|
||||
},
|
||||
Small(_) => {
|
||||
return Err(anyhow!("Bad small value in bitmap entry"));
|
||||
},
|
||||
Overflow => {
|
||||
w |= 0x3 << 62;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u64::pack(&w, out)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub trait SpaceMap {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use nom::{number::complete::*, IResult};
|
||||
use byteorder::{LittleEndian, WriteBytesExt};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
@@ -20,6 +21,12 @@ pub fn unpack<U: Unpack>(data: &[u8]) -> Result<U> {
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
pub trait Pack {
|
||||
fn pack<W: WriteBytesExt>(&self, data: &mut W) -> Result<()>;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
impl Unpack for u64 {
|
||||
fn disk_size() -> u32 {
|
||||
8
|
||||
@@ -30,6 +37,13 @@ impl Unpack for u64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for u64 {
|
||||
fn pack<W: WriteBytesExt>(&self, out: &mut W) -> Result<()> {
|
||||
out.write_u64::<LittleEndian>(*self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Unpack for u32 {
|
||||
fn disk_size() -> u32 {
|
||||
4
|
||||
@@ -40,4 +54,11 @@ impl Unpack for u32 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Pack for u32 {
|
||||
fn pack<W: WriteBytesExt>(&self, out: &mut W) -> Result<()> {
|
||||
out.write_u32::<LittleEndian>(*self)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user