### Basic FUSE Filesystem Mount Example Source: https://docs.rs/easy_fuser/latest/easy_fuser Demonstrates how to implement the FuseHandler trait and mount a custom filesystem using easy_fuser. It shows the basic structure for a custom filesystem and how to start it with either serial or parallel features. ```rust use easy_fuser::prelude::*; use easy_fuser::templates::DefaultFuseHandler; use std::path::{Path, PathBuf}; struct MyFS { inner: Box, } impl FuseHandler for MyFS { fn get_inner(&self) -> &dyn FuseHandler { self.inner.as_ref() } } fn main() -> std::io::Result<()> { let fs = MyFS { inner: Box::new(DefaultFuseHandler::new()) }; #[cfg(feature="serial")] easy_fuser::mount(fs, Path::new("/mnt/myfs"), &[])?; #[cfg(not(feature="serial"))] easy_fuser::mount(fs, Path::new("/mnt/myfs"), &[], 4)?; Ok(()) } ``` -------------------------------- ### Basic FUSE Filesystem Mount Example Source: https://docs.rs/easy_fuser/latest/easy_fuser/index Demonstrates how to implement the FuseHandler trait and mount a custom filesystem using easy_fuser. It shows the basic structure for a custom filesystem and how to start it with either serial or parallel features. ```rust use easy_fuser::prelude::*; use easy_fuser::templates::DefaultFuseHandler; use std::path::{Path, PathBuf}; struct MyFS { inner: Box, } impl FuseHandler for MyFS { fn get_inner(&self) -> &dyn FuseHandler { self.inner.as_ref() } } fn main() -> std::io::Result<()> { let fs = MyFS { inner: Box::new(DefaultFuseHandler::new()) }; #[cfg(feature="serial")] easy_fuser::mount(fs, Path::new("/mnt/myfs"), &[])?; #[cfg(not(feature="serial"))] easy_fuser::mount(fs, Path::new("/mnt/myfs"), &[], 4)?; Ok(()) } ``` -------------------------------- ### Rust: File Handle Management Example Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/index Demonstrates creating an `OwnedFileHandle` from a raw value, borrowing it, and converting it to and from `OwnedFd`. This example highlights the safe abstractions provided by the `file_handle` module for FUSE file handle management. ```rust use std::os::fd::OwnedFd; use easy_fuser::types::file_handle::{OwnedFileHandle, BorrowedFileHandle}; // Creating an OwnedFileHandle from a raw value (unsafe) let owned_handle = unsafe { OwnedFileHandle::from_raw(42) }; // Borrowing the file handle let borrowed_handle = owned_handle.borrow(); // Converting to and from OwnedFd let owned_fd = owned_handle.into_owned_fd(); let new_owned_handle = OwnedFileHandle::from_owned_fd(owned_fd).unwrap(); // Note: The above example assumes the existence of a valid file handle or descriptor. // In real-world scenarios, ensure proper error handling and validity checks. ``` -------------------------------- ### Rust FUSE Handler Implementation Example Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/templates/fd_handler_helper.rs Example demonstrating how to instantiate and use `FdHandlerHelper` and `FdHandlerHelperReadOnly` with an inner FUSE handler. ```rust let inner_handler = YourInnerHandler::new(); // or DefaultFuseHandler::new{}; let fd_handler = FdHandlerHelper::new(inner_handler); // Use fd_handler as your primary FuseHandler // For read-only operations: let read_only_handler = FdHandlerHelperReadOnly::new(inner_handler); // or DefaultFuseHandler::new{}; // Use read_only_handler as your primary FuseHandler for read-only operations ``` -------------------------------- ### MirrorFs Usage Example Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/mirror_fs/index Demonstrates how to instantiate MirrorFsReadOnly and MirrorFs handlers, which mirror filesystem content. These handlers require a repository path and an inner FuseHandler implementation. ```rust let read_only_fs = MirrorFsReadOnly::new(repo_path, inner_handler); // or let read_write_fs = MirrorFs::new(repo_path, inner_handler); ``` -------------------------------- ### Rust Example: File Handle Operations Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/types/file_handle.rs Demonstrates creating an `OwnedFileHandle` from a raw value, borrowing it, and converting between `OwnedFileHandle` and `OwnedFd`. This example highlights the usage of the file handle management types. ```rust use std::os::fd::OwnedFd; use easy_fuser::types::file_handle::{OwnedFileHandle, BorrowedFileHandle}; // Creating an OwnedFileHandle from a raw value (unsafe) let owned_handle = unsafe { OwnedFileHandle::from_raw(42) }; // Borrowing the file handle let borrowed_handle = owned_handle.borrow(); // Converting to and from OwnedFd let owned_fd = owned_handle.into_owned_fd(); let new_owned_handle = OwnedFileHandle::from_owned_fd(owned_fd).unwrap(); // Note: The above example assumes the existence of a valid file handle or descriptor. // In real-world scenarios, ensure proper error handling and validity checks. ``` -------------------------------- ### Rust FdHandlerHelper Example Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/fd_handler_helper/index Demonstrates how to instantiate and use `FdHandlerHelper` for general filesystem operations and `FdHandlerHelperReadOnly` for read-only operations in Rust Fuse implementations. Ensure the returned file handle can be converted to a valid file descriptor. ```rust let inner_handler = YourInnerHandler::new(); // or DefaultFuseHandler::new{}; let fd_handler = FdHandlerHelper::new(inner_handler); // Use fd_handler as your primary FuseHandler // For read-only operations: let read_only_handler = FdHandlerHelperReadOnly::new(inner_handler); // or DefaultFuseHandler::new{}; // Use read_only_handler as your primary FuseHandler for read-only operations ``` -------------------------------- ### MirrorFsReadOnlyTrait Implementation Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/templates/mirror_fs.rs Defines the constructor (`new`) and a method to get the source directory path (`source_dir`) for the MirrorFsReadOnly struct, adhering to the MirrorFsTrait. ```rust impl MirrorFsTrait for MirrorFsReadOnly { fn new>(source_path: PathBuf, inner: THandler) -> Self { Self { source_path, inner: Box::new(FdHandlerHelperReadOnly::new(inner)), } } fn source_dir(&self) -> &Path { self.source_path.as_path() } } ``` -------------------------------- ### BorrowedFileHandle Methods Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/struct.BorrowedFileHandle Provides documentation for the methods available on the BorrowedFileHandle struct, including functions to get the raw file descriptor and create new instances from different types of file descriptors. ```APIDOC impl<'a> BorrowedFileHandle<'a> pub fn as_raw(&self) -> u64 Retrieves the raw u64 value of the file handle. pub fn as_borrowed_fd(&self) -> BorrowedFileHandle<'a> Returns a borrowed file handle. pub fn from_borrowed_fd(fd: BorrowedFileHandle<'a>) -> BorrowedFileHandle<'a> Creates a BorrowedFileHandle from another BorrowedFileHandle. pub fn from_owned_fd(fd: std::os::unix::io::OwnedFd) -> BorrowedFileHandle<'static> Creates a BorrowedFileHandle from an OwnedFd. Note: This creates a 'static lifetime handle. pub fn from_raw(fd: u64) -> BorrowedFileHandle<'static> Creates a BorrowedFileHandle from a raw u64 file descriptor. Note: This creates a 'static lifetime handle. ``` -------------------------------- ### Rust Directory Listing Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/unix_fs.rs Shows how to list entries within a directory using the `readdir` function. This example creates a temporary directory, adds a file, lists the directory contents, and asserts the presence of the created file. ```rust #[test] fn test_readdir() { let tmpdir = TempDir::new().unwrap(); let file1 = tmpdir.path().join("file1"); File::create(&file1).unwrap(); let entries = readdir(&tmpdir.path()).unwrap(); assert!(entries.iter().any(|(name, _)| name == Path::new("file1"))); fs::remove_file(&file1).unwrap(); drop(tmpdir); } ``` -------------------------------- ### FdHandlerHelperReadOnly FuseHandler Methods Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/fd_handler_helper/struct.FdHandlerHelperReadOnly Provides documentation for core file system operations implemented by FdHandlerHelperReadOnly, delegating to an underlying FuseHandler. Includes methods for getting the inner handler, flushing, synchronizing, seeking, and reading file data. ```APIDOC FuseHandler Methods for FdHandlerHelperReadOnly: get_inner: Signature: fn get_inner(&self) -> &dyn FuseHandler Description: Delegate unprovided methods to another FuseHandler, enabling composition. Parameters: - &self: A reference to the FdHandlerHelperReadOnly instance. Returns: - A reference to the underlying FuseHandler trait object. flush: Signature: fn flush(&self, _req: &RequestInfo, _file_id: TId, file_handle: BorrowedFileHandle<'_, TId>, _lock_owner: u64) -> FuseResult<()> Description: Flush cached data for an open file. Parameters: - _req: Request information (unused). - _file_id: The identifier for the file (unused). - file_handle: A borrowed handle to the file. - _lock_owner: The owner of the lock (unused). Returns: - FuseResult<()>: Indicates success or failure of the flush operation. fsync: Signature: fn fsync(&self, _req: &RequestInfo, _file_id: TId, file_handle: BorrowedFileHandle<'_, TId>, datasync: bool) -> FuseResult<()> Description: Synchronize file contents to persistent storage. Parameters: - _req: Request information (unused). - _file_id: The identifier for the file (unused). - file_handle: A borrowed handle to the file. - datasync: If true, only data synchronization is performed, not metadata. Returns: - FuseResult<()>: Indicates success or failure of the fsync operation. lseek: Signature: fn lseek(&self, _req: &RequestInfo, _file_id: TId, file_handle: BorrowedFileHandle<'_, TId>, seek: SeekFrom) -> FuseResult Description: Reposition the read/write file offset. Parameters: - _req: Request information (unused). - _file_id: The identifier for the file (unused). - file_handle: A borrowed handle to the file. - seek: The SeekFrom enum specifying the new offset. Returns: - FuseResult: The new offset from the beginning of the file on success, or an error. read: Signature: fn read(&self, _req: &RequestInfo, _file_id: TId, file_handle: BorrowedFileHandle<'_, TId>, seek: SeekFrom, size: u32, _flags: FUSEOpenFlags, _lock_owner: Option) -> FuseResult> Description: Read data from a file at a specified offset and size. Parameters: - _req: Request information (unused). - _file_id: The identifier for the file (unused). - file_handle: A borrowed handle to the file. - seek: The SeekFrom enum specifying the offset to read from. - size: The number of bytes to read. - _flags: Open flags for the file (unused). - _lock_owner: The owner of the lock (unused). Returns: - FuseResult>: A vector of bytes containing the read data on success, or an error. ``` -------------------------------- ### easy_fuser Crate Overview Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/index Provides essential information about the easy_fuser crate, including its version, license, homepage, repository, and dependencies. It also highlights the documentation coverage percentage. ```text Project: /context7/rs-easy_fuser Content: [Docs.rs](/) * easy_fuser-0.4.1 + easy_fuser 0.4.1 + [Permalink](/easy_fuser/0.4.1/easy_fuser/templates/index.html "Get a link to this specific version") + [Docs.rs crate page](/crate/easy_fuser/latest "See easy_fuser in docs.rs") + [MIT](https://spdx.org/licenses/MIT) + Links + [Homepage](https://github.com/Alogani/easy_fuser) + [Repository](https://github.com/Alogani/easy_fuser) + [crates.io](https://crates.io/crates/easy_fuser "See easy_fuser in crates.io") + [Source](/crate/easy_fuser/latest/source/ "Browse source of easy_fuser-0.4.1") + Owners + [Alogani](https://crates.io/users/Alogani) + Dependencies + - [async-trait ^0.1.83 *normal* *optional*](/async-trait/%5E0.1.83) - [bitflags ^2.6.0 *normal*](/bitflags/%5E2.6.0) - [fuser ^0.15 *normal*](/fuser/%5E0.15) - [libc ^0.2 *normal*](/libc/%5E0.2) - [log ^0.4 *normal*](/log/%5E0.4) - [parking_lot ^0.12 *normal* *optional*](/parking_lot/%5E0.12) - [threadpool ^1.8 *normal* *optional*](/threadpool/%5E1.8) - [tokio ^1.42.0 *normal* *optional*](/tokio/%5E1.42.0) - [env_logger ^0.11 *dev*](/env_logger/%5E0.11) - [tempfile ^3.14 *dev*](/tempfile/%5E3.14) + Versions + [**77.48%** of the crate is documented](/crate/easy_fuser/latest) * Platform + [x86_64-unknown-linux-gnu](/crate/easy_fuser/latest/target-redirect/x86_64-unknown-linux-gnu/easy_fuser/templates/index.html) * [Feature flags](/crate/easy_fuser/latest/features "Browse available feature flags of easy_fuser-0.4.1") * docs.rs + [About docs.rs](/about) + [Privacy policy](https://foundation.rust-lang.org/policies/privacy-policy/#docs.rs) * Rust + [Rust website](https://www.rust-lang.org/) + [The Book](https://doc.rust-lang.org/book/) + [Standard Library API Reference](https://doc.rust-lang.org/std/) + [Rust by Example](https://doc.rust-lang.org/rust-by-example/) + [The Cargo Guide](https://doc.rust-lang.org/cargo/guide/) + [Clippy Documentation](https://doc.rust-lang.org/nightly/clippy) ``` -------------------------------- ### Rust IntoRawFd Example Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/trait.IntoRawFd An example demonstrating how to use the into_raw_fd method from the IntoRawFd trait in Rust to obtain a raw file descriptor from a File object. ```Rust use std::fs::File; #[cfg(any(unix, target_os = "wasi"))] use std::os::fd::{IntoRawFd, RawFd}; let f = File::open("foo.txt")?; #[cfg(any(unix, target_os = "wasi"))] let raw_fd: RawFd = f.into_raw_fd(); ``` -------------------------------- ### easy_fuser Session API Documentation Source: https://docs.rs/easy_fuser/latest/easy_fuser/prelude/struct.Session Comprehensive API documentation for the `Session` struct in the easy_fuser crate. This includes methods for creating, running, and managing FUSE filesystem sessions, along with details on its trait implementations. ```APIDOC Struct Session Represents a FUSE filesystem session. ```rust pub struct Session where FS: Filesystem, ``` **Description:** The session data structure manages the lifecycle of a FUSE filesystem, handling communication between the kernel and the userspace filesystem implementation. **Methods:** * **`new(filesystem: FS) -> Result, io::Error>`** * Creates a new FUSE session. * **Parameters:** * `filesystem`: An implementation of the `Filesystem` trait. * **Returns:** A `Result` containing the `Session` on success or an `io::Error` on failure. * **`from_fd(filesystem: FS, fd: RawFd) -> Result, io::Error>`** * Creates a new FUSE session from an existing file descriptor. * **Parameters:** * `filesystem`: An implementation of the `Filesystem` trait. * `fd`: The raw file descriptor for the FUSE device. * **Returns:** A `Result` containing the `Session` on success or an `io::Error` on failure. * **`run(&mut self) -> Result<(), io::Error>`** * Runs the FUSE session, blocking until the filesystem is unmounted. * **Parameters:** None. * **Returns:** A `Result` indicating success or an `io::Error` if an issue occurs during execution. * **`spawn(filesystem: FS) -> Result, io::Error>`** * Spawns a new FUSE session in a separate thread. * **Parameters:** * `filesystem`: An implementation of the `Filesystem` trait. * **Returns:** A `Result` containing the `Session` on success or an `io::Error` on failure. * **`unmount(&mut self) -> Result<(), io::Error>`** * Unmounts the FUSE filesystem. * **Parameters:** None. * **Returns:** A `Result` indicating success or an `io::Error` if unmounting fails. * **`unmount_callable(&mut self) -> Result<(), io::Error>`** * Unmounts the FUSE filesystem, allowing for callable unmount operations. * **Parameters:** None. * **Returns:** A `Result` indicating success or an `io::Error` if unmounting fails. **Trait Implementations:** * **`AsFd`**: Provides access to the underlying file descriptor. * **`Debug`**: Allows the `Session` to be formatted for debugging. * **`Drop`**: Ensures proper cleanup and unmounting when the `Session` goes out of scope. **Related Methods/Concepts:** * `fuser::Filesystem` trait: The core trait that user-defined filesystems must implement. * `fuser::MountOption`: Used for configuring mount options. * `fuser::MountPoint`: Represents the mount point of the filesystem. ``` -------------------------------- ### Rust: FuseHandler::init - Initialize filesystem and configure kernel Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/fd_handler_helper/struct.FdHandlerHelperReadOnly Initializes the filesystem and sets up the kernel connection. It requires request information and mutable access to kernel configuration. ```Rust fn init(&self, req: &[RequestInfo], config: &mut KernelConfig) -> FuseResult<()> // Initialize the filesystem and configure kernel connection ``` -------------------------------- ### FuseHandler API Documentation Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/mirror_fs/struct.MirrorFs Comprehensive documentation for FuseHandler methods, including signatures, parameters, and return types for file system operations. ```APIDOC FuseHandler::bmap fn bmap(&self, req: &RequestInfo, file_id: TId, blocksize: u32, idx: u64) -> FuseResult Maps block index within file to block index within device. Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the file. blocksize: u32 - The size of the block. idx: u64 - The block index. Returns: FuseResult - The mapped block index or an error. ``` ```APIDOC FuseHandler::copy_file_range fn copy_file_range(&self, req: &RequestInfo, file_in: TId, file_handle_in: BorrowedFileHandle<'_>, offset_in: i64, file_out: TId, file_handle_out: BorrowedFileHandle<'_>, offset_out: i64, len: u64, flags: u32) -> FuseResult Copy the specified range from the source inode to the destination inode. Parameters: req: RequestInfo - Information about the request. file_in: TId - The identifier for the input file. file_handle_in: BorrowedFileHandle<'_> - Handle to the input file. offset_in: i64 - The offset in the input file. file_out: TId - The identifier for the output file. file_handle_out: BorrowedFileHandle<'_> - Handle to the output file. offset_out: i64 - The offset in the output file. len: u64 - The number of bytes to copy. flags: u32 - Flags for the copy operation. Returns: FuseResult - The number of bytes copied or an error. ``` ```APIDOC FuseHandler::fallocate fn fallocate(&self, req: &RequestInfo, file_id: TId, file_handle: BorrowedFileHandle<'_>, offset: i64, length: i64, mode: FallocateFlags) -> FuseResult<()> Preallocate or deallocate space to a file. Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the file. file_handle: BorrowedFileHandle<'_> - Handle to the file. offset: i64 - The offset in the file. length: i64 - The length of the space to allocate or deallocate. mode: FallocateFlags - Flags specifying the allocation mode. Returns: FuseResult<()> - Success or an error. ``` ```APIDOC FuseHandler::flush fn flush(&self, req: &RequestInfo, file_id: TId, file_handle: BorrowedFileHandle<'_>, lock_owner: u64) -> FuseResult<()> Flush cached data for an open file. Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the file. file_handle: BorrowedFileHandle<'_> - Handle to the file. lock_owner: u64 - The owner of the lock. Returns: FuseResult<()> - Success or an error. ``` ```APIDOC FuseHandler::forget fn forget(&self, req: &RequestInfo, file_id: TId, nlookup: u64) Release references to an inode, if the nlookup count reaches zero (to subtract from the number of lookups). Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the inode. nlookup: u64 - The number of lookups to subtract. ``` ```APIDOC FuseHandler::fsync fn fsync(&self, req: &RequestInfo, file_id: TId, file_handle: BorrowedFileHandle<'_>, datasync: bool) -> FuseResult<()> Synchronize file contents. Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the file. file_handle: BorrowedFileHandle<'_> - Handle to the file. datasync: bool - Whether to perform data synchronization only. Returns: FuseResult<()> - Success or an error. ``` ```APIDOC FuseHandler::fsyncdir fn fsyncdir(&self, req: &RequestInfo, file_id: TId, file_handle: BorrowedFileHandle<'_>, datasync: bool) -> FuseResult<()> Synchronize directory contents. Parameters: req: RequestInfo - Information about the request. file_id: TId - The identifier for the directory. file_handle: BorrowedFileHandle<'_> - Handle to the directory. datasync: bool - Whether to perform data synchronization only. Returns: FuseResult<()> - Success or an error. ``` -------------------------------- ### Example: Using AsFd with Arc and Box Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/trait.AsFd A practical example demonstrating how to implement a custom trait (MyTrait) that requires AsFd for types wrapped in Arc and Box. This showcases the utility of the AsFd implementations for generic programming. ```rust use std::net::UdpSocket; use std::sync::Arc; trait MyTrait: AsFd {} impl MyTrait for Arc {} impl MyTrait for Box {} ``` -------------------------------- ### Example: Custom FUSE Filesystem Implementation in Rust Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/fuse_handler.rs This example demonstrates how to implement a custom FUSE filesystem by embedding and extending the `MirrorFsReadOnly` template. It shows how to create a struct that holds an inner handler and overrides specific methods like `lookup` to add custom logic while delegating other operations to the inner handler. ```rust use easy_fuser::templates::{DefaultFuseHandler, mirror_fs::*}; use easy_fuser::prelude::*; use std::path::{Path, PathBuf}; use std::ffi::OsStr; struct MyCustomFs { inner: Box>, // other fields... } impl MyCustomFs { pub fn new(source_path: PathBuf) -> Self { MyCustomFs { inner: Box::new(MirrorFsReadOnly::new(source_path, DefaultFuseHandler::new())) } } } impl FuseHandler for MyCustomFs { fn get_inner(&self) -> &dyn FuseHandler { // Delegate to MirrorFsReadOnly for standard behavior self.inner.as_ref() } fn lookup(&self, req: &RequestInfo, parent_id: PathBuf, name: &OsStr) -> FuseResult { // Custom logic for lookup operation // ... // Delegate to inner handler for standard behavior self.inner.lookup(req, parent_id, name) } // Implement other FuseHandler methods as needed, delegating to self.inner as appropriate // ... } ``` -------------------------------- ### easy_fuser templates.rs Module Overview Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/templates.rs Provides a high-level overview of the templates module in the easy_fuser crate. It outlines the purpose, key features like composability and customizability, and lists the available templates for FUSE filesystem development. ```rust //! # Template Implementations for easy_fuser //! //! This module provides a collection of template implementations and utility helpers //! designed to simplify the creation of FUSE filesystems using the easy_fuser library. //! //! ## Key Features: //! //! - **Composable Templates**: All templates in this module are designed with composition //! in mind. They can be used individually or combined to create more complex filesystem //! behaviors. //! //! - **Customizable Behavior**: Each function within these templates can be overridden, //! allowing for fine-grained control and customization of filesystem operations. //! //! - **DefaultFuseHandler**: A comprehensive starting point for implementing FUSE //! filesystems. It provides a default behavior for all standard FUSE operations. //! //! ## Usage: //! //! Users typically leverage these templates as a foundation for their own filesystem //! implementations. By extending or composing these templates, developers can rapidly //! prototype and implement custom FUSE filesystems while maintaining the flexibility //! to override specific behaviors as needed. //! //! ## Available Templates: //! //! - `DefaultFuseHandler`: A complete implementation of basic FUSE operations. //! - `fd_handler_helper`: Utilities for handling file descriptors in FUSE operations. //! - `mirror_fs`: Templates for creating mirror filesystems. //! //! For detailed information on each template, refer to their respective documentation. // mod default_fuse_handler; pub use default_fuse_handler::DefaultFuseHandler; pub mod fd_handler_helper; pub mod mirror_fs; ``` -------------------------------- ### easy_fuser Crate Information Source: https://docs.rs/easy_fuser/latest/easy_fuser/all Provides essential metadata and links for the easy_fuser Rust crate. This includes versioning, licensing, source code repository, and package manager links. ```APIDOC Crate: easy_fuser Version: 0.4.1 License: MIT Homepage: https://github.com/Alogani/easy_fuser Repository: https://github.com/Alogani/easy_fuser crates.io: https://crates.io/crates/easy_fuser Docs.rs Page: /easy_fuser/0.4.1/easy_fuser/all.html Source Browse: /crate/easy_fuser/latest/source/ ``` -------------------------------- ### Get Root Inode Source: https://docs.rs/easy_fuser/latest/easy_fuser/inode_mapper/struct.InodeMapper Retrieves the root Inode from the InodeMapper instance. ```Rust pub fn get_root_inode(&self) -> Inode ``` -------------------------------- ### easy_fuser Dependencies Source: https://docs.rs/easy_fuser/latest/easy_fuser/all Lists the direct dependencies required for the easy_fuser crate, categorized by their usage (normal, optional, dev). This helps understand the crate's ecosystem and potential build configurations. ```APIDOC Dependencies: - async-trait ^0.1.83 (normal, optional) - bitflags ^2.6.0 (normal) - fuser ^0.15 (normal) - libc ^0.2 (normal) - log ^0.4 (normal) - parking_lot ^0.12 (normal, optional) - threadpool ^1.8 (normal, optional) - tokio ^1.42.0 (normal, optional) - env_logger ^0.11 (dev) - tempfile ^3.14 (dev) ``` -------------------------------- ### Rust: Get callable fuser unmount object Source: https://docs.rs/easy_fuser/latest/easy_fuser/prelude/struct.Session Returns a thread-safe object that can be used to unmount the Filesystem. ```rust pub fn unmount_callable(&mut self) -> [SessionUnmounter](struct.SessionUnmounter.html "struct easy_fuser::prelude::SessionUnmounter") Returns a thread-safe object that can be used to unmount the Filesystem ``` -------------------------------- ### Rust: FUSEGetAttrFlags for Get Attributes Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/types/flags.rs Flags used in FUSE getattr operations, specifying how attributes should be retrieved. ```Rust bitflags! { #[derive(Debug, Copy, Clone)] pub struct FUSEGetAttrFlags: i32 { const GETATTR_FH = 1 << 0; const _ = !0; } } ``` -------------------------------- ### easy_fuser Module: templates Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/index Documentation for the 'templates' module within the easy_fuser crate. It outlines the purpose, key features, usage patterns, and available template implementations for building FUSE filesystems. ```text ## [easy_fuser](../../easy_fuser/index.html)0.4.1 ## Module templates ### Sections * [Template Implementations for easy_fuser](#template-implementations-for-easy_fuser "Template Implementations for easy_fuser") + [Key Features:](#key-features "Key Features:") + [Usage:](#usage "Usage:") + [Available Templates:](#available-templates "Available Templates:") ### [Module Items](#modules) * [Modules](#modules "Modules") * [Structs](#structs "Structs") ## [In crate easy_fuser](../index.html) [easy_fuser](../index.html) # Module templatesCopy item path [Source](../../src/easy_fuser/templates.rs.html#1-38) Expand description ## [§](#template-implementations-for-easy_fuser)Template Implementations for easy_fuser This module provides a collection of template implementations and utility helpers designed to simplify the creation of FUSE filesystems using the easy_fuser library. ### [§](#key-features)Key Features: * **Composable Templates**: All templates in this module are designed with composition in mind. They can be used individually or combined to create more complex filesystem behaviors. * **Customizable Behavior**: Each function within these templates can be overridden, allowing for fine-grained control and customization of filesystem operations. * **DefaultFuseHandler**: A comprehensive starting point for implementing FUSE filesystems. It provides a default behavior for all standard FUSE operations. ### [§](#usage)Usage: Users typically leverage these templates as a foundation for their own filesystem implementations. By extending or composing these templates, developers can rapidly prototype and implement custom FUSE filesystems while maintaining the flexibility to override specific behaviors as needed. ### [§](#available-templates)Available Templates: * `DefaultFuseHandler`: A complete implementation of basic FUSE operations. * `fd_handler_helper`: Utilities for handling file descriptors in FUSE operations. * `mirror_fs`: Templates for creating mirror filesystems. For detailed information on each template, refer to their respective documentation. ## Modules[§](#modules) [fd_handler_helper](fd_handler_helper/index.html "mod easy_fuser::templates::fd_handler_helper") : FdHandlerHelper and FdHandlerHelperReadOnly [mirror_fs](mirror_fs/index.html "mod easy_fuser::templates::mirror_fs") : MirrorFs ## Structs[§](#structs) [DefaultFuseHandler](struct.DefaultFuseHandler.html "struct easy_fuser::templates::DefaultFuseHandler") : DefaultFuseHandler ``` -------------------------------- ### FUSEWriteFlags Complement and Iteration Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/flags/struct.FUSEWriteFlags Details on how to get the bitwise complement of a flag set and how to iterate over the individual flags that are set. ```APIDOC complement(self) -> Self - Computes the bitwise negation of the flag set, truncating the result. - This is equivalent to `!self`. - Parameters: - self: The flag set to complement. - Returns: A new flag set representing the complement. iter(&self) -> Iter - Yields a set of contained flags values, corresponding to defined named flags. - Any unknown bits are yielded together as a final flags value. - Returns: An iterator over the set flags. iter_names(&self) -> IterNames - Yields only the contained named flags values. - Bits not corresponding to a defined named flag are not yielded. - Returns: An iterator over the set named flags. ``` -------------------------------- ### Get Inode Information Source: https://docs.rs/easy_fuser/latest/easy_fuser/inode_mapper/struct.InodeMapper Retrieves immutable information for a specific inode. Returns None if the inode does not exist in the mapper. ```APIDOC pub fn get(&self, inode: &Inode) -> Option> - **Description**: Retrieves immutable information associated with a given inode. - **Parameters**: - `inode`: The inode for which to retrieve information. - **Returns**: An `Option` containing `InodeInfo` if the inode is found, otherwise `None`. ``` -------------------------------- ### MirrorFsTrait for MirrorFs - Filesystem Methods Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/mirror_fs/struct.MirrorFs Implements filesystem operations for the MirrorFs struct, including creating a new MirrorFs instance and retrieving the source directory path. These methods are part of the MirrorFsTrait. ```APIDOC fn new>(source_path: PathBuf, inner: U) -> Self [Source](../../../src/easy_fuser/templates/mirror_fs.rs.html#307-309)[§](#method.source_dir) fn source_dir(&self) -> &Path [Source](../../../src/easy_fuser/templates/mirror_fs.rs.html#300-305)[§](#method.new) ``` -------------------------------- ### Generic Any Trait Implementation Source: https://docs.rs/easy_fuser/latest/easy_fuser/inode_mapper/struct.LookupResult Blanket implementation of the Any trait for any type T that is 'static and Sized. Provides a way to get the TypeId of a value. ```APIDOC impl Any for T where T: 'static + ?Sized fn type_id(&self) -> TypeId Gets the TypeId of self. ``` -------------------------------- ### BackgroundSession API Documentation (easy_fuser) Source: https://docs.rs/easy_fuser/latest/easy_fuser/prelude/struct.BackgroundSession Details the `BackgroundSession` struct, its fields, and associated methods, providing information on usage, parameters, and return types for managing background sessions. ```APIDOC Struct BackgroundSession Represents a background session, holding a thread guard for managing asynchronous operations. Fields: guard: JoinHandle> - Thread guard of the background session. Methods: new() - Creates a new BackgroundSession. join() - Joins the background thread, waiting for its completion. Source: https://docs.rs/fuser/0.15.1/x86_64-unknown-linux-gnu/src/fuser/session.rs.html#242 Implementations: impl BackgroundSession Source: https://docs.rs/fuser/0.15.1/x86_64-unknown-linux-gnu/src/fuser/session.rs.html#256 ``` -------------------------------- ### Get Mutable Inode Information Source: https://docs.rs/easy_fuser/latest/easy_fuser/inode_mapper/struct.InodeMapper Retrieves mutable information for a specific inode. Returns None if the inode does not exist in the mapper. ```APIDOC pub fn get_mut(&mut self, inode: &Inode) -> Option> - **Description**: Retrieves mutable information associated with a given inode. - **Parameters**: - `inode`: The inode for which to retrieve mutable information. - **Returns**: An `Option` containing `InodeInfoMut` if the inode is found, otherwise `None`. ``` -------------------------------- ### Rust Example: Implementing Trait with AsRawFd Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/trait.AsRawFd Demonstrates how to implement a custom trait that requires the AsRawFd bound for types wrapped in Arc and Box. ```rust use std::net::UdpSocket; use std::sync::Arc; trait MyTrait: AsRawFd { } impl MyTrait for Arc {} impl MyTrait for Box {} ``` -------------------------------- ### Mounting Operations Source: https://docs.rs/easy_fuser/latest/easy_fuser/all Functions related to mounting file systems. These include initiating a mount and spawning a mount process. ```APIDOC mount - Initiates a file system mount operation. spawn_mount - Spawns a new process to handle a mount operation. ``` -------------------------------- ### Get Mutable Inode Reference Source: https://docs.rs/easy_fuser/latest/src/easy_fuser/inode_mapper.rs Provides mutable access to an Inode's information, including its parent, name, and data. Returns `None` if the inode is not found. ```rust pub fn get_mut(&mut self, inode: &Inode) -> Option> { self.data .inodes .get_mut(inode) .map(|inode_value| InodeInfoMut { parent: &inode_value.parent, name: inode_value.name.as_mut(), data: &mut inode_value.data, }) } ``` -------------------------------- ### FuseHandler Methods: File Operations and Lifecycle Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/mirror_fs/struct.MirrorFs This section details the methods available on the FuseHandler trait for managing file system operations. It includes functions for setting attributes, creating symbolic links, removing files, initializing the filesystem, and performing cleanup. ```APIDOC FuseHandler Methods: File Operations and Lifecycle setattr: Set file attributes. Signature: fn setattr(&self, _req: &RequestInfo, file_id: PathBuf, attrs: SetAttrRequest) -> FuseResult Parameters: _req: RequestInfo - Information about the request. file_id: PathBuf - The path to the file. attrs: SetAttrRequest - The attributes to set. Returns: FuseResult - Result of the operation. setxattr: Set an extended attribute. Signature: fn setxattr(&self, _req: &RequestInfo, file_id: PathBuf, name: &OsStr, value: Vec, flags: FUSESetXAttrFlags, position: u32) -> FuseResult<()> Parameters: _req: RequestInfo - Information about the request. file_id: PathBuf - The path to the file. name: &OsStr - The name of the extended attribute. value: Vec - The value of the extended attribute. flags: FUSESetXAttrFlags - Flags for the operation. position: u32 - Position for the attribute. Returns: FuseResult<()> - Result of the operation. symlink: Create a symbolic link. Signature: fn symlink(&self, _req: &RequestInfo, parent_id: PathBuf, link_name: &OsStr, target: &Path) -> FuseResult Parameters: _req: RequestInfo - Information about the request. parent_id: PathBuf - The parent directory path. link_name: &OsStr - The name of the symbolic link. target: &Path - The target path for the link. Returns: FuseResult - Result of the operation. unlink: Remove a file. Signature: fn unlink(&self, _req: &RequestInfo, parent_id: PathBuf, name: &OsStr) -> FuseResult<()> Parameters: _req: RequestInfo - Information about the request. parent_id: PathBuf - The parent directory path. name: &OsStr - The name of the file to remove. Returns: FuseResult<()> - Result of the operation. get_default_ttl: Provide a default Time-To-Live for file metadata. Signature: fn get_default_ttl(&self) -> Duration Returns: Duration - The default TTL value. init: Initialize the filesystem and configure kernel connection. Signature: fn init(&self, req: &RequestInfo, config: &mut KernelConfig) -> FuseResult<()> Parameters: req: &RequestInfo - Information about the initialization request. config: &mut KernelConfig - Kernel configuration to be set. Returns: FuseResult<()> - Result of the initialization. destroy: Perform cleanup operations on filesystem exit. Signature: fn destroy(&self) Description: Cleans up resources when the filesystem is unmounted or exits. ``` -------------------------------- ### FuseHandler API Methods Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/fd_handler_helper/struct.FdHandlerHelper This section details the methods available on the FuseHandler trait for managing filesystem operations. It covers initialization, file access control, block mapping, file creation, and cleanup procedures. ```APIDOC FuseHandler Methods: get_default_ttl - Provides a default Time-To-Live for file metadata. - Signature: fn get_default_ttl(&self) -> Duration - Parameters: - self: A reference to the FuseHandler instance. - Returns: A Duration representing the default TTL. init - Initializes the filesystem and configures the kernel connection. - Signature: fn init(&self, req: &RequestInfo, config: &mut KernelConfig) -> FuseResult<()> - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - config: A mutable reference to KernelConfig for configuration. - Returns: A FuseResult indicating success or failure. destroy - Performs cleanup operations on filesystem exit. - Signature: fn destroy(&self) - Parameters: - self: A reference to the FuseHandler instance. access - Checks file access permissions. - Signature: fn access(&self, req: &RequestInfo, file_id: TId, mask: AccessMask) -> FuseResult<()> - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - file_id: The identifier for the file. - mask: AccessMask specifying the permissions to check. - Returns: A FuseResult indicating success or failure. bmap - Maps a block index within a file to its corresponding block index within the device. - Signature: fn bmap(&self, req: &RequestInfo, file_id: TId, blocksize: u32, idx: u64) -> FuseResult - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - file_id: The identifier for the file. - blocksize: The size of the blocks. - idx: The index of the block to map. - Returns: A FuseResult containing the mapped block index on success. create - Creates and opens a new file. - Signature: fn create(&self, req: &RequestInfo, parent_id: TId, name: &OsStr, mode: u32, umask: u32, flags: OpenFlags) -> FuseResult<(OwnedFileHandle, TId::Metadata, FUSEOpenResponseFlags)> - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - parent_id: The identifier of the parent directory. - name: The name of the file to create. - mode: The file mode (permissions). - umask: The umask to apply. - flags: OpenFlags specifying how to open the file. - Returns: A FuseResult containing the file handle, metadata, and open flags on success. forget - Releases references to an inode. If the nlookup count reaches zero, the inode is forgotten. - Signature: fn forget(&self, req: &RequestInfo, file_id: TId, nlookup: u64) - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - file_id: The identifier for the inode. - nlookup: The number of lookups to subtract. fsyncdir - Synchronizes directory data to disk. - Signature: fn fsyncdir(&self, req: &RequestInfo, file_id: TId, datasync: bool, datasync_metadata: bool, datasync_dir: bool) -> FuseResult<()> - Parameters: - self: A reference to the FuseHandler instance. - req: RequestInfo struct containing request details. - file_id: The identifier for the directory. - datasync: Flag for data synchronization. - datasync_metadata: Flag for metadata synchronization. - datasync_dir: Flag for directory synchronization. - Returns: A FuseResult indicating success or failure. ``` -------------------------------- ### Rust Any Trait: type_id Source: https://docs.rs/easy_fuser/latest/easy_fuser/types/file_handle/struct.OwnedFileHandle The `Any` trait provides a way to get the `TypeId` of a type, enabling runtime type identification. It requires the type to be `'static` and `?Sized`. ```APIDOC trait Any fn type_id(&self) -> TypeId Gets the TypeId of self. ``` -------------------------------- ### Rust Any Trait: type_id Source: https://docs.rs/easy_fuser/latest/easy_fuser/inode_mapper/struct.InodeMapper The Any trait provides a way to get the unique TypeId of a type. The type_id method returns the TypeId of the implementing type. ```APIDOC trait Any fn type_id(&self) -> TypeId Gets the TypeId of self. Parameters: - self: A reference to the object implementing Any. Returns: - TypeId: The unique identifier for the object's type. ``` -------------------------------- ### easy_fuser Crate Structure Overview Source: https://docs.rs/easy_fuser/latest/easy_fuser/all Outlines the main categories of items defined within the easy_fuser crate's API. This provides a high-level view of the crate's structure and available components. ```APIDOC Crate Items: - Structs - Enums - Constants - Traits - Functions - Type Aliases ``` -------------------------------- ### Rust Any Trait: type_id Source: https://docs.rs/easy_fuser/latest/easy_fuser/templates/mirror_fs/struct.MirrorFs The Any trait provides a way to get the unique TypeId of a type. The type_id method returns the TypeId of the implementing type. ```APIDOC trait Any fn type_id(&self) -> TypeId Gets the TypeId of self. Parameters: - self: A reference to the object implementing Any. Returns: - TypeId: The unique identifier for the object's type. ```