mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
rust: use rustfmt defaults
follow the kernel style guide, i.e idiomatic rust style. Signed-off-by: Alexander Fougner <fougner89@gmail.com>
This commit is contained in:
parent
bdc290eee0
commit
20aecb42d8
@ -1,12 +1,14 @@
|
||||
fn main() {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let out_dir: PathBuf = std::env::var_os("OUT_DIR").expect("ENV Var 'OUT_DIR' Expected").into();
|
||||
let out_dir: PathBuf = std::env::var_os("OUT_DIR")
|
||||
.expect("ENV Var 'OUT_DIR' Expected")
|
||||
.into();
|
||||
let top_dir: PathBuf = std::env::var_os("CARGO_MANIFEST_DIR")
|
||||
.expect("ENV Var 'CARGO_MANIFEST_DIR' Expected")
|
||||
.into();
|
||||
let libbcachefs_inc_dir =
|
||||
std::env::var("LIBBCACHEFS_INCLUDE").unwrap_or_else(|_| top_dir.join("libbcachefs").display().to_string());
|
||||
let libbcachefs_inc_dir = std::env::var("LIBBCACHEFS_INCLUDE")
|
||||
.unwrap_or_else(|_| top_dir.join("libbcachefs").display().to_string());
|
||||
let libbcachefs_inc_dir = std::path::Path::new(&libbcachefs_inc_dir);
|
||||
println!("{}", libbcachefs_inc_dir.display());
|
||||
|
||||
@ -15,8 +17,17 @@ fn main() {
|
||||
|
||||
let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs");
|
||||
let bindings = bindgen::builder()
|
||||
.header(top_dir.join("src").join("libbcachefs_wrapper.h").display().to_string())
|
||||
.clang_arg(format!("-I{}", libbcachefs_inc_dir.join("include").display()))
|
||||
.header(
|
||||
top_dir
|
||||
.join("src")
|
||||
.join("libbcachefs_wrapper.h")
|
||||
.display()
|
||||
.to_string(),
|
||||
)
|
||||
.clang_arg(format!(
|
||||
"-I{}",
|
||||
libbcachefs_inc_dir.join("include").display()
|
||||
))
|
||||
.clang_arg(format!("-I{}", libbcachefs_inc_dir.display()))
|
||||
.clang_arg("-DZSTD_STATIC_LINKING_ONLY")
|
||||
.clang_arg("-DNO_BCACHEFS_FS")
|
||||
@ -25,7 +36,9 @@ fn main() {
|
||||
.derive_default(true)
|
||||
.derive_eq(true)
|
||||
.layout_tests(true)
|
||||
.default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true })
|
||||
.default_enum_style(bindgen::EnumVariation::Rust {
|
||||
non_exhaustive: true,
|
||||
})
|
||||
.allowlist_function(".*bch2_.*")
|
||||
.allowlist_function("bio_.*")
|
||||
.allowlist_function("bch2_super_write_fd")
|
||||
@ -57,8 +70,19 @@ fn main() {
|
||||
|
||||
let keyutils = pkg_config::probe_library("libkeyutils").expect("Failed to find keyutils lib");
|
||||
let bindings = bindgen::builder()
|
||||
.header(top_dir.join("src").join("keyutils_wrapper.h").display().to_string())
|
||||
.clang_args(keyutils.include_paths.iter().map(|p| format!("-I{}", p.display())))
|
||||
.header(
|
||||
top_dir
|
||||
.join("src")
|
||||
.join("keyutils_wrapper.h")
|
||||
.display()
|
||||
.to_string(),
|
||||
)
|
||||
.clang_args(
|
||||
keyutils
|
||||
.include_paths
|
||||
.iter()
|
||||
.map(|p| format!("-I{}", p.display())),
|
||||
)
|
||||
.generate()
|
||||
.expect("BindGen Generation Failiure: [Keyutils]");
|
||||
bindings
|
||||
|
@ -1,2 +1,3 @@
|
||||
max_width=120
|
||||
hard_tabs = true
|
||||
# Default settings, i.e. idiomatic rust
|
||||
edition = "2021"
|
||||
newline_style = "Unix"
|
@ -43,7 +43,10 @@ impl PartialEq for bch_sb {
|
||||
impl bch_sb {
|
||||
pub fn crypt(&self) -> Option<&bch_sb_field_crypt> {
|
||||
unsafe {
|
||||
let ptr = bch2_sb_field_get(self as *const _ as *mut _, bch_sb_field_type::BCH_SB_FIELD_crypt) as *const u8;
|
||||
let ptr = bch2_sb_field_get(
|
||||
self as *const _ as *mut _,
|
||||
bch_sb_field_type::BCH_SB_FIELD_crypt,
|
||||
) as *const u8;
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::bcachefs;
|
||||
|
||||
pub const SUPERBLOCK_MAGIC: uuid::Uuid = uuid::Uuid::from_u128(
|
||||
0x_c68573f6_4e1a_45ca_8265_f57f48ba6d81
|
||||
);
|
||||
pub const SUPERBLOCK_MAGIC: uuid::Uuid =
|
||||
uuid::Uuid::from_u128(0x_c68573f6_4e1a_45ca_8265_f57f48ba6d81);
|
||||
|
||||
extern "C" {
|
||||
pub static stdout: *mut libc::FILE;
|
||||
@ -15,7 +14,10 @@ pub enum ReadSuperErr {
|
||||
type RResult<T> = std::io::Result<std::io::Result<T>>;
|
||||
|
||||
#[tracing_attributes::instrument(skip(opts))]
|
||||
pub fn read_super_opts(path: &std::path::Path, mut opts: bcachefs::bch_opts) -> RResult<bcachefs::bch_sb_handle> {
|
||||
pub fn read_super_opts(
|
||||
path: &std::path::Path,
|
||||
mut opts: bcachefs::bch_opts,
|
||||
) -> RResult<bcachefs::bch_sb_handle> {
|
||||
// let devp = camino::Utf8Path::from_path(devp).unwrap();
|
||||
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
@ -28,7 +30,8 @@ pub fn read_super_opts(path: &std::path::Path, mut opts: bcachefs::bch_opts) ->
|
||||
// let gag = BufferRedirect::stderr().unwrap();
|
||||
// tracing::trace!("entering libbcachefs");
|
||||
|
||||
let ret = unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
|
||||
let ret =
|
||||
unsafe { crate::bcachefs::bch2_read_super(path.as_ptr(), &mut opts, sb.as_mut_ptr()) };
|
||||
tracing::trace!(%ret);
|
||||
|
||||
match -ret {
|
||||
|
@ -1,2 +1,3 @@
|
||||
max_width=120
|
||||
hard_tabs = true
|
||||
# Default settings, i.e. idiomatic rust
|
||||
edition = "2021"
|
||||
newline_style = "Unix"
|
@ -99,7 +99,8 @@ fn mount_inner(
|
||||
});
|
||||
let fstype = fstype.as_c_str().to_bytes_with_nul().as_ptr() as *const c_char;
|
||||
|
||||
let ret = {let _entered = tracing::info_span!("libc::mount").entered();
|
||||
let ret = {
|
||||
let _entered = tracing::info_span!("libc::mount").entered();
|
||||
tracing::info!("mounting filesystem");
|
||||
// REQUIRES: CAP_SYS_ADMIN
|
||||
unsafe { libc::mount(src, target, fstype, mountflags, data) }
|
||||
@ -167,14 +168,13 @@ pub fn probe_filesystems() -> anyhow::Result<HashMap<Uuid, FileSystem>> {
|
||||
udev.match_subsystem("block")?; // find kernel block devices
|
||||
|
||||
let mut fs_map = HashMap::new();
|
||||
let devresults =
|
||||
udev.scan_devices()?
|
||||
let devresults = udev
|
||||
.scan_devices()?
|
||||
.into_iter()
|
||||
.filter_map(|dev| dev.devnode().map(ToOwned::to_owned));
|
||||
|
||||
for pathbuf in devresults {
|
||||
match get_super_block_uuid(&pathbuf)? {
|
||||
|
||||
Ok((uuid_key, superblock)) => {
|
||||
let fs = fs_map.entry(uuid_key).or_insert_with(|| {
|
||||
tracing::info!(msg="found bcachefs pool", uuid=?uuid_key);
|
||||
@ -182,26 +182,31 @@ pub fn probe_filesystems() -> anyhow::Result<HashMap<Uuid, FileSystem>> {
|
||||
});
|
||||
|
||||
fs.devices.push(pathbuf);
|
||||
},
|
||||
|
||||
Err(e) => { tracing::debug!(inner2_error=?e);}
|
||||
}
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
tracing::debug!(inner2_error=?e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!(msg = "found filesystems", count = fs_map.len());
|
||||
Ok(fs_map)
|
||||
}
|
||||
|
||||
// #[tracing_attributes::instrument(skip(dev, fs_map))]
|
||||
fn get_super_block_uuid(path: &std::path::Path) -> std::io::Result<std::io::Result<(Uuid, bcachefs::bch_sb_handle)>> {
|
||||
use gag::{BufferRedirect};
|
||||
fn get_super_block_uuid(
|
||||
path: &std::path::Path,
|
||||
) -> std::io::Result<std::io::Result<(Uuid, bcachefs::bch_sb_handle)>> {
|
||||
use gag::BufferRedirect;
|
||||
// Stop libbcachefs from spamming the output
|
||||
let gag = BufferRedirect::stdout().unwrap();
|
||||
|
||||
let sb = bch_bindgen::rs::read_super(&path)?;
|
||||
let super_block = match sb {
|
||||
Err(e) => { return Ok(Err(e)); }
|
||||
Err(e) => {
|
||||
return Ok(Err(e));
|
||||
}
|
||||
Ok(sb) => sb,
|
||||
};
|
||||
drop(gag);
|
||||
|
@ -31,8 +31,8 @@ const BCH_KEY_MAGIC: &str = "bch**key";
|
||||
use crate::filesystem::FileSystem;
|
||||
fn ask_for_key(fs: &FileSystem) -> anyhow::Result<()> {
|
||||
use anyhow::anyhow;
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use bch_bindgen::bcachefs::{self, bch2_chacha_encrypt_key, bch_encrypted_key, bch_key};
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use std::os::raw::c_char;
|
||||
|
||||
let key_name = std::ffi::CString::new(format!("bcachefs:{}", fs.uuid())).unwrap();
|
||||
|
@ -5,8 +5,8 @@ use uuid::Uuid;
|
||||
pub mod err {
|
||||
pub enum GError {
|
||||
Unknown {
|
||||
message: std::borrow::Cow<'static, String>
|
||||
}
|
||||
message: std::borrow::Cow<'static, String>,
|
||||
},
|
||||
}
|
||||
pub type GResult<T, E, OE> = ::core::result::Result<::core::result::Result<T, E>, OE>;
|
||||
pub type Result<T, E> = GResult<T, E, GError>;
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
fn main() {
|
||||
@ -12,17 +11,11 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[tracing_attributes::instrument("main")]
|
||||
pub fn main_inner() -> anyhow::Result<()> {
|
||||
use bcachefs_mount::{Cli, filesystem, key};
|
||||
use bcachefs_mount::{filesystem, key, Cli};
|
||||
unsafe {
|
||||
libc::setvbuf(
|
||||
filesystem::stdout,
|
||||
std::ptr::null_mut(),
|
||||
libc::_IONBF,
|
||||
0,
|
||||
);
|
||||
libc::setvbuf(filesystem::stdout, std::ptr::null_mut(), libc::_IONBF, 0);
|
||||
// libc::fflush(filesystem::stdout);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user