8 message: std::borrow::Cow<'static, String>
11 pub type GResult<T, E, OE> =::core::result::Result< ::core::result::Result<T, E>, OE>;
12 pub type Result<T, E> = GResult<T, E, GError>;
19 std::ffi::CStr::from_ptr(concat!($lit, "\0").as_ptr() as *const std::os::raw::c_char)
21 .as_ptr() as *const std::os::raw::c_char
27 struct ErrnoError(errno::Errno);
28 impl std::fmt::Display for ErrnoError {
29 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
33 impl std::error::Error for ErrnoError {}
35 #[derive(Clone, Debug)]
36 pub enum KeyLocation {
42 #[derive(Clone, Debug)]
43 pub struct KeyLoc(pub Option<KeyLocation>);
44 impl std::ops::Deref for KeyLoc {
45 type Target = Option<KeyLocation>;
46 fn deref(&self) -> &Self::Target {
50 impl std::str::FromStr for KeyLoc {
51 type Err = anyhow::Error;
52 fn from_str(s: &str) -> anyhow::Result<Self> {
53 // use anyhow::anyhow;
55 "" => Ok(KeyLoc(None)),
56 "fail" => Ok(KeyLoc(Some(KeyLocation::Fail))),
57 "wait" => Ok(KeyLoc(Some(KeyLocation::Wait))),
58 "ask" => Ok(KeyLoc(Some(KeyLocation::Ask))),
59 _ => Err(anyhow!("invalid password option")),
64 fn parse_fstab_uuid(uuid_raw: &str) -> Result<Uuid, uuid::Error> {
65 let mut uuid = String::from(uuid_raw);
66 if uuid.starts_with("UUID=") {
67 uuid = uuid.replacen("UUID=", "", 1);
69 return Uuid::parse_str(&uuid);
72 /// Mount a bcachefs filesystem by its UUID.
73 #[derive(Parser, Debug)]
74 #[command(author, version, about, long_about = None)]
76 /// Where the password would be loaded from.
78 /// Possible values are:
79 /// "fail" - don't ask for password, fail if filesystem is encrypted;
80 /// "wait" - wait for password to become available before mounting;
81 /// "ask" - prompt the user for password;
82 #[arg(short, long, default_value = "", verbatim_doc_comment)]
83 pub key_location: KeyLoc,
85 /// External UUID of the bcachefs filesystem
87 /// Accepts the UUID as is or as fstab style UUID=<UUID>
88 #[arg(value_parser=parse_fstab_uuid)]
91 /// Where the filesystem should be mounted. If not set, then the filesystem
92 /// won't actually be mounted. But all steps preceeding mounting the
93 /// filesystem (e.g. asking for passphrase) will still be performed.
94 pub mountpoint: Option<std::path::PathBuf>,
97 #[arg(short, default_value = "")]
104 // pub fn mnt_in_use()
108 use clap::CommandFactory;
109 Cli::command().debug_assert()