2023-02-21 23:58:42 +03:00
|
|
|
use anyhow::anyhow;
|
2021-10-18 20:27:51 +03:00
|
|
|
use crate::bcachefs;
|
2023-02-21 23:58:42 +03:00
|
|
|
use crate::bcachefs::*;
|
2023-02-27 05:38:12 +03:00
|
|
|
use crate::errcode::bch_errcode;
|
2021-10-18 20:27:51 +03:00
|
|
|
|
2023-01-16 11:22:49 +03:00
|
|
|
pub fn read_super_opts(
|
|
|
|
path: &std::path::Path,
|
2023-02-21 23:58:42 +03:00
|
|
|
mut opts: bch_opts,
|
|
|
|
) -> anyhow::Result<bch_sb_handle> {
|
2023-01-16 11:22:49 +03:00
|
|
|
use std::os::unix::ffi::OsStrExt;
|
2023-02-21 23:58:42 +03:00
|
|
|
let path = std::ffi::CString::new(path.as_os_str().as_bytes()).unwrap();
|
2023-01-16 11:22:49 +03:00
|
|
|
|
|
|
|
let mut sb = std::mem::MaybeUninit::zeroed();
|
|
|
|
|
|
|
|
let ret =
|
|
|
|
unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
|
|
|
|
|
2023-02-21 23:58:42 +03:00
|
|
|
if ret != 0 {
|
|
|
|
let err: bch_errcode = unsafe { ::std::mem::transmute(ret) };
|
|
|
|
Err(anyhow!(err))
|
|
|
|
} else {
|
|
|
|
Ok(unsafe { sb.assume_init() })
|
2023-01-16 11:22:49 +03:00
|
|
|
}
|
2021-10-18 20:27:51 +03:00
|
|
|
}
|
|
|
|
|
2023-02-21 23:58:42 +03:00
|
|
|
pub fn read_super(path: &std::path::Path) -> anyhow::Result<bch_sb_handle> {
|
|
|
|
let opts = bcachefs::bch_opts::default();
|
2023-01-16 11:22:49 +03:00
|
|
|
read_super_opts(path, opts)
|
2021-10-18 20:27:51 +03:00
|
|
|
}
|