diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/mod.rs | 20 |
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) + } +} |