rename ImageIndex to FixedIndex

also changed the file extension fron .iidx to .fidx
This commit is contained in:
Dietmar Maurer 2019-02-12 11:50:45 +01:00
parent 82bc0ad40c
commit 91a905b6dd
5 changed files with 27 additions and 26 deletions

View File

@ -2,6 +2,6 @@
pub mod chunker;
pub mod chunk_store;
pub mod image_index;
pub mod fixed_index;
pub mod archive_index;
pub mod datastore;

View File

@ -13,6 +13,7 @@ use uuid::Uuid;
//use chrono::{Local, TimeZone};
#[repr(C)]
//pub struct DynamicIndexHeader {
pub struct ArchiveIndexHeader {
pub magic: [u8; 12],
pub version: u32,

View File

@ -10,7 +10,7 @@ use std::sync::{Mutex, Arc};
use crate::tools;
use crate::config::datastore;
use super::chunk_store::*;
use super::image_index::*;
use super::fixed_index::*;
use super::archive_index::*;
use chrono::{Utc, TimeZone};
@ -75,16 +75,16 @@ impl DataStore {
})
}
pub fn create_image_writer<P: AsRef<Path>>(&self, filename: P, size: usize, chunk_size: usize) -> Result<ImageIndexWriter, Error> {
pub fn create_fixed_writer<P: AsRef<Path>>(&self, filename: P, size: usize, chunk_size: usize) -> Result<FixedIndexWriter, Error> {
let index = ImageIndexWriter::create(self.chunk_store.clone(), filename.as_ref(), size, chunk_size)?;
let index = FixedIndexWriter::create(self.chunk_store.clone(), filename.as_ref(), size, chunk_size)?;
Ok(index)
}
pub fn open_image_reader<P: AsRef<Path>>(&self, filename: P) -> Result<ImageIndexReader, Error> {
pub fn open_fixed_reader<P: AsRef<Path>>(&self, filename: P) -> Result<FixedIndexReader, Error> {
let index = ImageIndexReader::open(self.chunk_store.clone(), filename.as_ref())?;
let index = FixedIndexReader::open(self.chunk_store.clone(), filename.as_ref())?;
Ok(index)
}
@ -214,7 +214,7 @@ impl DataStore {
for entry in walker.filter_entry(|e| !is_hidden(e)) {
let path = entry?.into_path();
if let Some(ext) = path.extension() {
if ext == "iidx" {
if ext == "fidx" {
list.push(path);
} else if ext == "aidx" {
list.push(path);
@ -231,8 +231,8 @@ impl DataStore {
for path in image_list {
if let Some(ext) = path.extension() {
if ext == "iidx" {
let index = self.open_image_reader(&path)?;
if ext == "fidx" {
let index = self.open_fixed_reader(&path)?;
index.mark_used_chunks(status)?;
} else if ext == "aidx" {
let index = self.open_archive_reader(&path)?;

View File

@ -11,7 +11,7 @@ use uuid::Uuid;
use chrono::{Local, TimeZone};
#[repr(C)]
pub struct ImageIndexHeader {
pub struct FixedIndexHeader {
pub magic: [u8; 12],
pub version: u32,
pub uuid: [u8; 16],
@ -23,7 +23,7 @@ pub struct ImageIndexHeader {
// split image into fixed size chunks
pub struct ImageIndexReader {
pub struct FixedIndexReader {
store: Arc<ChunkStore>,
filename: PathBuf,
chunk_size: usize,
@ -33,7 +33,7 @@ pub struct ImageIndexReader {
pub ctime: u64,
}
impl Drop for ImageIndexReader {
impl Drop for FixedIndexReader {
fn drop(&mut self) {
if let Err(err) = self.unmap() {
@ -42,7 +42,7 @@ impl Drop for ImageIndexReader {
}
}
impl ImageIndexReader {
impl FixedIndexReader {
pub fn open(store: Arc<ChunkStore>, path: &Path) -> Result<Self, Error> {
@ -50,7 +50,7 @@ impl ImageIndexReader {
let mut file = std::fs::File::open(&full_path)?;
let header_size = std::mem::size_of::<ImageIndexHeader>();
let header_size = std::mem::size_of::<FixedIndexHeader>();
// todo: use static assertion when available in rust
if header_size != 4096 { bail!("got unexpected header size for {:?}", path); }
@ -58,9 +58,9 @@ impl ImageIndexReader {
let mut buffer = vec![0u8; header_size];
file.read_exact(&mut buffer)?;
let header = unsafe { &mut * (buffer.as_ptr() as *mut ImageIndexHeader) };
let header = unsafe { &mut * (buffer.as_ptr() as *mut FixedIndexHeader) };
if header.magic != *b"PROXMOX-IIDX" {
if header.magic != *b"PROXMOX-FIDX" {
bail!("got unknown magic number for {:?}", path);
}
@ -152,7 +152,7 @@ impl ImageIndexReader {
}
}
pub struct ImageIndexWriter {
pub struct FixedIndexWriter {
store: Arc<ChunkStore>,
filename: PathBuf,
tmp_filename: PathBuf,
@ -164,7 +164,7 @@ pub struct ImageIndexWriter {
pub ctime: u64,
}
impl Drop for ImageIndexWriter {
impl Drop for FixedIndexWriter {
fn drop(&mut self) {
let _ = std::fs::remove_file(&self.tmp_filename); // ignore errors
@ -174,13 +174,13 @@ impl Drop for ImageIndexWriter {
}
}
impl ImageIndexWriter {
impl FixedIndexWriter {
pub fn create(store: Arc<ChunkStore>, path: &Path, size: usize, chunk_size: usize) -> Result<Self, Error> {
let full_path = store.relative_path(path);
let mut tmp_path = full_path.clone();
tmp_path.set_extension("tmp_iidx");
tmp_path.set_extension("tmp_fidx");
let mut file = std::fs::OpenOptions::new()
.create(true).truncate(true)
@ -188,7 +188,7 @@ impl ImageIndexWriter {
.write(true)
.open(&tmp_path)?;
let header_size = std::mem::size_of::<ImageIndexHeader>();
let header_size = std::mem::size_of::<FixedIndexHeader>();
// todo: use static assertion when available in rust
if header_size != 4096 { panic!("got unexpected header size"); }
@ -199,9 +199,9 @@ impl ImageIndexWriter {
let uuid = Uuid::new_v4();
let buffer = vec![0u8; header_size];
let header = unsafe { &mut * (buffer.as_ptr() as *mut ImageIndexHeader) };
let header = unsafe { &mut * (buffer.as_ptr() as *mut FixedIndexHeader) };
header.magic = *b"PROXMOX-IIDX";
header.magic = *b"PROXMOX-FIDX";
header.version = u32::to_le(1);
header.ctime = u64::to_le(ctime);
header.size = u64::to_le(size as u64);

View File

@ -45,11 +45,11 @@ fn backup_image(datastore: &DataStore, file: &std::fs::File, size: usize, target
let mut target = PathBuf::from(target);
if let Some(ext) = target.extension() {
if ext != "iidx" {
bail!("got wrong file extension - expected '.iidx'");
if ext != "fidx" {
bail!("got wrong file extension - expected '.fidx'");
}
} else {
target.set_extension("iidx");
target.set_extension("fidx");
}
let mut index = datastore.create_image_writer(&target, size, chunk_size)?;