summaryrefslogtreecommitdiff
path: root/src/disk/data_block.rs
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-18 02:15:11 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-18 02:15:11 -0800
commitcd0163da154367f5437ae1423bc97c450d74adf7 (patch)
treec8f88dae8da14f9c2614170e48c5eedd279459f5 /src/disk/data_block.rs
parent95d8d84eef645b52d92fd3fb8fdea7aed1f6d474 (diff)
downloadmyfs-cd0163da154367f5437ae1423bc97c450d74adf7.tar.gz
myfs-cd0163da154367f5437ae1423bc97c450d74adf7.zip
I hate cache!
Diffstat (limited to 'src/disk/data_block.rs')
-rw-r--r--src/disk/data_block.rs89
1 files changed, 82 insertions, 7 deletions
diff --git a/src/disk/data_block.rs b/src/disk/data_block.rs
index 2160b91..9c8cc26 100644
--- a/src/disk/data_block.rs
+++ b/src/disk/data_block.rs
@@ -1,12 +1,54 @@
-pub trait Block: Default {}
+use crate::disk::inode::Inode;
+use libc::pathconf;
+
+pub trait Block: Default + Clone {}
+
+#[derive(Clone)]
+pub struct DataBlock(pub(crate) [u8; 4096]);
+
+impl Default for DataBlock {
+ fn default() -> Self {
+ Self([0; 4096])
+ }
+}
-#[derive(Default)]
-pub struct DataBlock([u8; 4096]);
impl Block for DataBlock {}
+#[derive(Clone)]
+pub struct InodeBlock {
+ pub(crate) inodes: [Inode; 16],
+}
+
+impl Default for InodeBlock {
+ fn default() -> Self {
+ Self {
+ inodes: [
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ Inode::empty(),
+ ],
+ }
+ }
+}
+
+impl Block for InodeBlock {}
+
const FULL_MAP: u32 = 0b111_111_111_111_111;
-#[derive(Default)]
+#[derive(Clone)]
pub struct DirectoryBlock {
entries: [[u8; 256]; 15],
inode_ids: [usize; 15],
@@ -14,6 +56,17 @@ pub struct DirectoryBlock {
reserved: [u8; 132],
}
+impl Default for DirectoryBlock {
+ fn default() -> Self {
+ Self {
+ entries: [[0; 256]; 15],
+ inode_ids: [0; 15],
+ occupancy_map: 0,
+ reserved: [0xFF; 132],
+ }
+ }
+}
+
impl Block for DirectoryBlock {}
impl DirectoryBlock {
@@ -42,11 +95,17 @@ impl DirectoryBlock {
}
}
-#[derive(Default)]
+#[derive(Clone)]
pub struct IndirectBlock {
pub entries: [u32; 1024],
}
+impl Default for IndirectBlock {
+ fn default() -> Self {
+ Self { entries: [0; 1024] }
+ }
+}
+
impl Block for IndirectBlock {}
impl IndirectBlock {
@@ -59,11 +118,19 @@ impl IndirectBlock {
}
}
-#[derive(Default)]
+#[derive(Clone)]
pub struct DoubleIndirectBlock {
pub indirect: [u32; 1024],
}
+impl Default for DoubleIndirectBlock {
+ fn default() -> Self {
+ Self {
+ indirect: [0; 1024],
+ }
+ }
+}
+
impl Block for DoubleIndirectBlock {}
impl DoubleIndirectBlock {
@@ -76,11 +143,19 @@ impl DoubleIndirectBlock {
}
}
-#[derive(Default)]
+#[derive(Clone)]
pub struct TripleIndirectBlock {
pub double_indirect: [u32; 1024],
}
+impl Default for TripleIndirectBlock {
+ fn default() -> Self {
+ Self {
+ double_indirect: [0; 1024],
+ }
+ }
+}
+
impl Block for TripleIndirectBlock {}
impl TripleIndirectBlock {