Slight clarifications, privatization

Moving on for cherry-picking
This commit is contained in:
Marek Ledworowski 2025-11-03 19:35:48 +01:00
parent b8f485df73
commit 7f50e6b515
9 changed files with 31 additions and 33 deletions

View File

@ -330,28 +330,6 @@ bool IOFile::Commit() const {
return commit_result;
}
bool IOFile::SetSize(u64 size) const {
if (!IsOpen()) {
return false;
}
errno = 0;
#ifdef _WIN32
const auto set_size_result = _chsize_s(fileno(file), static_cast<s64>(size)) == 0;
#else
const auto set_size_result = ftruncate(fileno(file), static_cast<s64>(size)) == 0;
#endif
if (!set_size_result) {
const auto ec = std::error_code{errno, std::generic_category()};
LOG_ERROR(Common_Filesystem, "Failed to resize the file at path={}, size={}, ec_message={}",
PathToUTF8String(file_path), size, ec.message());
}
return set_size_result;
}
u64 IOFile::GetSize() const {
if (!IsOpen()) {
return 0;

View File

@ -114,7 +114,6 @@ public:
bool Flush() const;
bool Commit() const;
bool SetSize(u64 size) const;
u64 GetSize() const;
bool Seek(s64 offset, SeekOrigin origin = SeekOrigin::SetOrigin) const;

View File

@ -24,7 +24,7 @@ public:
~SRandomDevice();
s64 pread(void* buf, size_t count, u64 offset) override;
//s64 pwrite(const void* buf, size_t count, u64 offset) override;
s64 pwrite(const void* buf, size_t count, u64 offset) override;
// clang-format off
s32 ioctl(u64 cmd, Common::VaCtx* args) override { DEVICE_STUB(); }

View File

@ -11,6 +11,11 @@
#include "quasi_types.h"
#include "quasifs_inode.h"
// #ifdef _linux_
// #else
// #define QUASI_CASE_INSENSITIVE
// #endif
/**
* Wrapper class
* Basically a Partition object with a bit of extra functionality and single superblock
@ -39,6 +44,7 @@ private:
// open file descriptors. search is linear, looking for first available nullptr
std::vector<fd_handle_ptr> open_fd;
// Drivers
HostIO hio_driver{};
HostVIO vio_driver{};

View File

@ -30,11 +30,11 @@ public:
}
virtual s64 read(void* buf, size_t count) {
return -QUASI_EBADF;
return pread(buf, count, 0);
}
virtual s64 write(const void* buf, size_t count) {
return -QUASI_EBADF;
return pwrite(buf, count, 0);
}
virtual s64 pread(void* buf, size_t count, u64 offset) {
@ -81,7 +81,7 @@ public:
virtual s64 pwritev(const Libraries::Kernel::OrbisKernelIovec* iov, int iovcnt, u64 offset) {
u64 tb = 0;
for (unsigned int idx = 0; idx < iovcnt; idx++) {
int status = this->pwrite(iov[idx].iov_base, iov[idx].iov_len,offset);
int status = this->pwrite(iov[idx].iov_base, iov[idx].iov_len, offset);
if (status < 0)
return status;
tb += status;

View File

@ -4,6 +4,7 @@
#include <map>
#include <string>
#include <vector>
#include "common/assert.h"
@ -14,13 +15,23 @@ namespace QuasiFS {
// Directory
class QuasiDirectory : public Inode {
public:
private:
std::map<std::string, inode_ptr> entries{};
public:
dir_ptr mounted_root = nullptr;
QuasiDirectory();
~QuasiDirectory() = default;
std::vector<std::string> Entries(void) {
std::vector<std::string> out{};
for (auto& kv : this->entries)
out.push_back(kv.first);
return out;
}
static dir_ptr Create(void) {
return std::make_shared<QuasiDirectory>();
}

View File

@ -88,7 +88,8 @@ void _printTree(const inode_ptr& node, const std::string& name, int depth) {
LOG_INFO(Kernel_Fs, "[ls -la]\t\t\t\t\t\t\t|--{}{}\n", depEnt, "[MOUNTPOINT]");
_printTree(dir->mounted_root, "", depth + 1);
} else {
for (auto& [childName, child] : dir->entries) {
for (auto& childName : dir->Entries()) {
inode_ptr child = dir->lookup(childName);
_printTree(child, childName, depth + 1);
}
}
@ -226,6 +227,8 @@ int QFS::ForceInsert(const fs::path& path, const std::string& name, inode_ptr no
return res.mountpoint->touch(std::static_pointer_cast<Directory>(res.node), name, node);
}
// DO NOT, AND I SWEAR D O N O T touch this function
// Debugging it is a royal PITA
int QFS::Resolve(const fs::path& path, Resolved& res) {
if (path.empty())
return -QUASI_EINVAL;

View File

@ -83,6 +83,8 @@ inode_ptr Partition::GetInodeByFileno(fileno_t fileno) {
return (inode_table.end() == ret) ? nullptr : ret->second;
}
// DO NOT, AND I SWEAR D O N O T touch this function
// Debugging it is a royal PITA
int Partition::Resolve(fs::path& path, Resolved& res) {
if (path.empty())
return -QUASI_EINVAL;
@ -361,8 +363,8 @@ bool Partition::IndexInode(inode_ptr node) {
inode_table[node_fileno] = node;
if (node->is_dir()) {
auto dir = std::static_pointer_cast<Directory>(node);
for (auto& kv : dir->entries)
IndexInode(kv.second);
for (auto& kv : dir->Entries())
IndexInode(dir->lookup(kv));
if (dir->mounted_root)
IndexInode(dir->mounted_root);
}

View File

@ -144,9 +144,8 @@ void Emulator::LoadFilesystem(const std::string& id) {
qfs->Operation.MKDir("/dev/fd");
qfs->ForceInsert("/dev/fd", "0", qfs::Device::Create<Devices::ZeroDevice>());
qfs->ForceInsert("/dev/fd", "1", qfs::Device::Create<Devices::Logger>("stdout", false));
// qfs->ForceInsert("/dev/fd", "1", std::make_shared<Devices::Logger>("stdout", false));
qfs->ForceInsert("/dev/fd", "2", qfs::Device::Create<Devices::Logger>("stderr", true));
// stdin is unavailable from within the app???
// std* is unavailable from within the app???
qfs->Operation.LinkSymbolic("/dev/fd/0", "/dev/stdin");
qfs->Operation.LinkSymbolic("/dev/fd/1", "/dev/stdout");
qfs->Operation.LinkSymbolic("/dev/fd/2", "/dev/stderr");