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;
|
2024-05-27 03:38:08 +03:00
|
|
|
use crate::path_to_cstr;
|
|
|
|
use anyhow::anyhow;
|
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> {
|
2024-03-03 02:41:55 +03:00
|
|
|
let path = path_to_cstr(path);
|
2023-01-16 11:22:49 +03:00
|
|
|
let mut sb = std::mem::MaybeUninit::zeroed();
|
|
|
|
|
2024-05-27 03:38:08 +03:00
|
|
|
let ret =
|
|
|
|
unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
|
2023-01-16 11:22:49 +03:00
|
|
|
|
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
|
|
|
}
|
2024-01-21 04:29:48 +03:00
|
|
|
|
|
|
|
pub fn read_super_silent(
|
|
|
|
path: &std::path::Path,
|
|
|
|
mut opts: bch_opts,
|
|
|
|
) -> anyhow::Result<bch_sb_handle> {
|
2024-03-03 02:41:55 +03:00
|
|
|
let path = path_to_cstr(path);
|
2024-01-21 04:29:48 +03:00
|
|
|
let mut sb = std::mem::MaybeUninit::zeroed();
|
|
|
|
|
2024-05-27 03:38:08 +03:00
|
|
|
let ret = unsafe {
|
|
|
|
crate::bcachefs::bch2_read_super_silent(path.as_ptr(), &mut opts, sb.as_mut_ptr())
|
|
|
|
};
|
2024-01-21 04:29:48 +03:00
|
|
|
|
|
|
|
if ret != 0 {
|
|
|
|
let err: bch_errcode = unsafe { ::std::mem::transmute(ret) };
|
|
|
|
Err(anyhow!(err))
|
|
|
|
} else {
|
|
|
|
Ok(unsafe { sb.assume_init() })
|
|
|
|
}
|
|
|
|
}
|