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
use super::api::*;
use super::dir::Directory;
use super::file::RegularFile;
use super::fixed::FixedFile;
use super::symlink::SymLink;
use ate::prelude::*;
use fxhash::FxHashMap;
use serde::*;
pub const PAGES_PER_BUNDLE: usize = 1024;
pub const PAGE_SIZE: usize = 131072;
pub const WEB_CONFIG_ID: u64 = 0xb709d79e5cf6dd64u64;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Page {
pub buf: Vec<u8>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PageBundle {
pub pages: Vec<Option<PrimaryKey>>,
}
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct Dentry {
pub parent: Option<u64>,
pub name: String,
pub mode: u32,
pub uid: u32,
pub gid: u32,
pub xattr: FxHashMap<String, String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Inode {
pub kind: FileKind,
pub dentry: Dentry,
pub size: u64,
pub bundles: Vec<Option<PrimaryKey>>,
pub children: DaoVec<Inode>,
pub link: Option<String>,
pub xattr: DaoMap<String, String>,
}
impl Inode {
pub fn new(name: String, mode: u32, uid: u32, gid: u32, kind: FileKind) -> Inode {
Inode {
kind,
dentry: Dentry {
name,
mode,
parent: None,
uid,
gid,
xattr: FxHashMap::default(),
},
size: 0,
bundles: Vec::default(),
children: DaoVec::new(),
link: None,
xattr: DaoMap::default(),
}
}
pub async fn as_file_spec(ino: u64, created: u64, updated: u64, dao: Dao<Inode>) -> FileSpec {
match dao.kind {
FileKind::Directory => FileSpec::Directory(Directory::new(dao, created, updated)),
FileKind::RegularFile => {
FileSpec::RegularFile(RegularFile::new(dao, created, updated).await)
}
FileKind::SymLink => FileSpec::SymLink(SymLink::new(dao, created, updated)),
FileKind::FixedFile => FileSpec::FixedFile(
FixedFile::new(ino, dao.dentry.name.clone(), FileKind::RegularFile)
.created(created)
.updated(updated),
),
}
}
pub async fn as_file_spec_mut(
ino: u64,
created: u64,
updated: u64,
dao: DaoMut<Inode>,
) -> FileSpec {
match dao.kind {
FileKind::Directory => FileSpec::Directory(Directory::new_mut(dao, created, updated)),
FileKind::RegularFile => {
FileSpec::RegularFile(RegularFile::new_mut(dao, created, updated).await)
}
FileKind::SymLink => FileSpec::SymLink(SymLink::new_mut(dao, created, updated)),
FileKind::FixedFile => FileSpec::FixedFile(
FixedFile::new(ino, dao.dentry.name.clone(), FileKind::RegularFile)
.created(created)
.updated(updated),
),
}
}
}