(disk_path: &Path)
| 122 | } |
| 123 | |
| 124 | pub fn build_serial(disk_path: &Path) -> Vec<u8> { |
| 125 | let mut default_serial = vec![0; VIRTIO_BLK_ID_BYTES as usize]; |
| 126 | match build_device_id(disk_path) { |
| 127 | Err(_) => { |
| 128 | warn!("Could not generate device id. We'll use a default."); |
| 129 | } |
| 130 | Ok(m) => { |
| 131 | // The kernel only knows to read a maximum of VIRTIO_BLK_ID_BYTES. |
| 132 | // This will also zero out any leftover bytes. |
| 133 | let disk_id = m.as_bytes(); |
| 134 | let bytes_to_copy = cmp::min(disk_id.len(), VIRTIO_BLK_ID_BYTES as usize); |
| 135 | default_serial[..bytes_to_copy].clone_from_slice(&disk_id[..bytes_to_copy]); |
| 136 | } |
| 137 | } |
| 138 | default_serial |
| 139 | } |
| 140 | |
| 141 | #[derive(Error, Debug)] |
| 142 | pub enum ExecuteError { |
no test coverage detected