]> git.sesse.net Git - bcachefs-tools-debian/blob - bch_bindgen/src/rs.rs
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / bch_bindgen / src / rs.rs
1 use anyhow::anyhow;
2 use crate::bcachefs;
3 use crate::bcachefs::*;
4 use crate::errcode::bch_errcode;
5
6 pub fn read_super_opts(
7     path: &std::path::Path,
8     mut opts: bch_opts,
9 ) -> anyhow::Result<bch_sb_handle> {
10     use std::os::unix::ffi::OsStrExt;
11     let path = std::ffi::CString::new(path.as_os_str().as_bytes()).unwrap();
12
13     let mut sb = std::mem::MaybeUninit::zeroed();
14
15     let ret =
16         unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
17
18     if ret != 0 {
19         let err: bch_errcode = unsafe { ::std::mem::transmute(ret) };
20         Err(anyhow!(err))
21     } else {
22         Ok(unsafe { sb.assume_init() })
23     }
24 }
25
26 pub fn read_super(path: &std::path::Path) -> anyhow::Result<bch_sb_handle> {
27     let opts = bcachefs::bch_opts::default();
28     read_super_opts(path, opts)
29 }