1#![doc = include_str!("../DOC.md")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4#[macro_use]
21extern crate log;
22#[cfg(feature = "async")]
23mod r#async;
24mod directory_cache;
25mod fuserng;
26mod inode_table;
27mod types;
28#[cfg(feature = "async")]
29pub use r#async::{AsyncFilesystem, AsyncFuserNG};
30#[cfg(feature = "async")]
31pub use futures_core::Stream;
32#[cfg(feature = "async")]
34pub mod asynchronous {
35 pub use crate::AsyncFilesystem as Filesystem;
36 pub use crate::AsyncFuserNG as FuserNG;
37}
38pub use crate::fuserng::*;
39pub use crate::types::*;
40pub use fuser::FileType;
41pub use fuser::InitFlags;
42pub use fuser::KernelConfig;
43pub use fuser::MountOption;
44use std::io;
49use std::path::Path;
50
51#[derive(Debug, Default)]
54pub enum ThreadCount {
55 #[default]
57 Default,
58 NumThreads(usize),
60}
61
62impl ThreadCount {
63 fn value(&self) -> usize {
64 match self {
65 Self::Default => std::thread::available_parallelism().unwrap().into(),
66 Self::NumThreads(num_threads) => *num_threads,
67 }
68 }
69}
70
71impl From<usize> for ThreadCount {
72 fn from(value: usize) -> Self {
73 ThreadCount::NumThreads(value)
74 }
75}
76#[inline(always)]
79pub fn mount<FS: fuser::Filesystem, P: AsRef<Path>>(
80 fs: FS,
81 mountpoint: P,
82 options: &[MountOption],
83 num_threads: ThreadCount,
84) -> io::Result<()> {
85 let mut config = fuser::Config::default();
86 config.mount_options = options.to_vec();
87 let num_threads = num_threads.value();
88 if num_threads > 0 {
89 config.n_threads = Some(num_threads);
90 }
91 fuser::mount(fs, mountpoint, &config)
92}
93
94#[inline(always)]
99pub fn spawn_mount<FS: fuser::Filesystem + Send + 'static, P: AsRef<Path>>(
100 fs: FS,
101 mountpoint: P,
102 options: &[MountOption],
103 num_threads: ThreadCount,
104) -> io::Result<fuser::BackgroundSession> {
105 let mut config = fuser::Config::default();
106 config.mount_options = options.to_vec();
107 let num_threads = num_threads.value();
108 if num_threads > 0 {
109 config.n_threads = Some(num_threads);
110 }
111 fuser::spawn_mount(fs, mountpoint, &config)
112}