use serde::{Deserialize, Serialize};
pub const FS_CHUNK_SIZE: usize = 3 * 1024 * 1024;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FsOp {
RealPath {
path: String,
},
Stat {
path: String,
follow_symlink: bool,
},
SetStat {
path: String,
follow_symlink: bool,
attrs: FsSetAttrs,
},
List {
path: String,
},
ReadLink {
path: String,
},
Symlink {
target: String,
link_path: String,
},
Mkdir {
path: String,
#[serde(default)]
mode: Option<u32>,
},
Remove {
path: String,
},
RemoveDir {
path: String,
recursive: bool,
},
Copy {
src: String,
dst: String,
},
Rename {
src: String,
dst: String,
},
OpenFile {
path: String,
options: FsOpenOptions,
},
OpenDir {
path: String,
},
CloseHandle {
handle: u64,
},
Read {
handle: u64,
offset: u64,
len: Option<u64>,
},
Write {
handle: u64,
offset: u64,
len: Option<u64>,
},
ReadDir {
handle: u64,
limit: Option<u32>,
},
FStat {
handle: u64,
},
FSetStat {
handle: u64,
attrs: FsSetAttrs,
},
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FsSetAttrs {
pub mode: Option<u32>,
pub uid: Option<u32>,
pub gid: Option<u32>,
pub size: Option<u64>,
pub atime: Option<i64>,
pub mtime: Option<i64>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FsOpenOptions {
pub read: bool,
pub write: bool,
pub append: bool,
pub create: bool,
pub truncate: bool,
pub create_new: bool,
pub mode: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FsRequest {
pub op: FsOp,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FsEntryInfo {
pub path: String,
pub kind: String,
pub size: u64,
pub mode: u32,
pub modified: Option<i64>,
pub uid: u32,
pub gid: u32,
pub atime: Option<i64>,
pub mtime: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum FsResponseData {
Stat(FsEntryInfo),
List(Vec<FsEntryInfo>),
Handle(u64),
Path(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FsResponse {
pub ok: bool,
#[serde(default)]
pub error: Option<String>,
#[serde(default)]
pub data: Option<FsResponseData>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FsData {
#[serde(with = "serde_bytes")]
pub data: Vec<u8>,
}