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
133
134
use core::{fmt, time};
use crate::internal::fuse_kernel;
use crate::protocol::common::{FileMode, NodeId};
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct NodeAttr(fuse_kernel::fuse_attr);
impl NodeAttr {
pub fn node_id(&self) -> Option<NodeId> {
NodeId::new(self.0.ino)
}
pub fn set_node_id(&mut self, node_id: NodeId) {
self.0.ino = node_id.get();
}
pub fn size(&self) -> u64 {
self.0.size
}
pub fn set_size(&mut self, size: u64) {
self.0.size = size;
}
pub fn blocks(&self) -> u64 {
self.0.blocks
}
pub fn set_blocks(&mut self, blocks: u64) {
self.0.blocks = blocks;
}
pub fn atime(&self) -> time::Duration {
time::Duration::new(self.0.atime, self.0.atimensec)
}
pub fn set_atime(&mut self, atime: time::Duration) {
self.0.atime = atime.as_secs();
self.0.atimensec = atime.subsec_nanos();
}
pub fn mtime(&self) -> time::Duration {
time::Duration::new(self.0.mtime, self.0.mtimensec)
}
pub fn set_mtime(&mut self, mtime: time::Duration) {
self.0.mtime = mtime.as_secs();
self.0.mtimensec = mtime.subsec_nanos();
}
pub fn ctime(&self) -> time::Duration {
time::Duration::new(self.0.ctime, self.0.ctimensec)
}
pub fn set_ctime(&mut self, ctime: time::Duration) {
self.0.ctime = ctime.as_secs();
self.0.ctimensec = ctime.subsec_nanos();
}
pub fn mode(&self) -> FileMode {
FileMode(self.0.mode)
}
pub fn set_mode(&mut self, mode: FileMode) {
self.0.mode = mode.0;
}
pub fn set_nlink(&mut self, nlink: u32) {
self.0.nlink = nlink;
}
pub fn set_user_id(&mut self, user_id: u32) {
self.0.uid = user_id;
}
pub fn set_group_id(&mut self, group_id: u32) {
self.0.gid = group_id;
}
pub fn set_rdev(&mut self, rdev: u32) {
self.0.rdev = rdev;
}
pub fn set_blksize(&mut self, blksize: u32) {
self.0.blksize = blksize;
}
pub(crate) fn new_ref(raw: &fuse_kernel::fuse_attr) -> &Self {
let p = raw as *const fuse_kernel::fuse_attr as *const Self;
unsafe { &*p }
}
pub(crate) fn new_ref_mut(raw: &mut fuse_kernel::fuse_attr) -> &mut Self {
let p = raw as *mut fuse_kernel::fuse_attr as *mut Self;
unsafe { &mut *p }
}
}
impl fmt::Debug for NodeAttr {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("NodeAttr")
.field("node_id", &format_args!("{:?}", &self.node_id()))
.field("size", &self.0.size)
.field("blocks", &self.0.blocks)
.field("atime", &self.atime())
.field("mtime", &self.mtime())
.field("ctime", &self.ctime())
.field("mode", &format_args!("{:#o}", &self.0.mode))
.field("nlink", &self.0.nlink)
.field("uid", &self.0.uid)
.field("gid", &self.0.gid)
.field("rdev", &self.0.rdev)
.field("blksize", &self.0.blksize)
.finish()
}
}