2 use std::os::unix::ffi::OsStrExt;
3 use std::path::PathBuf;
5 use crate::errcode::{bch_errcode, errptr_to_result};
8 pub raw: *mut c::bch_fs,
12 pub fn open(devices: &Vec<PathBuf>, opts: c::bch_opts) -> Result<Fs, bch_errcode> {
13 let devices: Vec<_> = devices.iter()
14 .map(|i| CString::new(i.as_os_str().as_bytes()).unwrap()).collect();
15 let dev_c_strs: Vec<_> = devices.iter()
16 .map(|i| { let p: *const i8 = i.as_ptr(); p })
18 let dev_c_strarray: *const *mut i8 = dev_c_strs[..].as_ptr() as *const *mut i8;
20 let ret = unsafe { c::bch2_fs_open(dev_c_strarray, dev_c_strs.len() as u32, opts) };
22 errptr_to_result(ret).map(|fs| Fs { raw: fs})
28 unsafe { c::bch2_fs_stop(self.raw) }