Create a QCOW2 image with `num_clusters` allocated clusters and return the tempfile handle. Each cluster is default QCOW2 cluster size of 64 KiB. The image is created via `QcowFile::new` then populated with writes so that the clusters are actually allocated in the L2 / refcount tables.
(num_clusters: usize)
| 36 | /// created via `QcowFile::new` then populated with writes so that the |
| 37 | /// clusters are actually allocated in the L2 / refcount tables. |
| 38 | fn create_qcow_tempfile(num_clusters: usize) -> TempFile { |
| 39 | let tmp = TempFile::new().expect("failed to create tempfile"); |
| 40 | let virtual_size = QCOW_CLUSTER_SIZE * num_clusters as u64; |
| 41 | let raw = RawFile::new(tmp.as_file().try_clone().unwrap(), false); |
| 42 | let mut qcow = QcowFile::new(raw, 3, virtual_size, true).expect("failed to create QCOW2 file"); |
| 43 | let buf = vec![0xA5u8; QCOW_CLUSTER_SIZE as usize]; |
| 44 | for i in 0..num_clusters { |
| 45 | qcow.seek(SeekFrom::Start(i as u64 * QCOW_CLUSTER_SIZE)) |
| 46 | .expect("seek failed"); |
| 47 | qcow.write_all(&buf).expect("write failed"); |
| 48 | } |
| 49 | qcow.flush().expect("flush failed"); |
| 50 | tmp |
| 51 | } |
| 52 | |
| 53 | /// Create a QCOW2 image with `num_clusters` allocated clusters opened |
| 54 | /// via QcowDisk with synchronous backend. |
no test coverage detected