]> git.sesse.net Git - bcachefs-tools-debian/blob - bch_bindgen/src/sb_io.rs
Remove gag usage
[bcachefs-tools-debian] / bch_bindgen / src / sb_io.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 }
30
31 pub fn read_super_silent(
32     path: &std::path::Path,
33     mut opts: bch_opts,
34 ) -> anyhow::Result<bch_sb_handle> {
35     use std::os::unix::ffi::OsStrExt;
36     let path = std::ffi::CString::new(path.as_os_str().as_bytes()).unwrap();
37
38     let mut sb = std::mem::MaybeUninit::zeroed();
39
40     let ret =
41         unsafe { crate::bcachefs::bch2_read_super_silent(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
42
43     if ret != 0 {
44         let err: bch_errcode = unsafe { ::std::mem::transmute(ret) };
45         Err(anyhow!(err))
46     } else {
47         Ok(unsafe { sb.assume_init() })
48     }
49 }