Process size of disks in bytes instead of megabytes
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		@@ -46,11 +46,11 @@ pub const DISK_NAME_MIN_LEN: usize = 2;
 | 
			
		||||
/// Disk name max length
 | 
			
		||||
pub const DISK_NAME_MAX_LEN: usize = 10;
 | 
			
		||||
 | 
			
		||||
/// Disk size min (MB)
 | 
			
		||||
pub const DISK_SIZE_MIN: usize = 100;
 | 
			
		||||
/// Disk size min (B)
 | 
			
		||||
pub const DISK_SIZE_MIN: usize = 100 * 1000 * 1000;
 | 
			
		||||
 | 
			
		||||
/// Disk size max (MB)
 | 
			
		||||
pub const DISK_SIZE_MAX: usize = 1000 * 1000 * 2;
 | 
			
		||||
/// Disk size max (B)
 | 
			
		||||
pub const DISK_SIZE_MAX: usize = 1000 * 1000 * 1000 * 1000 * 2;
 | 
			
		||||
 | 
			
		||||
/// Net nat entry comment max size
 | 
			
		||||
pub const NET_NAT_COMMENT_MAX_SIZE: usize = 250;
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ pub enum DiskFormat {
 | 
			
		||||
pub struct FileDisk {
 | 
			
		||||
    /// Disk name
 | 
			
		||||
    pub name: String,
 | 
			
		||||
    /// Disk size, in megabytes
 | 
			
		||||
    /// Disk size, in bytes
 | 
			
		||||
    pub size: usize,
 | 
			
		||||
    /// Disk format
 | 
			
		||||
    #[serde(flatten)]
 | 
			
		||||
@@ -141,8 +141,10 @@ impl FileDisk {
 | 
			
		||||
                    .arg("bs=1M");
 | 
			
		||||
 | 
			
		||||
                match alloc_type {
 | 
			
		||||
                    DiskAllocType::Fixed => cmd.arg(format!("count={}", self.size)),
 | 
			
		||||
                    DiskAllocType::Sparse => cmd.arg(format!("seek={}", self.size)).arg("count=0"),
 | 
			
		||||
                    DiskAllocType::Fixed => cmd.arg(format!("count={}", self.size_mb())),
 | 
			
		||||
                    DiskAllocType::Sparse => {
 | 
			
		||||
                        cmd.arg(format!("seek={}", self.size_mb())).arg("count=0")
 | 
			
		||||
                    }
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
                cmd.output()?
 | 
			
		||||
@@ -154,7 +156,7 @@ impl FileDisk {
 | 
			
		||||
                    .arg("-f")
 | 
			
		||||
                    .arg("qcow2")
 | 
			
		||||
                    .arg(file)
 | 
			
		||||
                    .arg(format!("{}M", self.size));
 | 
			
		||||
                    .arg(format!("{}M", self.size_mb()));
 | 
			
		||||
 | 
			
		||||
                cmd.output()?
 | 
			
		||||
            }
 | 
			
		||||
@@ -172,6 +174,11 @@ impl FileDisk {
 | 
			
		||||
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get the size of file disk in megabytes
 | 
			
		||||
    pub fn size_mb(&self) -> usize {
 | 
			
		||||
        self.size / (1000 * 1000)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, serde::Serialize)]
 | 
			
		||||
@@ -211,7 +218,7 @@ impl DiskFileInfo {
 | 
			
		||||
        // Determine file format
 | 
			
		||||
        let format = match ext {
 | 
			
		||||
            "qcow2" => DiskFileFormat::QCow2 {
 | 
			
		||||
                virtual_size: qcow_virt_size(file)? / (1000 * 1000),
 | 
			
		||||
                virtual_size: qcow_virt_size(file)?,
 | 
			
		||||
            },
 | 
			
		||||
            "raw" => DiskFileFormat::Raw {
 | 
			
		||||
                is_sparse: metadata.len() / 512 >= metadata.st_blocks(),
 | 
			
		||||
@@ -226,7 +233,7 @@ impl DiskFileInfo {
 | 
			
		||||
 | 
			
		||||
        Ok(Self {
 | 
			
		||||
            name,
 | 
			
		||||
            file_size: metadata.len() as usize / (1000 * 1000),
 | 
			
		||||
            file_size: metadata.len() as usize,
 | 
			
		||||
            format,
 | 
			
		||||
            file_name: file
 | 
			
		||||
                .file_name()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user