summaryrefslogtreecommitdiff
path: root/rust-src/mount/src
diff options
context:
space:
mode:
authorAlexander Fougner <fougner89@gmail.com>2023-01-12 20:35:23 +0100
committerAlexander Fougner <fougner89@gmail.com>2023-01-15 22:20:13 +0100
commit87243efa5c792f72be0bcea2fdf0c4335d59c2ec (patch)
treeb646133f468fef83ed4ec5520eeb9dd5ac96eb04 /rust-src/mount/src
parentccaca683b22170b633e3840fcc913c8a9ce30d51 (diff)
rust: support fstab style mount
- add support for fstab format, UUID=<uuid> - structopt is no longer actively maintained, replace with clap v4 which support everything structopt can and more. - update dependencies Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Diffstat (limited to 'rust-src/mount/src')
-rw-r--r--rust-src/mount/src/lib.rs33
-rw-r--r--rust-src/mount/src/main.rs11
2 files changed, 32 insertions, 12 deletions
diff --git a/rust-src/mount/src/lib.rs b/rust-src/mount/src/lib.rs
index 4e918e13..554ed798 100644
--- a/rust-src/mount/src/lib.rs
+++ b/rust-src/mount/src/lib.rs
@@ -1,5 +1,6 @@
use anyhow::anyhow;
-use structopt::StructOpt;
+use clap::Parser;
+use uuid::Uuid;
pub mod err {
pub enum GError {
@@ -31,14 +32,14 @@ impl std::fmt::Display for ErrnoError {
}
impl std::error::Error for ErrnoError {}
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub enum KeyLocation {
Fail,
Wait,
Ask,
}
-#[derive(Debug)]
+#[derive(Clone, Debug)]
pub struct KeyLoc(pub Option<KeyLocation>);
impl std::ops::Deref for KeyLoc {
type Target = Option<KeyLocation>;
@@ -60,19 +61,31 @@ impl std::str::FromStr for KeyLoc {
}
}
-#[derive(StructOpt, Debug)]
+fn parse_fstab_uuid(uuid_raw: &str) -> Result<Uuid, uuid::Error> {
+ let mut uuid = String::from(uuid_raw);
+ if uuid.starts_with("UUID=") {
+ uuid = uuid.replacen("UUID=", "", 1);
+ }
+ return Uuid::parse_str(&uuid);
+}
+
/// Mount a bcachefs filesystem by its UUID.
-pub struct Options {
+#[derive(Parser, Debug)]
+#[command(author, version, about, long_about = None)]
+pub struct Cli {
/// Where the password would be loaded from.
///
/// Possible values are:
/// "fail" - don't ask for password, fail if filesystem is encrypted;
/// "wait" - wait for password to become available before mounting;
/// "ask" - prompt the user for password;
- #[structopt(short, long, default_value = "")]
+ #[arg(short, long, default_value = "", verbatim_doc_comment)]
pub key_location: KeyLoc,
/// External UUID of the bcachefs filesystem
+ ///
+ /// Accepts the UUID as is or as fstab style UUID=<UUID>
+ #[arg(value_parser=parse_fstab_uuid)]
pub uuid: uuid::Uuid,
/// Where the filesystem should be mounted. If not set, then the filesystem
@@ -81,7 +94,7 @@ pub struct Options {
pub mountpoint: Option<std::path::PathBuf>,
/// Mount options
- #[structopt(short, default_value = "")]
+ #[arg(short, default_value = "")]
pub options: String,
}
@@ -89,3 +102,9 @@ pub mod filesystem;
pub mod key;
// pub fn mnt_in_use()
+
+#[test]
+fn verify_cli() {
+ use clap::CommandFactory;
+ Cli::command().debug_assert()
+}
diff --git a/rust-src/mount/src/main.rs b/rust-src/mount/src/main.rs
index 92b69170..66a60d9a 100644
--- a/rust-src/mount/src/main.rs
+++ b/rust-src/mount/src/main.rs
@@ -1,3 +1,6 @@
+
+use clap::Parser;
+
fn main() {
// convert existing log statements to tracing events
// tracing_log::LogTracer::init().expect("logtracer init failed!");
@@ -10,11 +13,9 @@ fn main() {
}
-
#[tracing_attributes::instrument("main")]
pub fn main_inner() -> anyhow::Result<()> {
- use structopt::StructOpt;
- use bcachefs_mount::{Options, filesystem, key};
+ use bcachefs_mount::{Cli, filesystem, key};
unsafe {
libc::setvbuf(
filesystem::stdout,
@@ -24,9 +25,9 @@ pub fn main_inner() -> anyhow::Result<()> {
);
// libc::fflush(filesystem::stdout);
}
- let opt = Options::from_args();
-
+ let opt = Cli::parse();
+
tracing::trace!(?opt);
let fss = filesystem::probe_filesystems()?;