]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/backup/fixed_index.rs: use correct size
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 4 Jul 2019 13:13:22 +0000 (15:13 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 4 Jul 2019 13:13:22 +0000 (15:13 +0200)
We need to consider that the last chunk may have smaller size.

src/api2/backup.rs
src/backup/fixed_index.rs

index 1faca22424f848368d82e1967b89bbd267cdb668..cbed7766ce0a3f0ac306f31047c5b1e0847d7401 100644 (file)
@@ -603,9 +603,14 @@ fn fixed_chunk_index(
     env.log(format!("download last backup index for archive '{}'", archive_name));
 
     let count = index.index_count();
+    let image_size = index.index_bytes();
     for pos in 0..count {
         let digest = index.index_digest(pos).unwrap();
-        let size = index.chunk_size as u32;
+        // Note: last chunk can be smaller
+        let start = (pos*index.chunk_size) as u64;
+        let mut end = start + index.chunk_size as u64;
+        if end > image_size { end = image_size; }
+        let size = (end - start) as u32;
         env.register_chunk(*digest, size)?;
     }
 
index 5d1937f31c6c4cea29c816abb93001ad1c13f940..1b58551a7fe4a716faa57531be42ee28a57edb35 100644 (file)
@@ -32,7 +32,7 @@ pub struct FixedIndexHeader {
 pub struct FixedIndexReader {
     _file: File,
     pub chunk_size: usize,
-    pub size: usize,
+    pub size: u64,
     index_length: usize,
     index: *mut u8,
     pub uuid: [u8; 16],
@@ -82,11 +82,11 @@ impl FixedIndexReader {
             bail!("got unknown magic number");
         }
 
-        let size = u64::from_le(header.size) as usize;
+        let size = u64::from_le(header.size);
         let ctime = u64::from_le(header.ctime);
-        let chunk_size = u64::from_le(header.chunk_size) as usize;
+        let chunk_size = u64::from_le(header.chunk_size);
 
-        let index_length = (size + chunk_size - 1)/chunk_size;
+        let index_length = ((size + chunk_size - 1)/chunk_size) as usize;
         let index_size = index_length*32;
 
         let rawfd = file.as_raw_fd();
@@ -111,7 +111,7 @@ impl FixedIndexReader {
 
         Ok(Self {
             _file: file,
-            chunk_size,
+            chunk_size: chunk_size as usize,
             size,
             index_length,
             index: data,
@@ -158,7 +158,7 @@ impl IndexFile for FixedIndexReader {
     }
 
     fn index_bytes(&self) -> u64 {
-        (self.index_length * self.chunk_size) as u64
+        self.size
     }
 }