From 393b7a8ada2a41db102a419559f3fdaa5b3ec17f Mon Sep 17 00:00:00 2001 From: Rafal Mielniczuk Date: Tue, 24 Oct 2023 11:34:47 +0100 Subject: [PATCH] Add truncate syscall --- cykusz-rs/src/kernel/syscall/mod.rs | 1 + cykusz-rs/src/kernel/syscall/sys.rs | 13 +++++++++++-- cykusz-rs/src/kernel/task/vm.rs | 8 ++++---- disk_scripts/make_disk.sh | 2 +- syscall-defs/src/lib.rs | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cykusz-rs/src/kernel/syscall/mod.rs b/cykusz-rs/src/kernel/syscall/mod.rs index 23da1d8f..b9e1d93a 100644 --- a/cykusz-rs/src/kernel/syscall/mod.rs +++ b/cykusz-rs/src/kernel/syscall/mod.rs @@ -87,6 +87,7 @@ pub fn syscall_handler(num: u64, a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) SYS_TICKSNS => sys::sys_ticksns(), SYS_GETPPID => sys::sys_getppid(), SYS_GETPGID => sys::sys_getpgid(a), + SYS_TRUNCATE => sys::sys_truncate(a, b), a => { logln!("NO SYS????? {}", a); Err(SyscallError::ENOSYS) diff --git a/cykusz-rs/src/kernel/syscall/sys.rs b/cykusz-rs/src/kernel/syscall/sys.rs index 9a0791b4..1f8a4226 100644 --- a/cykusz-rs/src/kernel/syscall/sys.rs +++ b/cykusz-rs/src/kernel/syscall/sys.rs @@ -460,6 +460,8 @@ pub fn sys_rmdir(path: u64, path_len: u64) -> SyscallResult { } pub fn sys_unlink(at: u64, path: u64, path_len: u64, flags: u64) -> SyscallResult { + let path = Path::new(make_str(path, path_len)); + logln4!("sys_unlink: {}", path.str()); if flags != 0 { return Err(SyscallError::EINVAL); } @@ -471,9 +473,7 @@ pub fn sys_unlink(at: u64, path: u64, path_len: u64, flags: u64) -> SyscallResul return Err(SyscallError::EBADFD); } - let path = Path::new(make_str(path, path_len)); - logln!("sys_unlink: {}", path.str()); let (_, name) = path.containing_dir(); @@ -1103,6 +1103,15 @@ pub fn sys_dup2(fd: u64, new_fd: u64, flags: u64) -> SyscallResult { .duplicate_at(fd as usize, new_fd as usize, flags) } +pub fn sys_truncate(fd: u64, size: u64) -> SyscallResult { + logln4!("truncate {} to size {}", fd, size); + let task = current_task_ref(); + + task.filetable().get_handle(fd as usize).ok_or(SyscallError::EBADFD)?.inode.inode().truncate(size as usize).map(|_r| { + Ok(0) + })? +} + pub fn sys_futex_wake(uaddr: u64) -> SyscallResult { let uaddr = VirtAddr(uaddr as usize); diff --git a/cykusz-rs/src/kernel/task/vm.rs b/cykusz-rs/src/kernel/task/vm.rs index 1efbfbbe..d4299513 100644 --- a/cykusz-rs/src/kernel/task/vm.rs +++ b/cykusz-rs/src/kernel/task/vm.rs @@ -812,16 +812,16 @@ impl VMData { fn log_vm(&self) { for e in self.maps.iter() { - if let Some(_f) = &e.mmaped_file { + if let Some(f) = &e.mmaped_file { logln_disabled!( "{} {}: {:?}, {:?} [ {} {:#x} {:#x} ]", e.start, e.end, e.prot, e.flags, - _f.file.full_path(), - _f.starting_offset, - _f.len, + f.file.full_path(), + f.starting_offset, + f.len, ); } else { logln_disabled!("{} {}: {:?}, {:?}", e.start, e.end, e.prot, e.flags,); diff --git a/disk_scripts/make_disk.sh b/disk_scripts/make_disk.sh index 8c6c8b99..58908156 100755 --- a/disk_scripts/make_disk.sh +++ b/disk_scripts/make_disk.sh @@ -7,7 +7,7 @@ chown $1:$1 disk.img parted disk.img mktable msdos -s parted disk.img mkpart primary ext2 2048s 64MiB -parted -- disk.img mkpart primary ext2 64Mib 3Gib # 112MB +parted -- disk.img mkpart primary ext2 64Mib 3GiB # 112MB parted -- disk.img mkpart primary ext2 3GiB 3.5Gib # 64 parted disk.img set 1 boot on diff --git a/syscall-defs/src/lib.rs b/syscall-defs/src/lib.rs index 101c26c4..8c45fda5 100644 --- a/syscall-defs/src/lib.rs +++ b/syscall-defs/src/lib.rs @@ -86,6 +86,7 @@ pub const SYS_TICKSNS: usize = 58; pub const SYS_GETPPID: usize = 59; pub const SYS_GETPGID: usize = 60; +pub const SYS_TRUNCATE: usize = 61; #[derive(Copy, Clone, PartialEq, Debug)] #[repr(u64)]