mirror of
https://git.proxmox.com/git/vma-to-pbs
synced 2025-08-05 03:01:55 +00:00
cargo fmt
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
4446414be2
commit
35a9fd8c0c
17
src/main.rs
17
src/main.rs
@ -37,7 +37,10 @@ fn backup_vma_to_pbs(
|
|||||||
println!("compress: {}", compress);
|
println!("compress: {}", compress);
|
||||||
println!("encrypt: {}", encrypt);
|
println!("encrypt: {}", encrypt);
|
||||||
|
|
||||||
let backup_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
|
let backup_time = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs();
|
||||||
println!("backup time: {}", backup_time);
|
println!("backup time: {}", backup_time);
|
||||||
|
|
||||||
let mut pbs_err: *mut c_char = ptr::null_mut();
|
let mut pbs_err: *mut c_char = ptr::null_mut();
|
||||||
@ -51,7 +54,9 @@ fn backup_vma_to_pbs(
|
|||||||
let key_password_cstr = key_password.map(|v| CString::new(v).unwrap());
|
let key_password_cstr = key_password.map(|v| CString::new(v).unwrap());
|
||||||
let key_password_ptr = key_password_cstr.map(|v| v.as_ptr()).unwrap_or(ptr::null());
|
let key_password_ptr = key_password_cstr.map(|v| v.as_ptr()).unwrap_or(ptr::null());
|
||||||
let master_keyfile_cstr = master_keyfile.map(|v| CString::new(v).unwrap());
|
let master_keyfile_cstr = master_keyfile.map(|v| CString::new(v).unwrap());
|
||||||
let master_keyfile_ptr = master_keyfile_cstr.map(|v| v.as_ptr()).unwrap_or(ptr::null());
|
let master_keyfile_ptr = master_keyfile_cstr
|
||||||
|
.map(|v| v.as_ptr())
|
||||||
|
.unwrap_or(ptr::null());
|
||||||
|
|
||||||
let pbs = proxmox_backup_new_ns(
|
let pbs = proxmox_backup_new_ns(
|
||||||
pbs_repository_cstr.as_ptr(),
|
pbs_repository_cstr.as_ptr(),
|
||||||
@ -154,7 +159,8 @@ fn backup_vma_to_pbs(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut image_chunk_buffer = proxmox_io::boxed::zeroed(PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE as usize);
|
let mut image_chunk_buffer =
|
||||||
|
proxmox_io::boxed::zeroed(PROXMOX_BACKUP_DEFAULT_CHUNK_SIZE as usize);
|
||||||
let mut bytes_transferred = 0;
|
let mut bytes_transferred = 0;
|
||||||
|
|
||||||
while bytes_transferred < device_size {
|
while bytes_transferred < device_size {
|
||||||
@ -279,7 +285,10 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let pbs_repository = matches.get_one::<String>("repository").unwrap().to_string();
|
let pbs_repository = matches.get_one::<String>("repository").unwrap().to_string();
|
||||||
let vmid = matches.get_one::<String>("vmid").unwrap().to_string();
|
let vmid = matches.get_one::<String>("vmid").unwrap().to_string();
|
||||||
let fingerprint = matches.get_one::<String>("fingerprint").unwrap().to_string();
|
let fingerprint = matches
|
||||||
|
.get_one::<String>("fingerprint")
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
let keyfile = matches.get_one::<String>("keyfile");
|
let keyfile = matches.get_one::<String>("keyfile");
|
||||||
let master_keyfile = matches.get_one::<String>("master_keyfile");
|
let master_keyfile = matches.get_one::<String>("master_keyfile");
|
||||||
|
27
src/vma.rs
27
src/vma.rs
@ -164,8 +164,10 @@ impl VmaReader {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config_name_file_offset = (vma_header.blob_buffer_offset + config_name_offset) as u64;
|
let config_name_file_offset =
|
||||||
let config_data_file_offset = (vma_header.blob_buffer_offset + config_data_offset) as u64;
|
(vma_header.blob_buffer_offset + config_name_offset) as u64;
|
||||||
|
let config_data_file_offset =
|
||||||
|
(vma_header.blob_buffer_offset + config_data_offset) as u64;
|
||||||
let config_name = Self::read_string_from_file(vma_file, config_name_file_offset)?;
|
let config_name = Self::read_string_from_file(vma_file, config_name_file_offset)?;
|
||||||
let config_data = Self::read_string_from_file(vma_file, config_data_file_offset)?;
|
let config_data = Self::read_string_from_file(vma_file, config_data_file_offset)?;
|
||||||
|
|
||||||
@ -190,8 +192,10 @@ impl VmaReader {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let device_name_file_offset = (self.vma_header.blob_buffer_offset + device_name_offset) as u64;
|
let device_name_file_offset =
|
||||||
let device_name = Self::read_string_from_file(&mut self.vma_file, device_name_file_offset).unwrap();
|
(self.vma_header.blob_buffer_offset + device_name_offset) as u64;
|
||||||
|
let device_name =
|
||||||
|
Self::read_string_from_file(&mut self.vma_file, device_name_file_offset).unwrap();
|
||||||
|
|
||||||
return Some(device_name.to_string());
|
return Some(device_name.to_string());
|
||||||
}
|
}
|
||||||
@ -252,7 +256,8 @@ impl VmaReader {
|
|||||||
mask: 0,
|
mask: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.block_index[device_id].resize(device_cluster_count as usize, block_index_entry_placeholder);
|
self.block_index[device_id]
|
||||||
|
.resize(device_cluster_count as usize, block_index_entry_placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file_offset = self.vma_header.header_size as u64;
|
let mut file_offset = self.vma_header.header_size as u64;
|
||||||
@ -275,7 +280,8 @@ impl VmaReader {
|
|||||||
mask: blockinfo.mask,
|
mask: blockinfo.mask,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.block_index[blockinfo.dev_id as usize][blockinfo.cluster_num as usize] = block_index_entry;
|
self.block_index[blockinfo.dev_id as usize][blockinfo.cluster_num as usize] =
|
||||||
|
block_index_entry;
|
||||||
file_offset += blockinfo.mask.count_ones() as u64 * 4096;
|
file_offset += blockinfo.mask.count_ones() as u64 * 4096;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,8 +319,10 @@ impl VmaReader {
|
|||||||
let mut buffer_is_zero = true;
|
let mut buffer_is_zero = true;
|
||||||
|
|
||||||
while buffer_offset < length {
|
while buffer_offset < length {
|
||||||
let block_index_entry = &this_device_block_index[(offset as usize + buffer_offset) / (4096 * 16)];
|
let block_index_entry =
|
||||||
self.vma_file.seek(SeekFrom::Start(block_index_entry.cluster_file_offset))?;
|
&this_device_block_index[(offset as usize + buffer_offset) / (4096 * 16)];
|
||||||
|
self.vma_file
|
||||||
|
.seek(SeekFrom::Start(block_index_entry.cluster_file_offset))?;
|
||||||
|
|
||||||
for i in 0..16 {
|
for i in 0..16 {
|
||||||
if buffer_offset >= length {
|
if buffer_offset >= length {
|
||||||
@ -325,7 +333,8 @@ impl VmaReader {
|
|||||||
let block_mask = ((block_index_entry.mask >> i) & 1) == 1;
|
let block_mask = ((block_index_entry.mask >> i) & 1) == 1;
|
||||||
|
|
||||||
if block_mask {
|
if block_mask {
|
||||||
self.vma_file.read_exact(&mut buffer[buffer_offset..block_buffer_end])?;
|
self.vma_file
|
||||||
|
.read_exact(&mut buffer[buffer_offset..block_buffer_end])?;
|
||||||
buffer_is_zero = false;
|
buffer_is_zero = false;
|
||||||
} else {
|
} else {
|
||||||
buffer[buffer_offset..block_buffer_end].fill(0);
|
buffer[buffer_offset..block_buffer_end].fill(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user