stubbed lseek

This commit is contained in:
Marek Ledworowski 2025-11-11 23:33:54 +01:00
parent 7df5d494dd
commit ff990b570d
6 changed files with 39 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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())