From 40f4e198a8f7bfa61f3af3b8b98716a9df0f2ec0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 21 May 2019 09:52:19 +0200 Subject: [PATCH] src/backup/dynamic_index.rs: add chunk_info method --- src/backup/dynamic_index.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index 7bd26f9f..2b5468ea 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -130,6 +130,23 @@ impl DynamicIndexReader { Ok(()) } + pub fn chunk_info(&self, pos: usize) -> Result<(u64, u64, [u8; 32]), Error> { + if pos >= self.index_entries { + bail!("chunk index out of range"); + } + let start = if pos == 0 { + 0 + } else { + unsafe { *(self.index.add((pos-1)*40) as *const u64) } + }; + + let end = unsafe { *(self.index.add(pos*40) as *const u64) }; + let mut digest: [u8; 32] = unsafe { std::mem::uninitialized() }; + unsafe { std::ptr::copy_nonoverlapping(self.index.add(pos*40+8), digest.as_mut_ptr(), 32); } + + Ok((start, end, digest)) + } + #[inline] fn chunk_end(&self, pos: usize) -> u64 { if pos >= self.index_entries {