diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-01-04 06:23:02 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-01-04 06:23:04 -0600 |
| commit | c3c7a5b25a47e54df5d6b887d19f23c6fb20be8b (patch) | |
| tree | 7edf6f3a6c4ae2fd0fb6f8cb4139c80f0a365e01 /src/fuse/ops/mod.rs | |
| parent | 47cda6cd90d40a1b550d55f7181b34c21508c2fb (diff) | |
Split crate::fuse::ops into submodules
Diffstat (limited to '')
| -rw-r--r-- | src/fuse/ops/mod.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/fuse/ops/mod.rs b/src/fuse/ops/mod.rs new file mode 100644 index 0000000..39a4ef0 --- /dev/null +++ b/src/fuse/ops/mod.rs @@ -0,0 +1,68 @@ +use std::{ + ffi::{CStr, OsStr}, + os::unix::ffi::OsStrExt, +}; + +use crate::util::OutputChain; +use super::{private_trait::Sealed, Done, Operation, Reply, Request}; +use bytemuck::{bytes_of, Pod}; + +mod dir; +mod entry; +mod global; +mod open; +mod rw; +mod xattr; + +pub use dir::{BufferedReaddir, Lookup, Readdir}; +pub use entry::{Forget, Getattr}; +pub use global::{Init, Statfs}; +pub use open::{Access, Open, Opendir, Release, Releasedir}; +pub use rw::{Flush, Read, Readlink, Write}; +pub use xattr::{Getxattr, Listxattr, Removexattr, Setxattr}; + +pub(crate) use global::InitState; + +pub trait FromRequest<'o, O: Operation<'o>> { + //TODO: Shouldn't be public + fn from_request(request: &Request<'o, O>) -> Self; +} + +pub enum Any {} + +impl Sealed for Any {} + +impl<'o> Operation<'o> for Any { + type RequestBody = (); + type ReplyTail = (); +} + +impl<'o, O: Operation<'o>> FromRequest<'o, O> for () { + fn from_request(_request: &Request<'o, O>) -> Self {} +} + +impl<'o, O: Operation<'o>> Reply<'o, O> { + fn empty(self) -> Done<'o> { + self.chain(OutputChain::empty()) + } + + fn single<P: Pod>(self, single: &P) -> Done<'o> { + self.chain(OutputChain::tail(&[bytes_of(single)])) + } + + fn inner(self, deref: impl FnOnce(&Self) -> &[u8]) -> Done<'o> { + let result = self + .session + .ok(self.unique, OutputChain::tail(&[deref(&self)])); + self.finish(result) + } + + fn chain(self, chain: OutputChain<'_>) -> Done<'o> { + let result = self.session.ok(self.unique, chain); + self.finish(result) + } +} + +fn c_to_os(c_str: &CStr) -> &OsStr { + OsStr::from_bytes(c_str.to_bytes()) +} |
