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