blob: 2ea25e7e2d4313aafa579a25edb6ca9113c4f018 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)
}
}
|