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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
use base64::Engine;
use serde::{Serialize, Serializer};

fn serialize_base64<T: AsRef<[u8]>, S: Serializer>(t: &T, s: S) -> Result<S::Ok, S::Error> {
    s.serialize_str(&base64::engine::general_purpose::STANDARD.encode(t.as_ref()))
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LookupParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GetattrParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
    /// Inode number of file.
    pub inode: u64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetTime {
    pub sec: i64,
    pub nsec: i64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SetattrParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of file.
    pub inode: u64,
    /// If specified, file mode to set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mode: Option<u32>,
    /// If specified the file will be resized to this size.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub size: Option<u64>,
    /// If specified, set access time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub atime: Option<SetTime>,
    /// If specified, set modified time.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mtime: Option<SetTime>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MknodParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
    /// File mode.
    pub mode: u32,
    /// Device number (for character or block device files).
    pub dev: u64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReadParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
    /// Inode number of file.
    pub inode: u64,
    /// Where in the file to start reading.
    pub offset: u64,
    /// Number of bytes to read.
    pub count: u64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WriteParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of file.
    pub inode: u64,
    #[serde(skip_serializing)]
    pub data: &'a [u8],
    /// Where in the file to start writing.
    pub offset: u64,
    /// If true, the file will be truncate to zero length before writing.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub truncate: Option<bool>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SymlinkParams<'a, T1: AsRef<[u8]>, T2: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T1,
    /// Target name.
    #[serde(serialize_with = "serialize_base64")]
    pub link: T2,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReadlinkParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
    /// Inode number of file.
    pub inode: u64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct MkdirParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
    /// File mode.
    pub mode: u32,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct UnlinkParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RmdirParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RenameParams<'a, T1: AsRef<[u8]>, T2: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T1,
    /// Inode number of the new parent directory.
    pub newparent: u64,
    /// Filename within the new parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub newname: T2,
    /// Optional rename flags.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub flags: Option<u32>,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LinkParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of file.
    pub inode: u64,
    /// Inode number of the new parent directory.
    pub newparent: u64,
    /// Filename within the new parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub newname: T,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ReaddirParams<'a> {
    /// The model's id.
    pub model_id: &'a str,
    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_id: Option<&'a str>,
    /// Inode number of directory.
    pub inode: u64,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RmdirAllParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of the parent directory.
    pub parent: u64,
    /// Filename within the parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub name: T,
}

#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CopyParams<'a, T: AsRef<[u8]>> {
    /// The model's id.
    pub model_id: &'a str,
    /// Inode number of file.
    pub inode: u64,
    /// Inode number of the new parent directory.
    pub newparent: u64,
    /// Filename within the new parent directory.
    #[serde(serialize_with = "serialize_base64")]
    pub newname: T,
}