backup/dynamic_index: use static assertion, fix size

The type was sized properly but the number was still wrong,
fixed this.
TODO! Once unions with non-Copy values are stable make this
a `union { full: [u8; 4096], data: TheActualHeader }`;

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-08-23 11:38:16 +02:00
parent bcb664cb69
commit 990b930f22
1 changed files with 7 additions and 5 deletions

View File

@ -27,9 +27,14 @@ pub struct DynamicIndexHeader {
pub ctime: u64,
/// Sha256 over the index ``SHA256(offset1||digest1||offset2||digest2||...)``
pub index_csum: [u8; 32],
reserved: [u8; 4030], // overall size is one page (4096 bytes)
reserved: [u8; 4032], // overall size is one page (4096 bytes)
}
proxmox::tools::static_assert_size!(DynamicIndexHeader, 4096);
// TODO: Once non-Copy unions are stabilized, use:
// union DynamicIndexHeader {
// reserved: [u8; 4096],
// pub data: DynamicIndexHeaderData,
// }
pub struct DynamicIndexReader {
_file: File,
@ -74,9 +79,6 @@ impl DynamicIndexReader {
let header_size = std::mem::size_of::<DynamicIndexHeader>();
// todo: use static assertion when available in rust
if header_size != 4096 { bail!("got unexpected header size"); }
let buffer = file.read_exact_allocated(header_size)?;
let header = unsafe { &* (buffer.as_ptr() as *const DynamicIndexHeader) };