diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-20 20:29:48 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-01-20 22:32:00 -0500 |
commit | 5e224596cfdf9ad9413536482224e2fe79b9e387 (patch) | |
tree | d2a2b3f4066cf8e656f4fc56890b07de97829721 /bch_bindgen/src | |
parent | b5fd066153c40a70a29caa1ea7987723ab687763 (diff) |
Remove gag usage
Possibly-fixes: https://github.com/koverstreet/bcachefs-tools/issues/217
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'bch_bindgen/src')
-rw-r--r-- | bch_bindgen/src/lib.rs | 2 | ||||
-rw-r--r-- | bch_bindgen/src/sb_io.rs (renamed from bch_bindgen/src/rs.rs) | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/bch_bindgen/src/lib.rs b/bch_bindgen/src/lib.rs index 4c549442..deb69a51 100644 --- a/bch_bindgen/src/lib.rs +++ b/bch_bindgen/src/lib.rs @@ -3,7 +3,7 @@ pub mod btree; pub mod bkey; pub mod errcode; pub mod keyutils; -pub mod rs; +pub mod sb_io; pub mod fs; pub mod opts; pub use paste::paste; diff --git a/bch_bindgen/src/rs.rs b/bch_bindgen/src/sb_io.rs index 24594ae1..172584d7 100644 --- a/bch_bindgen/src/rs.rs +++ b/bch_bindgen/src/sb_io.rs @@ -27,3 +27,23 @@ pub fn read_super(path: &std::path::Path) -> anyhow::Result<bch_sb_handle> { let opts = bcachefs::bch_opts::default(); read_super_opts(path, opts) } + +pub fn read_super_silent( + path: &std::path::Path, + mut opts: bch_opts, +) -> anyhow::Result<bch_sb_handle> { + use std::os::unix::ffi::OsStrExt; + let path = std::ffi::CString::new(path.as_os_str().as_bytes()).unwrap(); + + let mut sb = std::mem::MaybeUninit::zeroed(); + + let ret = + unsafe { crate::bcachefs::bch2_read_super_silent(path.as_ptr(), &mut opts, sb.as_mut_ptr()) }; + + if ret != 0 { + let err: bch_errcode = unsafe { ::std::mem::transmute(ret) }; + Err(anyhow!(err)) + } else { + Ok(unsafe { sb.assume_init() }) + } +} |