MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / build_serial

Function build_serial

block/src/lib.rs:124–139  ·  view source on GitHub ↗
(disk_path: &Path)

Source from the content-addressed store, hash-verified

122}
123
124pub 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)]
142pub enum ExecuteError {

Callers 2

newMethod · 0.85
newMethod · 0.85

Calls 3

build_device_idFunction · 0.85
as_bytesMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected