From 83e3409bd8fb9cec24bd353c24fdeb27473fefb5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 23 May 2024 14:49:23 +0300 Subject: [PATCH] Kernel/LibC: Update SYS_SEEK to return new offset and implement lseek --- kernel/include/kernel/OpenFileDescriptorSet.h | 2 +- kernel/kernel/OpenFileDescriptorSet.cpp | 4 ++-- kernel/kernel/Process.cpp | 3 +-- libc/unistd.cpp | 5 +++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/include/kernel/OpenFileDescriptorSet.h b/kernel/include/kernel/OpenFileDescriptorSet.h index 504f4b7f2f..993866577a 100644 --- a/kernel/include/kernel/OpenFileDescriptorSet.h +++ b/kernel/include/kernel/OpenFileDescriptorSet.h @@ -33,7 +33,7 @@ namespace Kernel BAN::ErrorOr fcntl(int fd, int cmd, int extra); - BAN::ErrorOr seek(int fd, off_t offset, int whence); + BAN::ErrorOr seek(int fd, off_t offset, int whence); BAN::ErrorOr tell(int) const; BAN::ErrorOr fstat(int fd, struct stat*) const; diff --git a/kernel/kernel/OpenFileDescriptorSet.cpp b/kernel/kernel/OpenFileDescriptorSet.cpp index f1502ac15f..bd09d0b030 100644 --- a/kernel/kernel/OpenFileDescriptorSet.cpp +++ b/kernel/kernel/OpenFileDescriptorSet.cpp @@ -207,7 +207,7 @@ namespace Kernel return BAN::Error::from_errno(ENOTSUP); } - BAN::ErrorOr OpenFileDescriptorSet::seek(int fd, off_t offset, int whence) + BAN::ErrorOr OpenFileDescriptorSet::seek(int fd, off_t offset, int whence) { TRY(validate_fd(fd)); @@ -233,7 +233,7 @@ namespace Kernel m_open_files[fd]->offset = new_offset; - return {}; + return new_offset; } BAN::ErrorOr OpenFileDescriptorSet::tell(int fd) const diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 7991bd40cd..359d040308 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -1136,8 +1136,7 @@ namespace Kernel BAN::ErrorOr Process::sys_seek(int fd, off_t offset, int whence) { LockGuard _(m_process_lock); - TRY(m_open_file_descriptors.seek(fd, offset, whence)); - return 0; + return TRY(m_open_file_descriptors.seek(fd, offset, whence)); } BAN::ErrorOr Process::sys_tell(int fd) diff --git a/libc/unistd.cpp b/libc/unistd.cpp index 508b825629..bec5435ee0 100644 --- a/libc/unistd.cpp +++ b/libc/unistd.cpp @@ -93,6 +93,11 @@ ssize_t pread(int fildes, void* buf, size_t nbyte, off_t offset) return syscall(SYS_PREAD, fildes, buf, nbyte, offset); } +off_t lseek(int fildes, off_t offset, int whence) +{ + return syscall(SYS_SEEK, fildes, offset, whence); +} + int dup(int fildes) { return syscall(SYS_DUP, fildes);