Skip to main content

async_fuser/ll/reply_async/
xattr.rs

1//! Response data implementation of async xattr operations.
2
3use std::io::IoSlice;
4
5use smallvec::SmallVec;
6
7use crate::ll::ResponseStruct;
8use crate::ll::fuse_abi;
9use crate::ll::ioslice_concat::IosliceConcat;
10use crate::ll::reply::Response;
11
12enum XattrPayload<'a> {
13    Size(ResponseStruct<fuse_abi::fuse_getxattr_out>),
14    Data([IoSlice<'a>; 1]),
15}
16
17impl IosliceConcat for XattrPayload<'_> {
18    fn iter_slices(&self) -> impl Iterator<Item = IoSlice<'_>> + '_ {
19        let slices = match self {
20            Self::Size(size) => SmallVec::<[IoSlice<'_>; 1]>::from_iter(size.iter_slices()),
21            Self::Data(data) => SmallVec::<[IoSlice<'_>; 1]>::from_iter(data.iter_slices()),
22        };
23        slices.into_iter()
24    }
25}
26
27/// Response data from async xattr operations.
28#[derive(Debug)]
29pub enum XattrResponse {
30    /// Report the size of the xattr payload.
31    Size(u32),
32    /// Return the xattr payload bytes.
33    Data(Vec<u8>),
34}
35
36impl XattrResponse {
37    /// Creates a size-reporting xattr response.
38    pub fn size(size: u32) -> Self {
39        Self::Size(size)
40    }
41
42    /// Creates a data xattr response.
43    pub fn data(data: Vec<u8>) -> Self {
44        Self::Data(data)
45    }
46}
47
48impl Response for XattrResponse {
49    fn payload(&self) -> impl IosliceConcat {
50        match self {
51            Self::Size(size) => XattrPayload::Size(ResponseStruct::new_xattr_size(*size)),
52            Self::Data(data) => XattrPayload::Data([IoSlice::new(data.as_slice())]),
53        }
54    }
55}