]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/bch_bindgen/src/fs.rs
remove library from bcachefs-tools Rust package
[bcachefs-tools-debian] / rust-src / bch_bindgen / src / fs.rs
1 use std::ffi::CString;
2 use std::os::unix::ffi::OsStrExt;
3 use std::path::PathBuf;
4 use crate::c;
5 use crate::errcode::{bch_errcode, errptr_to_result};
6
7 pub struct Fs {
8     pub raw: *mut c::bch_fs,
9 }
10
11 impl Fs {
12     pub fn open(devs: &Vec<PathBuf>, opts: c::bch_opts) -> Result<Fs, bch_errcode> {
13         let devs: Vec<_> = devs.iter()
14             .map(|i| CString::new(i.as_os_str().as_bytes()).unwrap().into_raw())
15             .collect();
16
17         let ret = unsafe { c::bch2_fs_open(devs[..].as_ptr(), devs.len() as u32, opts) };
18
19         errptr_to_result(ret).map(|fs| Fs { raw: fs})
20     }
21 }
22
23 impl Drop for Fs {
24     fn drop(&mut self) {
25         unsafe { c::bch2_fs_stop(self.raw) }
26     }             
27 }