summaryrefslogtreecommitdiff
path: root/rust-src/src/cmd_mount.rs
diff options
context:
space:
mode:
authorThomas Bertschinger <tahbertschinger@gmail.com>2024-01-07 18:36:33 -0700
committerKent Overstreet <kent.overstreet@linux.dev>2024-01-07 21:38:31 -0500
commit9a9af6e9e6560407326b37345ebe434a0839420f (patch)
treee105d7ed49fb20988e9e9c6c1a94fc2d6bb63475 /rust-src/src/cmd_mount.rs
parentb90031efaa4500b8ce5ffc55e9d1ed716196b814 (diff)
create common entry point for Rust commands
The bcachefs sub-commands that are implemented in Rust (completions, list, and mount) had separate entrypoints and thus had some differences in behavior. This introduces a common entry point for the Rust sub-commands. This reduces duplicate boilerplate code like parsing argv and setting up logging, and will facilitate converting more sub-commands to Rust in the future. An immediate benefit is that this fixes an issue with `bcachefs list` not reporting errors: before: $ bcachefs list /dev/typo $ echo $? 0 after: $ bcachefs list /dev/typo ERROR - bcachefs_rust::cmd_list: Fatal error: "No such file or directory" $ echo $? 1 Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'rust-src/src/cmd_mount.rs')
-rw-r--r--rust-src/src/cmd_mount.rs12
1 files changed, 3 insertions, 9 deletions
diff --git a/rust-src/src/cmd_mount.rs b/rust-src/src/cmd_mount.rs
index a75dd21f..3f8253f5 100644
--- a/rust-src/src/cmd_mount.rs
+++ b/rust-src/src/cmd_mount.rs
@@ -4,10 +4,9 @@ use log::{info, debug, error, LevelFilter};
use clap::{Parser};
use uuid::Uuid;
use std::path::PathBuf;
-use crate::{key, transform_c_args};
+use crate::key;
use crate::key::KeyLocation;
-use crate::logger::SimpleLogger;
-use std::ffi::{CString, c_int, c_char, c_void};
+use std::ffi::{CString, c_int, c_char, c_void, OsStr};
use std::os::unix::ffi::OsStrExt;
fn mount_inner(
@@ -222,14 +221,9 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> {
Ok(())
}
-#[no_mangle]
-#[allow(clippy::not_unsafe_ptr_arg_deref)]
-pub extern "C" fn cmd_mount(argc: c_int, argv: *const *const c_char) -> c_int {
- transform_c_args!(argv, argc, argv);
+pub fn cmd_mount(argv: Vec<&OsStr>) -> c_int {
let opt = Cli::parse_from(argv);
- log::set_boxed_logger(Box::new(SimpleLogger)).unwrap();
-
// @TODO : more granular log levels via mount option
log::set_max_level(match opt.verbose {
0 => LevelFilter::Warn,