src/backup/*_index.rs: used generated magic numbers
This commit is contained in:
		@ -121,6 +121,12 @@ pub static COMPRESSED_CHUNK_MAGIC_1_0: [u8; 8] = [191, 237, 46, 195, 108, 17, 22
 | 
			
		||||
// openssl::sha::sha256(b"Proxmox Backup zstd compressed encrypted chunk v1.0")[0..8]
 | 
			
		||||
pub static ENCR_COMPR_CHUNK_MAGIC_1_0: [u8; 8] = [9, 40, 53, 200, 37, 150, 90, 196];
 | 
			
		||||
 | 
			
		||||
// openssl::sha::sha256(b"Proxmox Backup fixed sized chunk index v1.0")[0..8]
 | 
			
		||||
pub static FIXED_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [47, 127, 65, 237, 145, 253, 15, 205];
 | 
			
		||||
 | 
			
		||||
// openssl::sha::sha256(b"Proxmox Backup dynamic sized chunk index v1.0")[0..8]
 | 
			
		||||
pub static DYNAMIC_SIZED_CHUNK_INDEX_1_0: [u8; 8] = [28, 145, 78, 165, 25, 186, 179, 205];
 | 
			
		||||
 | 
			
		||||
mod crypt_setup;
 | 
			
		||||
pub use crypt_setup::*;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -24,13 +24,12 @@ use super::{DataChunk, DataChunkBuilder};
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct DynamicIndexHeader {
 | 
			
		||||
    /// The string `PROXMOX-DIDX`
 | 
			
		||||
    pub magic: [u8; 12],
 | 
			
		||||
    pub version: u32,
 | 
			
		||||
    pub magic: [u8; 8],
 | 
			
		||||
    pub uuid: [u8; 16],
 | 
			
		||||
    pub ctime: u64,
 | 
			
		||||
    /// Sha256 over the index ``SHA256(offset1||digest1||offset2||digest2||...)``
 | 
			
		||||
    pub index_csum: [u8; 32],
 | 
			
		||||
    reserved: [u8; 4024], // overall size is one page (4096 bytes)
 | 
			
		||||
    reserved: [u8; 4030], // overall size is one page (4096 bytes)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -80,15 +79,10 @@ impl DynamicIndexReader {
 | 
			
		||||
 | 
			
		||||
        let header = unsafe { &* (buffer.as_ptr() as *const DynamicIndexHeader) };
 | 
			
		||||
 | 
			
		||||
        if header.magic != *b"PROXMOX-DIDX" {
 | 
			
		||||
        if header.magic != super::DYNAMIC_SIZED_CHUNK_INDEX_1_0 {
 | 
			
		||||
            bail!("got unknown magic number for {:?}", path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let version = u32::from_le(header.version);
 | 
			
		||||
        if  version != 1 {
 | 
			
		||||
            bail!("got unsupported version number ({}) for {:?}", version, path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let ctime = u64::from_le(header.ctime);
 | 
			
		||||
 | 
			
		||||
        let rawfd = file.as_raw_fd();
 | 
			
		||||
@ -429,8 +423,7 @@ impl DynamicIndexWriter {
 | 
			
		||||
        let mut buffer = vec::undefined(header_size);
 | 
			
		||||
        let header = crate::tools::map_struct_mut::<DynamicIndexHeader>(&mut buffer)?;
 | 
			
		||||
 | 
			
		||||
        header.magic = *b"PROXMOX-DIDX";
 | 
			
		||||
        header.version = u32::to_le(1);
 | 
			
		||||
        header.magic = super::DYNAMIC_SIZED_CHUNK_INDEX_1_0;
 | 
			
		||||
        header.ctime = u64::to_le(ctime);
 | 
			
		||||
        header.uuid = *uuid.as_bytes();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,16 +17,14 @@ use super::ChunkInfo;
 | 
			
		||||
/// Header format definition for fixed index files (`.fidx`)
 | 
			
		||||
#[repr(C)]
 | 
			
		||||
pub struct FixedIndexHeader {
 | 
			
		||||
    /// The string `PROXMOX-FIDX`
 | 
			
		||||
    pub magic: [u8; 12],
 | 
			
		||||
    pub version: u32,
 | 
			
		||||
    pub magic: [u8; 8],
 | 
			
		||||
    pub uuid: [u8; 16],
 | 
			
		||||
    pub ctime: u64,
 | 
			
		||||
    pub size: u64,
 | 
			
		||||
    pub chunk_size: u64,
 | 
			
		||||
    /// Sha256 over the index ``SHA256(digest1||digest2||...)``
 | 
			
		||||
    pub index_csum: [u8; 32],
 | 
			
		||||
    reserved: [u8; 4008], // overall size is one page (4096 bytes)
 | 
			
		||||
    pub size: u64,
 | 
			
		||||
    pub chunk_size: u64,
 | 
			
		||||
    reserved: [u8; 4016], // overall size is one page (4096 bytes)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// split image into fixed size chunks
 | 
			
		||||
@ -78,15 +76,10 @@ impl FixedIndexReader {
 | 
			
		||||
 | 
			
		||||
        let header = unsafe { &mut * (buffer.as_ptr() as *mut FixedIndexHeader) };
 | 
			
		||||
 | 
			
		||||
        if header.magic != *b"PROXMOX-FIDX" {
 | 
			
		||||
        if header.magic != super::FIXED_SIZED_CHUNK_INDEX_1_0 {
 | 
			
		||||
            bail!("got unknown magic number for {:?}", path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let version = u32::from_le(header.version);
 | 
			
		||||
        if  version != 1 {
 | 
			
		||||
            bail!("got unsupported version number ({})", version);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let size = u64::from_le(header.size) as usize;
 | 
			
		||||
        let ctime = u64::from_le(header.ctime);
 | 
			
		||||
        let chunk_size = u64::from_le(header.chunk_size) as usize;
 | 
			
		||||
@ -244,8 +237,7 @@ impl FixedIndexWriter {
 | 
			
		||||
        let buffer = vec![0u8; header_size];
 | 
			
		||||
        let header = unsafe { &mut * (buffer.as_ptr() as *mut FixedIndexHeader) };
 | 
			
		||||
 | 
			
		||||
        header.magic = *b"PROXMOX-FIDX";
 | 
			
		||||
        header.version = u32::to_le(1);
 | 
			
		||||
        header.magic = super::FIXED_SIZED_CHUNK_INDEX_1_0;
 | 
			
		||||
        header.ctime = u64::to_le(ctime);
 | 
			
		||||
        header.size = u64::to_le(size as u64);
 | 
			
		||||
        header.chunk_size = u64::to_le(chunk_size as u64);
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user