]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/mount/src/main.rs
rust: use rustfmt defaults
[bcachefs-tools-debian] / rust-src / mount / src / main.rs
1 use clap::Parser;
2
3 fn main() {
4     // convert existing log statements to tracing events
5     // tracing_log::LogTracer::init().expect("logtracer init failed!");
6     // format tracing log data to env_logger like stdout
7     tracing_subscriber::fmt::init();
8
9     if let Err(e) = crate::main_inner() {
10         tracing::error!(fatal_error = ?e);
11     }
12 }
13
14 #[tracing_attributes::instrument("main")]
15 pub fn main_inner() -> anyhow::Result<()> {
16     use bcachefs_mount::{filesystem, key, Cli};
17     unsafe {
18         libc::setvbuf(filesystem::stdout, std::ptr::null_mut(), libc::_IONBF, 0);
19         // libc::fflush(filesystem::stdout);
20     }
21
22     let opt = Cli::parse();
23
24     tracing::trace!(?opt);
25
26     let fss = filesystem::probe_filesystems()?;
27     let fs = fss
28         .get(&opt.uuid)
29         .ok_or_else(|| anyhow::anyhow!("filesystem was not found"))?;
30
31     tracing::info!(msg="found filesystem", %fs);
32     if fs.encrypted() {
33         let key = opt
34             .key_location
35             .0
36             .ok_or_else(|| anyhow::anyhow!("no keyoption specified for locked filesystem"))?;
37
38         key::prepare_key(&fs, key)?;
39     }
40
41     let mountpoint = opt
42         .mountpoint
43         .ok_or_else(|| anyhow::anyhow!("mountpoint option was not specified"))?;
44
45     fs.mount(&mountpoint, &opt.options)?;
46
47     Ok(())
48 }
49
50 #[cfg(test)]
51 mod test {
52     // use insta::assert_debug_snapshot;
53     // #[test]
54     // fn snapshot_testing() {
55     //  insta::assert_debug_snapshot!();
56     // }
57 }