summaryrefslogtreecommitdiff
path: root/ayafs-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'ayafs-core/src')
-rw-r--r--ayafs-core/src/block_device/disk.rs2
-rw-r--r--ayafs-core/src/filesystem/trait_impl.rs26
-rw-r--r--ayafs-core/src/memory/cached_block.rs3
3 files changed, 18 insertions, 13 deletions
diff --git a/ayafs-core/src/block_device/disk.rs b/ayafs-core/src/block_device/disk.rs
index cc9552c..745a0b2 100644
--- a/ayafs-core/src/block_device/disk.rs
+++ b/ayafs-core/src/block_device/disk.rs
@@ -27,7 +27,6 @@ impl Disk {
impl BlockDevice for Disk {
fn read(&self, block_id: usize, buffer: &mut [u8]) {
- assert_eq!(buffer.len(), BLOCK_SIZE);
let mut device = self.device.borrow_mut();
device
.seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64))
@@ -39,7 +38,6 @@ impl BlockDevice for Disk {
}
fn write(&self, block_id: usize, buffer: &[u8]) {
- assert_eq!(buffer.len(), BLOCK_SIZE);
let mut device = self.device.borrow_mut();
device
.seek(SeekFrom::Start((block_id * BLOCK_SIZE) as u64))
diff --git a/ayafs-core/src/filesystem/trait_impl.rs b/ayafs-core/src/filesystem/trait_impl.rs
index 48afac3..922486d 100644
--- a/ayafs-core/src/filesystem/trait_impl.rs
+++ b/ayafs-core/src/filesystem/trait_impl.rs
@@ -6,11 +6,7 @@ use crate::utils::{from_filetype, from_systime, time_now, to_fileattr, to_filety
use crate::{AyaFS, TTL};
use fuser::TimeOrNow::{Now, SpecificTime};
use fuser::{FileType, Filesystem, KernelConfig, ReplyAttr, ReplyData, ReplyDirectory, ReplyEmpty, ReplyEntry, ReplyOpen, ReplyWrite, Request, TimeOrNow, ReplyStatfs, FileAttr, ReplyCreate};
-use libc::{
- c_int, EACCES, EBADF, EEXIST, EINVAL, EIO, EISDIR, ENAMETOOLONG, ENOENT, ENOSPC, ENOTDIR,
- ENOTEMPTY, EPERM, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY, RENAME_EXCHANGE,
- RENAME_NOREPLACE, R_OK, S_ISGID, S_ISUID, S_IXGRP, S_IXOTH, S_IXUSR, W_OK,
-};
+use libc::{c_int, EACCES, EBADF, EEXIST, EINVAL, EIO, EISDIR, ENAMETOOLONG, ENOENT, ENOSPC, ENOTDIR, ENOTEMPTY, EPERM, O_ACCMODE, O_RDONLY, O_RDWR, O_WRONLY, RENAME_EXCHANGE, RENAME_NOREPLACE, R_OK, S_ISGID, S_ISUID, S_IXGRP, S_IXOTH, S_IXUSR, W_OK, EFAULT};
use log::{debug, trace};
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
@@ -167,7 +163,10 @@ impl Filesystem for AyaFS {
let mut inode = inode.clone();
let (inode_index, _read, write) =
self.file_handle_map.get(&file_handle).unwrap();
- assert_eq!(ino as usize, *inode_index);
+ if *inode_index != ino as usize {
+ reply.error(EFAULT);
+ return;
+ }
if !write {
reply.error(EACCES);
} else {
@@ -1114,7 +1113,10 @@ impl Filesystem for AyaFS {
.get(&fh)
.cloned()
.unwrap();
- assert_eq!(inode_num, ino as usize);
+ if inode_num != ino as usize {
+ reply.error(EFAULT);
+ return;
+ }
if let Some(inode) = self.get_inode(ino as usize) {
if inode.is_dir() {
reply.error(EISDIR);
@@ -1194,7 +1196,10 @@ impl Filesystem for AyaFS {
.get(&fh)
.cloned()
.unwrap();
- assert_eq!(inode_num, ino as usize);
+ if inode_num != ino as usize {
+ reply.error(EFAULT);
+ return;
+ }
if let Some(inode) = self.get_inode(inode_num) {
if inode.is_dir() {
reply.error(EISDIR);
@@ -1336,7 +1341,10 @@ impl Filesystem for AyaFS {
offset: i64,
mut reply: ReplyDirectory,
) {
- assert_eq!(self.file_handle_map.get(&fh).unwrap().0, ino as usize);
+ if self.file_handle_map.get(&fh).unwrap().0 != ino as usize {
+ reply.error(EFAULT);
+ return;
+ }
if let Some(inode) = self.get_inode(ino as usize) {
if !inode.is_dir() {
reply.error(ENOTDIR);
diff --git a/ayafs-core/src/memory/cached_block.rs b/ayafs-core/src/memory/cached_block.rs
index ae0f2a9..e4bcb2a 100644
--- a/ayafs-core/src/memory/cached_block.rs
+++ b/ayafs-core/src/memory/cached_block.rs
@@ -157,8 +157,7 @@ impl<T: Block> BlockCache<T> {
if self.cache.contains(&block.index) {
let mut data_block = convert::<U, T>(&block).clone();
data_block.dirty = true; // TODO 需要把显式写回的都标记为 dirty 吗
- let (entry, _value) = self.cache.push(block.index, data_block).unwrap();
- assert_eq!(entry, block.index);
+ self.cache.push(block.index, data_block).unwrap();
trace!("update_block(global_block_id: {})", block.index + self.global_offset);
true
} else {