russh_sftp/
extensions.rs

1use crate::{error::Error, ser};
2
3pub const LIMITS: &str = "limits@openssh.com";
4pub const HARDLINK: &str = "hardlink@openssh.com";
5pub const FSYNC: &str = "fsync@openssh.com";
6pub const STATVFS: &str = "statvfs@openssh.com";
7
8macro_rules! impl_try_into_bytes {
9    ($struct:ty) => {
10        impl TryInto<Vec<u8>> for $struct {
11            type Error = Error;
12
13            fn try_into(self) -> Result<Vec<u8>, Self::Error> {
14                ser::to_bytes(&self).map(|b| b.to_vec())
15            }
16        }
17    };
18}
19
20#[derive(Debug, Serialize, Deserialize)]
21pub struct LimitsExtension {
22    pub max_packet_len: u64,
23    pub max_read_len: u64,
24    pub max_write_len: u64,
25    pub max_open_handles: u64,
26}
27
28#[derive(Debug, Serialize, Deserialize)]
29pub struct HardlinkExtension {
30    pub oldpath: String,
31    pub newpath: String,
32}
33
34impl_try_into_bytes!(HardlinkExtension);
35
36#[derive(Debug, Serialize, Deserialize)]
37pub struct FsyncExtension {
38    pub handle: String,
39}
40
41impl_try_into_bytes!(FsyncExtension);
42
43#[derive(Debug, Serialize, Deserialize)]
44pub struct StatvfsExtension {
45    pub path: String,
46}
47
48impl_try_into_bytes!(StatvfsExtension);
49
50#[derive(Debug, Serialize, Deserialize)]
51pub struct Statvfs {
52    /// The file system block size
53    pub block_size: u64,
54    /// The fundamental file system block size
55    pub fragment_size: u64,
56    /// The number of blocks.
57    ///
58    /// Units are in units of `fragment_size`
59    pub blocks: u64,
60    /// The number of free blocks in the file system
61    pub blocks_free: u64,
62    /// The number of free blocks for unprivileged users
63    pub blocks_avail: u64,
64    /// The total number of file inodes
65    pub inodes: u64,
66    /// The number of free file inodes
67    pub inodes_free: u64,
68    /// The number of free file inodes for unprivileged users
69    pub inodes_avail: u64,
70    /// The file system id
71    pub fs_id: u64,
72    /// The mount flags
73    pub flags: u64,
74    /// The maximum filename length
75    pub name_max: u64,
76}