From 886df6daf6bb6b922276157dba1cc099e897a9ea Mon Sep 17 00:00:00 2001 From: Chuyan Zhang Date: Sat, 18 Nov 2023 02:43:01 -0800 Subject: Major refactor of file hierarchy --- src/utils/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/utils/mod.rs (limited to 'src/utils') 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) + } +} -- cgit v1.2.3-70-g09d2