use std::path::PathBuf;
use serde::Deserialize;
use serde::Serialize;
pub(crate) mod sys;
pub mod commands;
pub mod constants;
mod device;
pub use device::Controller;
pub use device::DiskConfig;
fn scsi_option_lock_default() -> bool {
true
}
fn scsi_option_block_size_default() -> u32 {
512
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, serde_keyvalue::FromKeyValues)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct ScsiOption {
pub path: PathBuf,
#[serde(default, rename = "ro")]
pub read_only: bool,
#[serde(default = "scsi_option_lock_default")]
pub lock: bool,
#[serde(default = "scsi_option_block_size_default")]
pub block_size: u32,
#[serde(default)]
pub root: bool,
}
#[cfg(test)]
mod tests {
use std::path::Path;
use serde_keyvalue::from_key_values;
use super::*;
#[test]
fn parse_scsi_options() {
let scsi_option = from_key_values::<ScsiOption>("/path/to/image").unwrap();
assert_eq!(
scsi_option,
ScsiOption {
path: Path::new("/path/to/image").to_path_buf(),
read_only: false,
lock: scsi_option_lock_default(),
block_size: 512,
root: false,
}
);
let scsi_option = from_key_values::<ScsiOption>("/path/to/image,ro").unwrap();
assert_eq!(
scsi_option,
ScsiOption {
path: Path::new("/path/to/image").to_path_buf(),
read_only: true,
lock: scsi_option_lock_default(),
block_size: 512,
root: false,
}
);
let scsi_option = from_key_values::<ScsiOption>("/path/to/image,block-size=1024").unwrap();
assert_eq!(
scsi_option,
ScsiOption {
path: Path::new("/path/to/image").to_path_buf(),
read_only: false,
lock: scsi_option_lock_default(),
block_size: 1024,
root: false,
}
);
let scsi_option =
from_key_values::<ScsiOption>("/path/to/image,block-size=1024,root").unwrap();
assert_eq!(
scsi_option,
ScsiOption {
path: Path::new("/path/to/image").to_path_buf(),
read_only: false,
lock: scsi_option_lock_default(),
block_size: 1024,
root: true,
}
);
}
}