summaryrefslogtreecommitdiff
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2023-11-18 02:43:01 -0800
committerChuyan Zhang <me@zcy.moe>2023-11-18 02:43:01 -0800
commit886df6daf6bb6b922276157dba1cc099e897a9ea (patch)
tree300b135bddd8ce8631dfd3ec45a9bf3d021a24df /src/utils/mod.rs
parentcd0163da154367f5437ae1423bc97c450d74adf7 (diff)
downloadmyfs-886df6daf6bb6b922276157dba1cc099e897a9ea.tar.gz
myfs-886df6daf6bb6b922276157dba1cc099e897a9ea.zip
Major refactor of file hierarchy
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
new file mode 100644
index 0000000..2ea25e7
--- /dev/null
+++ b/src/utils/mod.rs
@@ -0,0 +1,20 @@
+use crate::disk::inode::INODE_SIZE;
+use crate::{AyaFS, INODE_PER_BLOCK};
+use std::time::{SystemTime, UNIX_EPOCH};
+
+impl AyaFS {
+ pub(crate) fn time_now() -> u32 {
+ SystemTime::now()
+ .duration_since(UNIX_EPOCH)
+ .expect("How can current time be earlier than UNIX_EPOCH?")
+ .as_secs() as u32
+ }
+
+ /// 输入 inode 编号, 返回它对应的 block number 和 block 内 offset
+ pub(crate) fn locate_inode(&self, inode_index: usize) -> (usize, usize) {
+ let block_number =
+ inode_index / INODE_PER_BLOCK + 1 + self.inode_bitmap.length + self.data_bitmap.length;
+ let block_offset = inode_index % INODE_PER_BLOCK * INODE_SIZE;
+ (block_number, block_offset)
+ }
+}