1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use core::fmt;
use core::mem::size_of;
use crate::error::ErrorCode;
use crate::internal::fuse_kernel;
use crate::protocol::common::NodeId;
pub use fuse_kernel::OpcodeEnum as Opcode;
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct RequestHeader(fuse_kernel::fuse_in_header);
impl RequestHeader {
pub(crate) fn new_ref(raw: &fuse_kernel::fuse_in_header) -> &Self {
unsafe {
&*(raw as *const fuse_kernel::fuse_in_header
as *const RequestHeader)
}
}
pub fn opcode(&self) -> u32 {
self.0.opcode.0
}
pub fn opcode_enum(&self) -> Option<Opcode> {
self.0.opcode.to_enum()
}
pub fn request_id(&self) -> u64 {
self.0.unique
}
pub fn node_id(&self) -> Option<NodeId> {
NodeId::new(self.0.nodeid)
}
pub fn user_id(&self) -> u32 {
self.0.uid
}
pub fn group_id(&self) -> u32 {
self.0.gid
}
pub fn process_id(&self) -> u32 {
self.0.pid
}
pub fn size(&self) -> u32 {
self.0.len
}
pub fn body_len(&self) -> u32 {
const BODY_START: u32 = size_of::<fuse_kernel::fuse_in_header>() as u32;
return self.0.len.saturating_sub(BODY_START);
}
}
impl fmt::Debug for RequestHeader {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("RequestHeader")
.field("opcode", &self.0.opcode.0)
.field("opcode_enum", &format_args!("{:?}", self.opcode_enum()))
.field("request_id", &self.0.unique)
.field("node_id", &format_args!("{:?}", self.node_id()))
.field("user_id", &self.0.uid)
.field("group_id", &self.0.gid)
.field("process_id", &self.0.pid)
.field("size", &self.0.len)
.field("body_len", &self.body_len())
.finish()
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct ResponseHeader(fuse_kernel::fuse_out_header);
impl ResponseHeader {
pub fn request_id(&self) -> u64 {
self.0.unique
}
pub fn error(&self) -> Option<ErrorCode> {
let code = core::num::NonZeroU16::new((-self.0.error) as u16)?;
Some(ErrorCode::new(code))
}
pub fn error_name(&self) -> Option<&'static str> {
let code = self.error()?;
code.name()
}
pub fn size(&self) -> u32 {
self.0.len
}
pub fn body_len(&self) -> u32 {
const BODY_START: u32 =
size_of::<fuse_kernel::fuse_out_header>() as u32;
return self.0.len.saturating_sub(BODY_START);
}
}
impl fmt::Debug for ResponseHeader {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("ResponseHeader")
.field("request_id", &self.0.unique)
.field("error", &format_args!("{:?}", &self.error()))
.field("error_name", &format_args!("{:?}", &self.error_name()))
.field("size", &self.0.len)
.field("body_len", &self.body_len())
.finish()
}
}