Skip to content

Commit

Permalink
实现fat文件系统的truncate方法 (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryShore authored Nov 8, 2023
1 parent df2f505 commit 04babc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kernel/src/filesystem/fat/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,17 @@ impl IndexNode for LockedFATInode {
}
}

fn truncate(&self, len: usize) -> Result<(), SystemError> {
let guard: SpinLockGuard<FATInode> = self.0.lock();
let old_size = guard.metadata.size as usize;
if len < old_size {
drop(guard);
self.resize(len)
} else {
Ok(())
}
}

fn list(&self) -> Result<Vec<String>, SystemError> {
let mut guard: SpinLockGuard<FATInode> = self.0.lock();
let fatent: &FATDirEntry = &guard.inode_type;
Expand Down
7 changes: 7 additions & 0 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ pub const SYS_IOCTL: usize = 16;
#[allow(dead_code)]
pub const SYS_WRITEV: usize = 20;

pub const SYS_MADVISE: usize = 28;

pub const SYS_DUP: usize = 32;
pub const SYS_DUP2: usize = 33;

Expand Down Expand Up @@ -1128,6 +1130,11 @@ impl Syscall {
Ok(0)
}

SYS_MADVISE => {
kwarn!("SYS_MADVISE has not yet been implemented");
Ok(0)
}

_ => panic!("Unsupported syscall ID: {}", syscall_num),
};
return r;
Expand Down

0 comments on commit 04babc3

Please sign in to comment.