1use alloc::{collections::BTreeMap, string::String};
2
3use crate::storage::BlockStorage;
4use crate::types::InodeId;
5
6#[derive(Clone, Copy, Default)]
7pub struct Metadata {
8 pub size: u64,
9 pub created: u64,
10 pub modified: u64,
11 pub permissions: u16,
12 pub is_dir: bool,
13}
14
15pub enum FileContent {
17 File(BlockStorage),
18 Dir(BTreeMap<String, InodeId>),
19}
20
21pub struct Inode {
23 pub id: InodeId,
24 pub metadata: Metadata,
25 pub content: FileContent,
26}
27
28impl Inode {
29 pub fn new_file(id: InodeId) -> Self {
30 Self {
31 id,
32 metadata: Metadata {
33 size: 0,
34 created: 0,
35 modified: 0,
36 permissions: 0o644,
37 is_dir: false,
38 },
39 content: FileContent::File(BlockStorage::new()),
40 }
41 }
42
43 pub fn new_dir(id: InodeId) -> Self {
44 Self {
45 id,
46 metadata: Metadata {
47 size: 0,
48 created: 0,
49 modified: 0,
50 permissions: 0o755,
51 is_dir: true,
52 },
53 content: FileContent::Dir(BTreeMap::new()),
54 }
55 }
56}