summaryrefslogtreecommitdiff
path: root/src/memory
diff options
context:
space:
mode:
Diffstat (limited to 'src/memory')
-rw-r--r--src/memory/cached_block.rs16
-rw-r--r--src/memory/cached_inode.rs10
2 files changed, 16 insertions, 10 deletions
diff --git a/src/memory/cached_block.rs b/src/memory/cached_block.rs
index 9e266ef..eb59a4b 100644
--- a/src/memory/cached_block.rs
+++ b/src/memory/cached_block.rs
@@ -2,6 +2,7 @@ use crate::block_device::{BlockDevice, BLOCK_SIZE};
use crate::disk::block::Block;
use crate::AyaFS;
use and_then_some::BoolExt;
+use log::debug;
use lru::LruCache;
use std::num::NonZeroUsize;
use std::sync::Arc;
@@ -46,11 +47,9 @@ impl<T: Block> BlockCache<T> {
pub(crate) fn load_block(&mut self, index: usize) -> bool {
if self.cache.contains(&index) == false {
- let block = T::default();
- let buffer = unsafe {
- std::slice::from_raw_parts_mut(&block as *const T as *mut u8, BLOCK_SIZE)
- };
- self.device.read(index, buffer);
+ let mut buffer = [0u8; BLOCK_SIZE];
+ self.device.read(index, &mut buffer);
+ let block: T = unsafe { std::mem::transmute_copy(&buffer) };
let cached_block = CachedBlock {
block,
index,
@@ -77,8 +76,11 @@ impl<T: Block> BlockCache<T> {
/// 从 LRU cache 里获取一个 block 的可变引用, 如果没有在 cache 中会加载.
pub(crate) fn get_block_mut<U: Block>(&mut self, index: usize) -> Option<&mut CachedBlock<U>> {
- self.load_block(index)
- .and_then(|| self.cache.get_mut(&index).map(convert_mut::<T, U>))
+ debug!("Blockcache get block mut");
+ self.load_block(index).and_then(|| {
+ debug!("block loaded");
+ self.cache.get_mut(&index).map(convert_mut::<T, U>)
+ })
}
/// 从 LRU cache 中读取一个 block 的引用, *不会* 影响 LRU cache 的结构, 如果没有在 cache 中不会加载.
diff --git a/src/memory/cached_inode.rs b/src/memory/cached_inode.rs
index b81bd2e..dd5e5c3 100644
--- a/src/memory/cached_inode.rs
+++ b/src/memory/cached_inode.rs
@@ -1,7 +1,8 @@
-use crate::disk::block::{Block, InodeBlock};
+use crate::disk::block::InodeBlock;
use crate::disk::inode::{Inode, InodeMode, INODE_SIZE};
-use crate::AyaFS;
+use crate::{utils, AyaFS};
use and_then_some::BoolExt;
+use log::debug;
impl AyaFS {
pub(crate) fn create_inode(
@@ -12,20 +13,23 @@ impl AyaFS {
gid: u32,
flags: u32,
) -> Option<usize> {
+ debug!("create inode");
self.inode_bitmap.allocate().map(|inode_index| {
+ debug!("creating inode");
self.get_inode_mut(inode_index).map(|inode| {
*inode = Inode::make_inode(
permissions,
mode,
uid,
gid,
- Self::time_now(),
+ utils::time_now(),
flags,
0,
0,
0,
);
});
+ debug!("inode created");
inode_index
})
}