commented on some things, awaiting will to live

This commit is contained in:
Marek Ledworowski 2025-11-13 00:01:16 +01:00
parent 7e4affaf8b
commit 8f2fb6a76f
4 changed files with 47 additions and 34 deletions

View File

@ -31,7 +31,6 @@ protected:
void RebuildDirents(void); void RebuildDirents(void);
time_t last_dirent_rebuild_time{0}; time_t last_dirent_rebuild_time{0};
std::vector<u64> dirent_offset{};
std::vector<u8> dirent_cache_bin{}; std::vector<u8> dirent_cache_bin{};
public: public:

View File

@ -46,7 +46,7 @@ public:
s64 pread(void* buf, u64 count, s64 offset) override; 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; s64 getdents(void* buf, u32 count, s64 offset, s64* basep) override;
}; };

View File

@ -15,11 +15,35 @@ QuasiDirectory::QuasiDirectory() {
} }
s64 QuasiDirectory::pread(void* buf, u64 count, s64 offset) { 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); return getdents(buf, count, offset, nullptr);
} }
s64 QuasiDirectory::lseek(s64 current, s64 offset, s32 whence) { s64 QuasiDirectory::lseek(s64 current, s64 offset, s32 whence) {
LOG_ERROR(Kernel_Fs, "(STUB)"); LOG_ERROR(Kernel_Fs, "(STUB)");
// TBD, most likely acts like a file would
switch (whence) { switch (whence) {
case 0: case 0:
return offset; return offset;
@ -46,9 +70,9 @@ s64 QuasiDirectory::getdents(void* buf, u32 count, s64 offset, s64* basep) {
RebuildDirents(); RebuildDirents();
memset(buf, 0, count); memset(buf, 0, count);
// Copies as many COMPLETE dirents as possible // always returns 512 bytes
// If they don't fit - fill with 0s // forces handle ptr to increment in multiples of 512
// Last dirent has its size adjusted to fill the rest of the buffer // returns each memory-aligned segment
if (offset >= this->st.st_size) if (offset >= this->st.st_size)
return 0; return 0;
@ -157,7 +181,6 @@ void QuasiDirectory::RebuildDirents(void) {
u64 dirent_size = 0; u64 dirent_size = 0;
this->dirent_cache_bin.clear(); this->dirent_cache_bin.clear();
this->dirent_offset.clear();
for (auto entry = entries.begin(); entry != entries.end(); ++entry) { for (auto entry = entries.begin(); entry != entries.end(); ++entry) {
dirent_t tmp{}; dirent_t tmp{};
@ -172,11 +195,11 @@ void QuasiDirectory::RebuildDirents(void) {
auto dirent_ptr = reinterpret_cast<const u8*>(&tmp); auto dirent_ptr = reinterpret_cast<const u8*>(&tmp);
dirent_cache_bin.insert(dirent_cache_bin.end(), dirent_ptr, dirent_ptr + tmp.d_reclen); 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; 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; return;
} }

View File

@ -39,29 +39,22 @@ s64 DirectoryPFS::pread(void* buf, u64 count, s64 offset) {
return count; return count;
} }
s64 DirectoryPFS::lseek(s64 current, s64 offset, s32 whence) { // s64 DirectoryPFS::lseek(s64 current, s64 offset, s32 whence) {
switch (whence) { // LOG_ERROR(Kernel_Fs, "(PFS STUB)");
case 0:
return offset; // // TBD, most likely acts like a file would
break;
case 1: // switch (whence) {
if ((current + offset) >= dirents_size) // case 0:
return current + offset; // return offset;
{ // case 1:
auto _tmp = // return current + offset;
std::lower_bound(dirent_offset.begin(), dirent_offset.end(), current + offset); // case 2:
if (_tmp == dirent_offset.end()) // return this->st.st_size + offset;
return -QUASI_EINVAL; // }
return *_tmp; // UNREACHABLE_MSG("lseek with unknown whence {}", whence);
} // return -QUASI_ENOSYS;
break; // }
case 2:
return dirents_size + offset;
break;
}
UNREACHABLE_MSG("lseek with unknown whence {}", whence);
return -QUASI_ENOSYS;
}
s64 DirectoryPFS::getdents(void* buf, u32 count, s64 offset, s64* basep) { s64 DirectoryPFS::getdents(void* buf, u32 count, s64 offset, s64* basep) {
RebuildDirents(); RebuildDirents();
@ -89,7 +82,6 @@ void DirectoryPFS::RebuildDirents(void) {
u64 dirent_size = 0; u64 dirent_size = 0;
this->dirent_cache_bin.clear(); this->dirent_cache_bin.clear();
this->dirent_offset.clear();
for (auto entry = entries.begin(); entry != entries.end(); ++entry) { for (auto entry = entries.begin(); entry != entries.end(); ++entry) {
dirent_pfs_t tmp{}; dirent_pfs_t tmp{};
@ -104,11 +96,10 @@ void DirectoryPFS::RebuildDirents(void) {
auto dirent_ptr = reinterpret_cast<const u8*>(&tmp); auto dirent_ptr = reinterpret_cast<const u8*>(&tmp);
dirent_cache_bin.insert(dirent_cache_bin.end(), dirent_ptr, dirent_ptr + tmp.d_reclen); 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; dirent_size += tmp.d_reclen;
} }
this->st.st_size = dirent_size; // directory size is always 65536 bytes
return; return;
} }