From 8f2fb6a76f944e5b248c9fce2d8278918b481235 Mon Sep 17 00:00:00 2001 From: Marek Ledworowski Date: Thu, 13 Nov 2025 00:01:16 +0100 Subject: [PATCH] commented on some things, awaiting will to live --- .../quasifs/quasifs_inode_quasi_directory.h | 1 - .../quasifs_inode_quasi_directory_pfs.h | 2 +- .../src/quasifs_inode_quasi_directory.cpp | 35 ++++++++++++--- .../src/quasifs_inode_quasi_directory_pfs.cpp | 43 ++++++++----------- 4 files changed, 47 insertions(+), 34 deletions(-) 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 cd884f9d6..2ddf5d727 100644 --- a/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h +++ b/src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h @@ -31,7 +31,6 @@ protected: void RebuildDirents(void); time_t last_dirent_rebuild_time{0}; - std::vector dirent_offset{}; std::vector dirent_cache_bin{}; public: diff --git a/src/core/file_sys/quasifs/quasifs_inode_quasi_directory_pfs.h b/src/core/file_sys/quasifs/quasifs_inode_quasi_directory_pfs.h index e8669f7b9..deb0498a5 100644 --- a/src/core/file_sys/quasifs/quasifs_inode_quasi_directory_pfs.h +++ b/src/core/file_sys/quasifs/quasifs_inode_quasi_directory_pfs.h @@ -46,7 +46,7 @@ public: s64 pread(void* buf, u64 count, s64 offset) override; - s64 lseek(s64 current, s64 offset, s32 whence) override; + // s64 lseek(s64 current, s64 offset, s32 whence) override; s64 getdents(void* buf, u32 count, s64 offset, s64* basep) 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 658ed886f..b0857d087 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 @@ -15,11 +15,35 @@ QuasiDirectory::QuasiDirectory() { } s64 QuasiDirectory::pread(void* buf, u64 count, s64 offset) { + RebuildDirents(); + + // complete dirents are divided into 512 (0-filled) byte blocks + // if more than 512 bytes are read, it draws bytes from the next block + // anything after last dirent is zeroed-out + // reclen of last complete dirent (in aligned segment) has size filling up to the end of the + // segment + + if (offset >= this->dirent_cache_bin.size()) + return 0; + + s64 bytes_available = this->dirent_cache_bin.size() - offset; + // bytes_to_read but retains the same variable lmao + if (bytes_available >= count) + bytes_available = count; + + memcpy(buf, this->dirent_cache_bin.data() + offset, bytes_available); + + // always returns count + return count; + return getdents(buf, count, offset, nullptr); } s64 QuasiDirectory::lseek(s64 current, s64 offset, s32 whence) { LOG_ERROR(Kernel_Fs, "(STUB)"); + + // TBD, most likely acts like a file would + switch (whence) { case 0: return offset; @@ -46,9 +70,9 @@ s64 QuasiDirectory::getdents(void* buf, u32 count, s64 offset, s64* basep) { RebuildDirents(); memset(buf, 0, count); - // Copies as many COMPLETE dirents as possible - // If they don't fit - fill with 0s - // Last dirent has its size adjusted to fill the rest of the buffer + // always returns 512 bytes + // forces handle ptr to increment in multiples of 512 + // returns each memory-aligned segment if (offset >= this->st.st_size) return 0; @@ -157,7 +181,6 @@ void QuasiDirectory::RebuildDirents(void) { u64 dirent_size = 0; this->dirent_cache_bin.clear(); - this->dirent_offset.clear(); for (auto entry = entries.begin(); entry != entries.end(); ++entry) { dirent_t tmp{}; @@ -172,11 +195,11 @@ void QuasiDirectory::RebuildDirents(void) { auto dirent_ptr = reinterpret_cast(&tmp); dirent_cache_bin.insert(dirent_cache_bin.end(), dirent_ptr, dirent_ptr + tmp.d_reclen); - dirent_offset.push_back(dirent_size); dirent_size += tmp.d_reclen; } - this->st.st_size = dirent_size; + // directory size is aligned to 512 + this->st.st_size = Common::AlignUp(dirent_size, 512); return; } 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 2bd819326..d14e3a2c7 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 @@ -39,29 +39,22 @@ s64 DirectoryPFS::pread(void* buf, u64 count, s64 offset) { return count; } -s64 DirectoryPFS::lseek(s64 current, s64 offset, s32 whence) { - switch (whence) { - case 0: - return offset; - break; - case 1: - if ((current + offset) >= dirents_size) - return current + offset; - { - auto _tmp = - std::lower_bound(dirent_offset.begin(), dirent_offset.end(), current + offset); - if (_tmp == dirent_offset.end()) - return -QUASI_EINVAL; - return *_tmp; - } - break; - case 2: - return dirents_size + offset; - break; - } - UNREACHABLE_MSG("lseek with unknown whence {}", whence); - return -QUASI_ENOSYS; -} +// s64 DirectoryPFS::lseek(s64 current, s64 offset, s32 whence) { +// LOG_ERROR(Kernel_Fs, "(PFS STUB)"); + +// // TBD, most likely acts like a file would + +// 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; +// } s64 DirectoryPFS::getdents(void* buf, u32 count, s64 offset, s64* basep) { RebuildDirents(); @@ -89,7 +82,6 @@ void DirectoryPFS::RebuildDirents(void) { u64 dirent_size = 0; this->dirent_cache_bin.clear(); - this->dirent_offset.clear(); for (auto entry = entries.begin(); entry != entries.end(); ++entry) { dirent_pfs_t tmp{}; @@ -104,11 +96,10 @@ void DirectoryPFS::RebuildDirents(void) { auto dirent_ptr = reinterpret_cast(&tmp); dirent_cache_bin.insert(dirent_cache_bin.end(), dirent_ptr, dirent_ptr + tmp.d_reclen); - dirent_offset.push_back(dirent_size); dirent_size += tmp.d_reclen; } - this->st.st_size = dirent_size; + // directory size is always 65536 bytes return; }