use std::cmp::min;
use std::path::Path;
use std::sync::Arc;
use serde::Deserialize;
use serde_aco::Help;
use crate::fuse::passthrough::Passthrough;
use crate::virtio::Result;
use crate::virtio::dev::DevParam;
use crate::virtio::dev::fs::{Fs, FsConfig};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Help)]
pub struct SharedDirParam {
pub tag: String,
pub path: Box<Path>,
#[serde(default)]
pub dax_window: usize,
}
impl DevParam for SharedDirParam {
type Device = Fs<Passthrough>;
fn build(self, name: impl Into<Arc<str>>) -> Result<Fs<Passthrough>> {
let passthrough = Passthrough::new(self.path)?;
let mut config = FsConfig {
tag: [0; 36],
num_request_queues: 1,
notify_buf_size: 0,
};
let tag_size = min(config.tag.len(), self.tag.len());
config.tag[0..tag_size].copy_from_slice(&self.tag.as_bytes()[0..tag_size]);
Fs::new(name, passthrough, config, self.dax_window)
}
}