From ff990b570d8ca8add9b101e7bec7582654a84eaf Mon Sep 17 00:00:00 2001 From: Marek Ledworowski Date: Tue, 11 Nov 2025 23:33:54 +0100 Subject: [PATCH] stubbed lseek --- src/core/file_sys/hostio/host_io_win32.h | 6 ++--- .../file_sys/hostio/src/host_io_virtual.cpp | 9 ++++++++ .../file_sys/hostio/src/host_io_win32.cpp | 6 ++--- .../quasifs/quasifs_inode_quasi_directory.h | 2 +- .../src/quasifs_inode_quasi_directory.cpp | 22 +++++++++++++++++-- .../src/quasifs_inode_quasi_directory_pfs.cpp | 5 +++-- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/core/file_sys/hostio/host_io_win32.h b/src/core/file_sys/hostio/host_io_win32.h index b8ca70cc5..cf494605e 100644 --- a/src/core/file_sys/hostio/host_io_win32.h +++ b/src/core/file_sys/hostio/host_io_win32.h @@ -85,19 +85,19 @@ public: s32 Flush(const s32 fd) override; s32 FSync(const s32 fd) override; - s64 LSeek(const s32 fd, u64 offset, s32 whence) override; + s64 LSeek(const s32 fd, s64 offset, s32 whence) override; s64 Tell(const s32 fd) override; s32 Truncate(const fs::path& path, u64 size) override; s32 FTruncate(const s32 fd, u64 size) override; s64 Read(const s32 fd, void* buf, u64 count) override; - s64 PRead(const s32 fd, void* buf, u64 count, u64 offset) override; + s64 PRead(const s32 fd, void* buf, u64 count, s64 offset) override; s64 ReadV(const s32 fd, OrbisKernelIovec* iov, u32 iovcnt) override; s64 PReadV(const s32 fd, OrbisKernelIovec* iov, u32 iovcnt, s64 offset) override; s64 Write(const s32 fd, const void* buf, u64 count) override; - s64 PWrite(const s32 fd, const void* buf, u64 count, u64 offset) override; + s64 PWrite(const s32 fd, const void* buf, u64 count, s64 offset) override; s64 WriteV(const s32 fd, const OrbisKernelIovec* iov, u32 iovcnt) override; s64 PWriteV(const s32 fd, const OrbisKernelIovec* iov, u32 iovcnt, s64 offset) override; diff --git a/src/core/file_sys/hostio/src/host_io_virtual.cpp b/src/core/file_sys/hostio/src/host_io_virtual.cpp index 337a86489..19eb1fe8e 100644 --- a/src/core/file_sys/hostio/src/host_io_virtual.cpp +++ b/src/core/file_sys/hostio/src/host_io_virtual.cpp @@ -383,6 +383,15 @@ s64 HostIO_Virtual::GetDents(const s32 fd, void* buf, u64 count, s64* basep) { if (nullptr == node) return -QUASI_EBADF; + // GetDents must have read size equal to or greater than block size for that FS + // In most cases it's 512 bytes + // Not sure yet if other partitions share the same size + if (count < 512) { + LOG_ERROR(Kernel_Fs, + "(Partial STUB) check for block size associated. Read size must be greater"); + return -QUASI_EINVAL; + } + s64 br = node->getdents(buf, count, handle->pos, basep); if (br > 0) diff --git a/src/core/file_sys/hostio/src/host_io_win32.cpp b/src/core/file_sys/hostio/src/host_io_win32.cpp index 5cb1835ec..946f010d7 100644 --- a/src/core/file_sys/hostio/src/host_io_win32.cpp +++ b/src/core/file_sys/hostio/src/host_io_win32.cpp @@ -58,7 +58,7 @@ s32 HostIO_Win32::FSync(const s32 fd) { return 0 == status ? 0 : -errno; } -s64 HostIO_Win32::LSeek(const s32 fd, u64 offset, s32 whence) { +s64 HostIO_Win32::LSeek(const s32 fd, s64 offset, s32 whence) { errno = 0; s32 status = _lseeki64(fd, offset, ToWIN32SeekOrigin(origin)); return status >= 0 ? status : -errno; @@ -90,7 +90,7 @@ s64 HostIO_Win32::Read(const s32 fd, void* buf, u64 count) { return status >= 0 ? status : -errno; } -s64 HostIO_Win32::PRead(const s32 fd, void* buf, u64 count, u64 offset) { +s64 HostIO_Win32::PRead(const s32 fd, void* buf, u64 count, s64 offset) { errno = 0; s64 bak = LSeek(fd, 0, SeekOrigin::CURRENT); if (bak < 0) @@ -116,7 +116,7 @@ s64 HostIO_Win32::Write(const s32 fd, const void* buf, u64 count) { return status >= 0 ? status : -errno; } -s64 HostIO_Win32::PWrite(const s32 fd, const void* buf, u64 count, u64 offset) { +s64 HostIO_Win32::PWrite(const s32 fd, const void* buf, u64 count, s64 offset) { errno = 0; s64 bak = LSeek(fd, 0, SeekOrigin::CURRENT); if (bak < 0) diff --git a/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h b/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h index 7633105a7..ed4d328fe 100644 --- a/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h +++ b/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h @@ -62,7 +62,7 @@ public: virtual s64 pread(void* buf, u64 count, s64 offset) override; // s64 pwrite(const void* buf, size_t count, u64 offset) override; - + s64 lseek(s64 current, s64 offset, s32 whence) override; s32 fstat(Libraries::Kernel::OrbisKernelStat* sb) override; s32 ftruncate(s64 length) final override; diff --git a/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory.cpp b/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory.cpp index 4f51e17fa..c0842a4fc 100644 --- a/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory.cpp +++ b/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory.cpp @@ -17,6 +17,20 @@ s64 QuasiDirectory::pread(void* buf, u64 count, s64 offset) { return getdents(buf, count, offset, nullptr); } +s64 QuasiDirectory::lseek(s64 current, s64 offset, s32 whence) { + LOG_ERROR(Kernel_Fs, "(STUB)"); + switch (whence) { + case 0: + return offset; + case 1: + return current + offset; + case 2: + return this->st.st_size + offset; + } + UNREACHABLE_MSG("lseek with unknown whence {}", whence); + return -QUASI_ENOSYS; +} + s32 QuasiDirectory::fstat(Libraries::Kernel::OrbisKernelStat* sb) { RebuildDirents(); *sb = st; @@ -29,8 +43,12 @@ s32 QuasiDirectory::ftruncate(s64 length) { s64 QuasiDirectory::getdents(void* buf, u32 count, s64 offset, s64* basep) { RebuildDirents(); + memset(buf, 0, count); - auto it = dirent_cache.lower_bound(offset); + if (offset >= this->st.st_size) + return 0; + + auto it = dirent_cache.upper_bound(offset); if (it == dirent_cache.end()) return 0; @@ -140,8 +158,8 @@ void QuasiDirectory::RebuildDirents(void) { tmp.d_type = node->type() >> 12; tmp.d_reclen = Common::AlignUp(dirent_meta_size + tmp.d_namlen + 1, 4); - dirent_cache[dirent_size] = tmp; dirent_size += tmp.d_reclen; + dirent_cache[dirent_size] = tmp; } this->st.st_size = dirent_size; diff --git a/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory_pfs.cpp b/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory_pfs.cpp index 6d1524ab7..fe56e0be5 100644 --- a/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory_pfs.cpp +++ b/src/core/file_sys/quasifs/src/quasifs_inode_quasi_directory_pfs.cpp @@ -17,13 +17,13 @@ DirectoryPFS::~DirectoryPFS() = default; s64 DirectoryPFS::pread(void* buf, u64 count, s64 offset) { RebuildDirents(); + memset(buf, 0, count); auto it = dirent_cache.lower_bound(offset); if (it == dirent_cache.end()) return 0; - memset(buf, 0, count); u64 cumulative_offset = 0; u32* reclen_location = nullptr; for (; it != dirent_cache.end(); it++) { @@ -76,7 +76,8 @@ s64 DirectoryPFS::lseek(s64 current, s64 offset, s32 whence) { s64 DirectoryPFS::getdents(void* buf, u32 count, s64 offset, s64* basep) { RebuildDirents(); - + memset(buf, 0, count); + auto it = dirent_cache.lower_bound(offset); if (it == dirent_cache.end())