1use super::*;
2use std::{ffi::CString, ops::Deref, os::unix::ffi::OsStrExt, path::Path};
3
4#[repr(C)]
5pub struct Iov {
6 iov: hf3fs_iov,
7}
8
9impl Iov {
10 pub fn create(
11 mount_point: &Path,
12 buf_size: usize,
13 block_size: usize,
14 numa: i32,
15 ) -> Result<Self> {
16 let c_str = CString::new(mount_point.as_os_str().as_bytes()).unwrap();
17
18 let mut iov = hf3fs_iov::default();
19 let ret =
20 unsafe { hf3fs_iovcreate(&mut iov, c_str.as_ptr() as _, buf_size, block_size, numa) };
21
22 if ret == 0 {
23 Ok(Self { iov })
24 } else {
25 Err(Error::CretateIovFailed(-ret))
26 }
27 }
28}
29
30impl Drop for Iov {
31 fn drop(&mut self) {
32 unsafe { hf3fs_iovdestroy(&mut self.iov) };
33 }
34}
35
36impl Deref for Iov {
37 type Target = hf3fs_iov;
38
39 fn deref(&self) -> &Self::Target {
40 &self.iov
41 }
42}
43
44unsafe impl Send for Iov {}
45unsafe impl Sync for Iov {}