diff --git a/src/backup.rs b/src/backup.rs index ab7e400a..28054bc1 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -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; diff --git a/src/backup/archive_index.rs b/src/backup/archive_index.rs index e72580de..c991d1a2 100644 --- a/src/backup/archive_index.rs +++ b/src/backup/archive_index.rs @@ -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, diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index df5686fe..0206b7ec 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -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>(&self, filename: P, size: usize, chunk_size: usize) -> Result { + pub fn create_fixed_writer>(&self, filename: P, size: usize, chunk_size: usize) -> Result { - 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>(&self, filename: P) -> Result { + pub fn open_fixed_reader>(&self, filename: P) -> Result { - 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)?; diff --git a/src/backup/image_index.rs b/src/backup/fixed_index.rs similarity index 93% rename from src/backup/image_index.rs rename to src/backup/fixed_index.rs index d15cb06f..9beefea0 100644 --- a/src/backup/image_index.rs +++ b/src/backup/fixed_index.rs @@ -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, 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, path: &Path) -> Result { @@ -50,7 +50,7 @@ impl ImageIndexReader { let mut file = std::fs::File::open(&full_path)?; - let header_size = std::mem::size_of::(); + let header_size = std::mem::size_of::(); // 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, 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, path: &Path, size: usize, chunk_size: usize) -> Result { 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::(); + let header_size = std::mem::size_of::(); // 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); diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 12e0cdd1..cbd6953f 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -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)?;