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) } }