decthings_api/client/rpc/fs/
request.rs

1use serde::Serialize;
2
3fn serialize_base64<T: AsRef<[u8]>, S: serde::Serializer>(t: &T, s: S) -> Result<S::Ok, S::Error> {
4    use base64::Engine;
5    s.serialize_str(&base64::engine::general_purpose::STANDARD.encode(t.as_ref()))
6}
7
8#[derive(Debug, Clone, Serialize)]
9#[serde(rename_all = "camelCase")]
10pub struct LookupParams<'a, T: AsRef<[u8]>> {
11    /// The model's id.
12    pub model_id: &'a str,
13    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub snapshot_id: Option<&'a str>,
16    /// Inode number of the parent directory.
17    pub parent: u64,
18    /// Filename within the parent directory.
19    #[serde(serialize_with = "serialize_base64")]
20    pub name: T,
21}
22
23#[derive(Debug, Clone, Serialize)]
24#[serde(rename_all = "camelCase")]
25pub struct GetattrParams<'a> {
26    /// The model's id.
27    pub model_id: &'a str,
28    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub snapshot_id: Option<&'a str>,
31    /// Inode number of file.
32    pub inode: u64,
33}
34
35#[derive(Debug, Clone, Serialize)]
36#[serde(rename_all = "camelCase")]
37pub struct SetTime {
38    pub sec: i64,
39    pub nsec: i64,
40}
41
42#[derive(Debug, Clone, Serialize)]
43#[serde(rename_all = "camelCase")]
44pub struct SetattrParams<'a> {
45    /// The model's id.
46    pub model_id: &'a str,
47    /// Inode number of file.
48    pub inode: u64,
49    /// If specified, file mode to set.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub mode: Option<u32>,
52    /// If specified the file will be resized to this size.
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub size: Option<u64>,
55    /// If specified, set access time.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub atime: Option<SetTime>,
58    /// If specified, set modified time.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub mtime: Option<SetTime>,
61}
62
63#[derive(Debug, Clone, Serialize)]
64#[serde(rename_all = "camelCase")]
65pub struct MknodParams<'a, T: AsRef<[u8]>> {
66    /// The model's id.
67    pub model_id: &'a str,
68    /// Inode number of the parent directory.
69    pub parent: u64,
70    /// Filename within the parent directory.
71    #[serde(serialize_with = "serialize_base64")]
72    pub name: T,
73    /// File mode.
74    pub mode: u32,
75    /// Device number (for character or block device files).
76    pub dev: u64,
77}
78
79#[derive(Debug, Clone, Serialize)]
80#[serde(rename_all = "camelCase")]
81pub struct ReadParams<'a> {
82    /// The model's id.
83    pub model_id: &'a str,
84    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub snapshot_id: Option<&'a str>,
87    /// Inode number of file.
88    pub inode: u64,
89    /// Where in the file to start reading.
90    pub offset: u64,
91    /// Number of bytes to read.
92    pub count: u64,
93}
94
95#[derive(Debug, Clone, Serialize)]
96#[serde(rename_all = "camelCase")]
97pub struct WriteParams<'a, D: AsRef<[u8]>> {
98    /// The model's id.
99    pub model_id: &'a str,
100    /// Inode number of file.
101    pub inode: u64,
102    #[serde(skip_serializing)]
103    pub data: D,
104    /// Where in the file to start writing.
105    pub offset: u64,
106    /// If true, the file will be truncate to zero length before writing.
107    #[serde(skip_serializing_if = "Option::is_none")]
108    pub truncate: Option<bool>,
109}
110
111#[derive(Debug, Clone, Serialize)]
112#[serde(rename_all = "camelCase")]
113pub struct SymlinkParams<'a, T1: AsRef<[u8]>, T2: AsRef<[u8]>> {
114    /// The model's id.
115    pub model_id: &'a str,
116    /// Inode number of the parent directory.
117    pub parent: u64,
118    /// Filename within the parent directory.
119    #[serde(serialize_with = "serialize_base64")]
120    pub name: T1,
121    /// Target name.
122    #[serde(serialize_with = "serialize_base64")]
123    pub link: T2,
124}
125
126#[derive(Debug, Clone, Serialize)]
127#[serde(rename_all = "camelCase")]
128pub struct ReadlinkParams<'a> {
129    /// The model's id.
130    pub model_id: &'a str,
131    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub snapshot_id: Option<&'a str>,
134    /// Inode number of file.
135    pub inode: u64,
136}
137
138#[derive(Debug, Clone, Serialize)]
139#[serde(rename_all = "camelCase")]
140pub struct MkdirParams<'a, T: AsRef<[u8]>> {
141    /// The model's id.
142    pub model_id: &'a str,
143    /// Inode number of the parent directory.
144    pub parent: u64,
145    /// Filename within the parent directory.
146    #[serde(serialize_with = "serialize_base64")]
147    pub name: T,
148    /// File mode.
149    pub mode: u32,
150}
151
152#[derive(Debug, Clone, Serialize)]
153#[serde(rename_all = "camelCase")]
154pub struct UnlinkParams<'a, T: AsRef<[u8]>> {
155    /// The model's id.
156    pub model_id: &'a str,
157    /// Inode number of the parent directory.
158    pub parent: u64,
159    /// Filename within the parent directory.
160    #[serde(serialize_with = "serialize_base64")]
161    pub name: T,
162}
163
164#[derive(Debug, Clone, Serialize)]
165#[serde(rename_all = "camelCase")]
166pub struct RmdirParams<'a, T: AsRef<[u8]>> {
167    /// The model's id.
168    pub model_id: &'a str,
169    /// Inode number of the parent directory.
170    pub parent: u64,
171    /// Filename within the parent directory.
172    #[serde(serialize_with = "serialize_base64")]
173    pub name: T,
174}
175
176#[derive(Debug, Clone, Serialize)]
177#[serde(rename_all = "camelCase")]
178pub struct RenameParams<'a, T1: AsRef<[u8]>, T2: AsRef<[u8]>> {
179    /// The model's id.
180    pub model_id: &'a str,
181    /// Inode number of the parent directory.
182    pub parent: u64,
183    /// Filename within the parent directory.
184    #[serde(serialize_with = "serialize_base64")]
185    pub name: T1,
186    /// Inode number of the new parent directory.
187    pub newparent: u64,
188    /// Filename within the new parent directory.
189    #[serde(serialize_with = "serialize_base64")]
190    pub newname: T2,
191    /// Optional rename flags.
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub flags: Option<u32>,
194}
195
196#[derive(Debug, Clone, Serialize)]
197#[serde(rename_all = "camelCase")]
198pub struct LinkParams<'a, T: AsRef<[u8]>> {
199    /// The model's id.
200    pub model_id: &'a str,
201    /// Inode number of file.
202    pub inode: u64,
203    /// Inode number of the new parent directory.
204    pub newparent: u64,
205    /// Filename within the new parent directory.
206    #[serde(serialize_with = "serialize_base64")]
207    pub newname: T,
208}
209
210#[derive(Debug, Clone, Serialize)]
211#[serde(rename_all = "camelCase")]
212pub struct ReaddirParams<'a> {
213    /// The model's id.
214    pub model_id: &'a str,
215    /// If provided, the filesystem of the snapshot will be used. Otherwise, the filesystem of the model will be used.
216    #[serde(skip_serializing_if = "Option::is_none")]
217    pub snapshot_id: Option<&'a str>,
218    /// Inode number of directory.
219    pub inode: u64,
220}
221
222#[derive(Debug, Clone, Serialize)]
223#[serde(rename_all = "camelCase")]
224pub struct RmdirAllParams<'a, T: AsRef<[u8]>> {
225    /// The model's id.
226    pub model_id: &'a str,
227    /// Inode number of the parent directory.
228    pub parent: u64,
229    /// Filename within the parent directory.
230    #[serde(serialize_with = "serialize_base64")]
231    pub name: T,
232}
233
234#[derive(Debug, Clone, Serialize)]
235#[serde(rename_all = "camelCase")]
236pub struct CopyParams<'a, T: AsRef<[u8]>> {
237    /// The model's id.
238    pub model_id: &'a str,
239    /// Inode number of file.
240    pub inode: u64,
241    /// Inode number of the new parent directory.
242    pub newparent: u64,
243    /// Filename within the new parent directory.
244    #[serde(serialize_with = "serialize_base64")]
245    pub newname: T,
246}