实现fat文件系统的truncate方法 (#428)

This commit is contained in:
MemoryShore 2023-11-08 21:42:51 +08:00 committed by GitHub
parent df2f5051ac
commit 04babc3fab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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;

View File

@ -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;
@ -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;