Skip to main content

arcbox_virtio_fs/
handler.rs

1//! FUSE request handler trait — implemented downstream (e.g. by `arcbox-fs`).
2
3use arcbox_virtio_core::error::Result;
4
5use crate::session::FuseSession;
6
7/// Trait for handling FUSE requests.
8///
9/// This trait is implemented by `arcbox-fs::FsServer` to process FUSE
10/// filesystem operations. The `VirtioFs` device dispatches requests to
11/// this handler.
12///
13/// # Example
14///
15/// ```ignore
16/// use arcbox_virtio::fs::{FuseRequestHandler, FuseRequest, FuseResponse};
17///
18/// struct MyFsHandler;
19///
20/// impl FuseRequestHandler for MyFsHandler {
21///     fn handle_request(&self, request: &[u8]) -> arcbox_virtio_core::error::Result<Vec<u8>> {
22///         // Process FUSE request and return response
23///         Ok(FuseResponse::new(0, vec![]).into_data())
24///     }
25/// }
26/// ```
27pub trait FuseRequestHandler: Send + Sync {
28    /// Handles a FUSE request and returns the response.
29    ///
30    /// The request contains the raw FUSE protocol bytes from the guest.
31    /// The handler should parse, process, and return the response bytes.
32    fn handle_request(&self, request: &[u8]) -> Result<Vec<u8>>;
33
34    /// Called when the FUSE session is initialized.
35    ///
36    /// This is invoked after the `FUSE_INIT` handshake completes successfully.
37    fn on_init(&self, _session: &FuseSession) {}
38
39    /// Called when the FUSE session is destroyed.
40    fn on_destroy(&self) {}
41}