]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/mount/src/main.rs
Update bcachefs sources to 8e1519ccb6 bcachefs: Add tracepoint & counter for btree...
[bcachefs-tools-debian] / rust-src / mount / src / main.rs
1 use bcachefs_mount::Cli;
2 use bch_bindgen::{error, info};
3 use clap::Parser;
4 use colored::Colorize;
5
6 fn main() {
7     let opt = Cli::parse();
8     bch_bindgen::log::set_verbose_level(opt.verbose + bch_bindgen::log::ERROR);
9     colored::control::set_override(opt.colorize);
10     if let Err(e) = crate::main_inner(opt) {
11         error!("Fatal error: {}", e);
12     }
13 }
14
15 pub fn main_inner(opt: Cli) -> anyhow::Result<()> {
16     use bcachefs_mount::{filesystem, key};
17     unsafe {
18         libc::setvbuf(filesystem::stdout, std::ptr::null_mut(), libc::_IONBF, 0);
19         // libc::fflush(filesystem::stdout);
20     }
21
22     let fss = filesystem::probe_filesystems()?;
23     let fs = fss
24         .get(&opt.uuid)
25         .ok_or_else(|| anyhow::anyhow!("filesystem was not found"))?;
26
27     info!("found filesystem {}", fs);
28     if fs.encrypted() {
29         let key = opt
30             .key_location
31             .0
32             .ok_or_else(|| anyhow::anyhow!("no keyoption specified for locked filesystem"))?;
33
34         key::prepare_key(&fs, key)?;
35     }
36
37     let mountpoint = opt
38         .mountpoint
39         .ok_or_else(|| anyhow::anyhow!("mountpoint option was not specified"))?;
40
41     fs.mount(&mountpoint, &opt.options)?;
42
43     Ok(())
44 }
45
46 #[cfg(test)]
47 mod test {
48     // use insta::assert_debug_snapshot;
49     // #[test]
50     // fn snapshot_testing() {
51     //  insta::assert_debug_snapshot!();
52     // }
53 }