Removed BaseDevice

Cleaned up devices (again)
Unified types inside quasifs
This commit is contained in:
Marek Ledworowski 2025-11-03 23:22:30 +01:00
parent cfb77f33ac
commit 661d017326
37 changed files with 295 additions and 603 deletions

View File

@ -655,8 +655,6 @@ set(QUASIFS src/core/file_sys/quasifs/src/quasifs.cpp
src/core/file_sys/quasifs/src/quasifs_inode_symlink.cpp
src/core/file_sys/quasifs/src/quasifs_partition.cpp
src/core/file_sys/devices/base_device.cpp
src/core/file_sys/devices/base_device.h
src/core/file_sys/devices/console_device.cpp
src/core/file_sys/devices/console_device.h
src/core/file_sys/devices/deci_tty6_device.cpp
@ -671,6 +669,8 @@ set(QUASIFS src/core/file_sys/quasifs/src/quasifs.cpp
src/core/file_sys/devices/random_device.h
src/core/file_sys/devices/srandom_device.cpp
src/core/file_sys/devices/srandom_device.h
src/core/file_sys/devices/rng_device.cpp
src/core/file_sys/devices/rng_device.h
src/core/file_sys/devices/zero_device.cpp
src/core/file_sys/devices/zero_device.h
)

View File

@ -1,12 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/file_sys/devices/base_device.h"
namespace Core::Devices {
BaseDevice::BaseDevice() = default;
BaseDevice::~BaseDevice() = default;
} // namespace Core::Devices

View File

@ -1,87 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "common/types.h"
#include "common/va_ctx.h"
#include "core/libraries/kernel/orbis_error.h"
/**
*
*
*
* TODO: Find a way to yeet this
*
*
*
*
*/
namespace Libraries::Kernel {
struct OrbisKernelStat;
struct OrbisKernelIovec;
} // namespace Libraries::Kernel
namespace Core::Devices {
class BaseDevice {
public:
explicit BaseDevice();
virtual ~BaseDevice() = 0;
virtual s32 ioctl(u64 cmd, Common::VaCtx* args) {
return ORBIS_KERNEL_ERROR_ENOTTY;
}
virtual s64 write(const void* buf, u64 nbytes) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 readv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 writev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 preadv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 pwritev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 lseek(s64 offset, int whence) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 read(void* buf, u64 nbytes) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s32 fstat(Libraries::Kernel::OrbisKernelStat* sb) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s32 fsync() {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s32 ftruncate(s64 length) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 getdents(void* buf, u32 nbytes, s64* basep) {
return ORBIS_KERNEL_ERROR_EBADF;
}
virtual s64 pwrite(const void* buf, u64 nbytes, s64 offset) {
return ORBIS_KERNEL_ERROR_EBADF;
}
};
} // namespace Core::Devices

View File

@ -8,7 +8,7 @@
#include <vector>
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \

View File

@ -5,7 +5,6 @@
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
namespace Core::Devices {

View File

@ -10,11 +10,11 @@ namespace Core::Devices {
NullDevice::NullDevice() = default;
NullDevice::~NullDevice() = default;
s64 NullDevice::pread(void* buf, size_t count, s64 offset) {
s64 NullDevice::read(void* buf, u64 count) {
return 0;
}
s64 NullDevice::pwrite(const void* buf, size_t count, s64 offset) {
s64 NullDevice::write(const void* buf, u64 count) {
return count;
}

View File

@ -3,10 +3,8 @@
#pragma once
#include <cstring>
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \
@ -23,8 +21,8 @@ public:
NullDevice();
~NullDevice();
s64 pread(void* buf, size_t count, s64 offset) override;
s64 pwrite(const void* buf, size_t count, s64 offset) override;
s64 read(void* buf, u64 count) override;
s64 write(const void* buf, u64 count) override;
// clang-format off
s32 ioctl(u64 cmd, Common::VaCtx* args) override { DEVICE_STUB(); }

View File

@ -14,7 +14,7 @@ RandomDevice::RandomDevice() {
RandomDevice::~RandomDevice() = default;
s64 RandomDevice::pread(void* buf, u64 count, s64 offset) {
s64 RandomDevice::read(void* buf, u64 count) {
auto rbuf = static_cast<char*>(buf);
for (size_t i = 0; i < count; i++) {
rbuf[i] = std::rand() & 0xFF;
@ -22,7 +22,7 @@ s64 RandomDevice::pread(void* buf, u64 count, s64 offset) {
return count;
}
s64 RandomDevice::pwrite(const void* buf, u64 count, s64 offset) {
s64 RandomDevice::write(const void* buf, u64 count) {
return count;
}

View File

@ -5,7 +5,6 @@
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \
@ -21,8 +20,8 @@ public:
RandomDevice();
~RandomDevice();
s64 pread(void* buf, size_t count, s64 offset) override;
s64 pwrite(const void* buf, size_t count, s64 offset) override;
s64 read(void* buf, u64 count) override;
s64 write(const void* buf, u64 count) override;
// clang-format off
s32 ioctl(u64 cmd, Common::VaCtx* args) override { DEVICE_STUB(); }

View File

@ -3,15 +3,15 @@
#include <cstdlib>
#include <ctime>
#include "common/logging/log.h"
#include "common/va_ctx.h"
#include "core/file_sys/devices/rng_device.h"
namespace Core::Devices {
std::shared_ptr<BaseDevice> RngDevice::Create(u32 handle, const char*, s32, u16) {
std::srand(std::time(nullptr));
return std::static_pointer_cast<BaseDevice>(std::make_shared<RngDevice>(handle));
}
RngDevice::RngDevice() = default;
RngDevice::~RngDevice() = default;
s32 RngDevice::ioctl(u64 cmd, Common::VaCtx* args) {
LOG_INFO(Kernel_Pthread, "called, cmd = {:#x}", cmd);
@ -29,59 +29,4 @@ s32 RngDevice::ioctl(u64 cmd, Common::VaCtx* args) {
return 0;
}
s64 RngDevice::write(const void* buf, u64 nbytes) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::writev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::readv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::preadv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::lseek(s64 offset, s32 whence) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::read(void* buf, u64 nbytes) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s32 RngDevice::fstat(Libraries::Kernel::OrbisKernelStat* sb) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s32 RngDevice::fsync() {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s32 RngDevice::ftruncate(s64 length) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::getdents(void* buf, u32 nbytes, s64* basep) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
s64 RngDevice::pwrite(const void* buf, u64 nbytes, s64 offset) {
LOG_ERROR(Kernel_Fs, "(STUBBED) called");
return 0;
}
} // namespace Core::Devices

View File

@ -2,32 +2,42 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include "core/file_sys/devices/base_device.h"
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \
{ \
LOG_ERROR(Kernel_Fs, "(STUBBED) called"); \
return -QUASI_ENOSYS; \
}
namespace Core::Devices {
class RngDevice final : public BaseDevice {
u32 handle;
class RngDevice final : public QuasiFS::Device {
public:
static std::shared_ptr<BaseDevice> Create(u32 handle, const char*, s32, u16);
explicit RngDevice(u32 handle) : handle(handle) {}
~RngDevice() override = default;
RngDevice();
~RngDevice();
s32 ioctl(u64 cmd, Common::VaCtx* args) override;
s64 write(const void* buf, u64 nbytes) override;
s64 readv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) override;
s64 writev(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt) override;
s64 preadv(const Libraries::Kernel::OrbisKernelIovec* iov, s32 iovcnt, s64 offset) override;
s64 lseek(s64 offset, s32 whence) override;
s64 read(void* buf, u64 nbytes) override;
s32 fstat(Libraries::Kernel::OrbisKernelStat* sb) override;
s32 fsync() override;
s32 ftruncate(s64 length) override;
s64 getdents(void* buf, u32 nbytes, s64* basep) override;
s64 pwrite(const void* buf, u64 nbytes, s64 offset) override;
// clang-format off
s64 read(void* buf, u64 count) override { DEVICE_STUB(); }
s64 write(const void* buf, u64 count) override { DEVICE_STUB(); }
s64 pread(void* buf, size_t count, s64 offset) override { DEVICE_STUB(); }
s64 pwrite(const void* buf, size_t count, s64 offset) override { DEVICE_STUB(); }
s64 readv(const Libraries::Kernel::OrbisKernelIovec* iov, int iovcnt) override { DEVICE_STUB(); }
s64 writev(const Libraries::Kernel::OrbisKernelIovec* iov, int iovcnt) override { DEVICE_STUB(); }
s64 preadv(const Libraries::Kernel::OrbisKernelIovec* iov, int iovcnt, s64 offset) override { DEVICE_STUB(); }
s64 pwritev(const Libraries::Kernel::OrbisKernelIovec* iov, int iovcnt, s64 offset) override { DEVICE_STUB(); }
s64 lseek(s64 offset, int whence) override { DEVICE_STUB(); }
s32 fstat(Libraries::Kernel::OrbisKernelStat* sb) override { DEVICE_STUB(); }
s32 fsync() override { DEVICE_STUB(); }
s32 ftruncate(s64 length) override { DEVICE_STUB(); }
s64 getdents(void* buf, u32 nbytes, s64* basep) override { DEVICE_STUB(); }
// clang-format on
private:
struct GetRandomArgs {

View File

@ -14,7 +14,7 @@ SRandomDevice::SRandomDevice() {
SRandomDevice::~SRandomDevice() = default;
s64 SRandomDevice::pread(void* buf, size_t count, s64 offset) {
s64 SRandomDevice::read(void* buf, u64 count) {
auto rbuf = static_cast<char*>(buf);
for (size_t i = 0; i < count; i++) {
rbuf[i] = std::rand();
@ -22,7 +22,7 @@ s64 SRandomDevice::pread(void* buf, size_t count, s64 offset) {
return count;
}
s64 SRandomDevice::pwrite(const void* buf, size_t count, s64 offset) {
s64 SRandomDevice::write(const void* buf, u64 count) {
return count;
}

View File

@ -5,7 +5,6 @@
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \
@ -22,8 +21,8 @@ public:
SRandomDevice();
~SRandomDevice();
s64 pread(void* buf, size_t count, s64 offset) override;
s64 pwrite(const void* buf, size_t count, s64 offset) override;
s64 read(void* buf, u64 count) override;
s64 write(const void* buf, u64 count) override;
// clang-format off
s32 ioctl(u64 cmd, Common::VaCtx* args) override { DEVICE_STUB(); }

View File

@ -10,12 +10,12 @@ namespace Core::Devices {
ZeroDevice::ZeroDevice() = default;
ZeroDevice::~ZeroDevice() = default;
s64 ZeroDevice::pread(void* buf, size_t count, s64 offset) {
s64 ZeroDevice::read(void* buf, u64 count) {
memset(buf, 0, count);
return count;
}
s64 ZeroDevice::pwrite(const void* buf, size_t count, s64 offset) {
s64 ZeroDevice::write(const void* buf, u64 count) {
return count;
}

View File

@ -4,7 +4,7 @@
#pragma once
#include "common/logging/log.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#define DEVICE_STUB() \
@ -21,8 +21,8 @@ public:
ZeroDevice();
~ZeroDevice();
s64 pread(void* buf, size_t count, s64 offset) override;
s64 pwrite(const void* buf, size_t count, s64 offset) override;
s64 read(void* buf, u64 count) override;
s64 write(const void* buf, u64 count) override;
// clang-format off
s32 ioctl(u64 cmd, Common::VaCtx* args) override { DEVICE_STUB(); }

View File

@ -10,7 +10,6 @@
#include <tsl/robin_map.h>
#include "common/io_file.h"
#include "common/logging/formatter.h"
#include "core/file_sys/devices/base_device.h"
#include "core/file_sys/directories/base_directory.h"
namespace Libraries::Net {
@ -84,7 +83,6 @@ struct File {
Common::FS::IOFile f;
std::mutex m_mutex;
std::shared_ptr<Directories::BaseDirectory> directory; // only valid for type == Directory
std::shared_ptr<Devices::BaseDevice> device; // only valid for type == Device
std::shared_ptr<Libraries::Net::Socket> socket; // only valid for type == Socket
std::shared_ptr<Libraries::Net::Epoll> epoll; // only valid for type == Epoll
std::shared_ptr<Libraries::Net::Resolver> resolver; // only valid for type == Resolver

View File

@ -79,21 +79,21 @@ public:
// POSIX Functions
//
int Open(const fs::path& path, int flags, u16 mode = 0755) override;
int Creat(const fs::path& path, u16 mode = 0755) override;
int Close(const int fd) override;
s32 Open(const fs::path& path, int flags, u16 mode = 0755) override;
s32 Creat(const fs::path& path, u16 mode = 0755) override;
s32 Close(const int fd) override;
int Link(const fs::path& src, const fs::path& dst) override;
int Unlink(const fs::path& path) override;
int LinkSymbolic(const fs::path& src, const fs::path& dst) override;
s32 Link(const fs::path& src, const fs::path& dst) override;
s32 Unlink(const fs::path& path) override;
s32 LinkSymbolic(const fs::path& src, const fs::path& dst) override;
int Flush(const int fd) override;
int FSync(const int fd) override;
u64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
s32 Flush(const int fd) override;
s32 FSync(const int fd) override;
s64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
s64 Tell(const int fd) override;
int Truncate(const fs::path& path, u64 size) override;
int FTruncate(const int fd, u64 size) override;
s32 Truncate(const fs::path& path, u64 size) override;
s32 FTruncate(const int fd, u64 size) override;
s64 Write(const int fd, const void* buf, u64 count) override;
s64 Read(const int fd, void* buf, u64 count) override;
@ -101,14 +101,14 @@ public:
s64 PWrite(const int fd, const void* buf, u64 count, u64 offset) override;
s64 PRead(const int fd, void* buf, u64 count, u64 offset) override;
int MKDir(const fs::path& path, u16 mode = 0755) override;
int RMDir(const fs::path& path) override;
s32 MKDir(const fs::path& path, u16 mode = 0755) override;
s32 RMDir(const fs::path& path) override;
int Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int Chmod(const fs::path& path, u16 mode) override;
int FChmod(const int fd, u16 mode) override;
s32 Chmod(const fs::path& path, u16 mode) override;
s32 FChmod(const int fd, u16 mode) override;
};
} // namespace HostIODriver

View File

@ -45,21 +45,21 @@ public:
* This function doesn't return numeric fd
* The only outputs are 0 and -errno!
*/
int Open(const fs::path& path, int flags, u16 mode = 0755) override;
int Creat(const fs::path& path, u16 mode = 0755) override;
int Close(const int fd) override;
s32 Open(const fs::path& path, int flags, u16 mode = 0755) override;
s32 Creat(const fs::path& path, u16 mode = 0755) override;
s32 Close(const int fd) override;
int Link(const fs::path& src, const fs::path& dst) override;
int Unlink(const fs::path& path) override;
int LinkSymbolic(const fs::path& src, const fs::path& dst) override;
s32 Link(const fs::path& src, const fs::path& dst) override;
s32 Unlink(const fs::path& path) override;
s32 LinkSymbolic(const fs::path& src, const fs::path& dst) override;
int Flush(const int fd) override;
int FSync(const int fd) override;
u64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
s32 Flush(const int fd) override;
s32 FSync(const int fd) override;
s64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
s64 Tell(const int fd) override;
int Truncate(const fs::path& path, u64 size) override;
int FTruncate(const int fd, u64 size) override;
s32 Truncate(const fs::path& path, u64 size) override;
s32 FTruncate(const int fd, u64 size) override;
s64 Write(const int fd, const void* buf, u64 count) override;
s64 Read(const int fd, void* buf, u64 count) override;
@ -67,14 +67,14 @@ public:
s64 PWrite(const int fd, const void* buf, u64 count, u64 offset) override;
s64 PRead(const int fd, void* buf, u64 count, u64 offset) override;
int MKDir(const fs::path& path, u16 mode = 0755) override;
int RMDir(const fs::path& path) override;
s32 MKDir(const fs::path& path, u16 mode = 0755) override;
s32 RMDir(const fs::path& path) override;
int Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int Chmod(const fs::path& path, u16 mode) override;
int FChmod(const int fd, u16 mode) override;
s32 Chmod(const fs::path& path, u16 mode) override;
s32 FChmod(const int fd, u16 mode) override;
//
// Derived, complex functions are to be handled by main FS class

View File

@ -24,21 +24,21 @@ public:
HostIO_Win32();
~HostIO_Win32();
int Open(const fs::path& path, int flags, u16 mode = 0755) override;
int Creat(const fs::path& path, u16 mode = 0755) override;
int Close(const int fd) override;
s32 Open(const fs::path& path, int flags, u16 mode = 0755) override;
s32 Creat(const fs::path& path, u16 mode = 0755) override;
s32 Close(const int fd) override;
// int Link(const fs::path& src, const fs::path& dst) override;
// int Unlink(const fs::path& path) override;
// int LinkSymbolic(const fs::path& src, const fs::path& dst) override;
s32 Link(const fs::path& src, const fs::path& dst) override;
s32 Unlink(const fs::path& path) override;
s32 LinkSymbolic(const fs::path& src, const fs::path& dst) override;
// int Flush(const int fd) override;
// int FSync(const int fd) override;
// u64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
s32 Flush(const int fd) override;
s32 FSync(const int fd) override;
// s64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) override;
// s64 Tell(const int fd) override;
// int Truncate(const fs::path& path, u64 size) override;
// int FTruncate(const int fd, u64 size) override;
s32 Truncate(const fs::path& path, u64 size) override;
s32 FTruncate(const int fd, u64 size) override;
// s64 Write(const int fd, const void* buf, u64 count) override;
// s64 Read(const int fd, void* buf, u64 count) override;
@ -46,14 +46,14 @@ public:
// s64 PWrite(const int fd, const void* buf, u64 count, u64 offset) override;
// s64 PRead(const int fd, void* buf, u64 count, u64 offset) override;
// int MKDir(const fs::path& path, u16 mode = 0755) override;
// int RMDir(const fs::path& path) override;
s32 MKDir(const fs::path& path, u16 mode = 0755) override;
s32 RMDir(const fs::path& path) override;
// int Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
// int FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
// int Chmod(const fs::path& path, u16 mode) override;
// int FChmod(const int fd, u16 mode) override;
s32 Chmod(const fs::path& path, u16 mode) override;
s32 FChmod(const int fd, u16 mode) override;
};
} // namespace HostIODriver

View File

@ -16,21 +16,21 @@ HostIO_Base::HostIO_Base() = default;
HostIO_Base::~HostIO_Base() = default;
// clang-format off
int HostIO_Base::Open(const fs::path& path, int flags, u16 mode) { STUB(); }
int HostIO_Base::Creat(const fs::path& path, u16 mode) { STUB() }
int HostIO_Base::Close(const int fd) { STUB() }
s32 HostIO_Base::Open(const fs::path& path, int flags, u16 mode) { STUB(); }
s32 HostIO_Base::Creat(const fs::path& path, u16 mode) { STUB() }
s32 HostIO_Base::Close(const int fd) { STUB() }
int HostIO_Base::Link(const fs::path& src, const fs::path& dst) { STUB() }
int HostIO_Base::Unlink(const fs::path& path) { STUB() }
int HostIO_Base::LinkSymbolic(const fs::path& src, const fs::path& dst) { STUB() }
s32 HostIO_Base::Link(const fs::path& src, const fs::path& dst) { STUB() }
s32 HostIO_Base::Unlink(const fs::path& path) { STUB() }
s32 HostIO_Base::LinkSymbolic(const fs::path& src, const fs::path& dst) { STUB() }
int HostIO_Base::Flush(const int fd) { STUB() }
int HostIO_Base::FSync(const int fd) { STUB() }
u64 HostIO_Base::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) { STUB() }
s32 HostIO_Base::Flush(const int fd) { STUB() }
s32 HostIO_Base::FSync(const int fd) { STUB() }
s64 HostIO_Base::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) { STUB() }
s64 HostIO_Base::Tell(const int fd) { STUB() }
int HostIO_Base::Truncate(const fs::path& path, u64 size) { STUB() }
int HostIO_Base::FTruncate(const int fd, u64 size) { STUB() }
s32 HostIO_Base::Truncate(const fs::path& path, u64 size) { STUB() }
s32 HostIO_Base::FTruncate(const int fd, u64 size) { STUB() }
s64 HostIO_Base::Write(const int fd, const void* buf, u64 count) { STUB() }
s64 HostIO_Base::Read(const int fd, void* buf, u64 count) { STUB() }
@ -38,14 +38,14 @@ s64 HostIO_Base::Read(const int fd, void* buf, u64 count) { STUB() }
s64 HostIO_Base::PWrite(const int fd, const void* buf, u64 count, u64 offset) { STUB() }
s64 HostIO_Base::PRead(const int fd, void* buf, u64 count, u64 offset) { STUB() }
int HostIO_Base::MKDir(const fs::path& path, u16 mode) { STUB() }
int HostIO_Base::RMDir(const fs::path& path) { STUB() }
s32 HostIO_Base::MKDir(const fs::path& path, u16 mode) { STUB() }
s32 HostIO_Base::RMDir(const fs::path& path) { STUB() }
int HostIO_Base::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) { STUB() }
int HostIO_Base::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) { STUB() }
s32 HostIO_Base::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) { STUB() }
s32 HostIO_Base::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) { STUB() }
int HostIO_Base::Chmod(const fs::path& path, u16 mode) { STUB() }
int HostIO_Base::FChmod(const int fd, u16 mode) { STUB() }
s32 HostIO_Base::Chmod(const fs::path& path, u16 mode) { STUB() }
s32 HostIO_Base::FChmod(const int fd, u16 mode) { STUB() }
// clang-format on
} // namespace HostIODriver

View File

@ -5,10 +5,9 @@
#include <filesystem>
#include <system_error>
#include "core/libraries/kernel/file_system.h"
#include "../../quasifs/quasi_types.h"
#include "common/types.h"
#include "core/file_sys/quasifs/quasi_types.h"
#include "core/libraries/kernel/file_system.h"
namespace HostIODriver {
namespace fs = std::filesystem;
@ -25,31 +24,31 @@ public:
// Native wrappers
//
virtual int Open(const fs::path& path, int flags, u16 mode = 0755);
virtual int Creat(const fs::path& path, u16 mode = 0755);
virtual int Close(const int fd);
virtual s32 Open(const fs::path& path, int flags, u16 mode = 0755);
virtual s32 Creat(const fs::path& path, u16 mode = 0755);
virtual s32 Close(const int fd);
virtual int LinkSymbolic(const fs::path& src, const fs::path& dst);
virtual int Link(const fs::path& src, const fs::path& dst);
virtual int Unlink(const fs::path& path);
virtual int Flush(const int fd);
virtual int FSync(const int fd);
virtual int Truncate(const fs::path& path, u64 size);
virtual int FTruncate(const int fd, u64 size);
virtual u64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin);
virtual s32 LinkSymbolic(const fs::path& src, const fs::path& dst);
virtual s32 Link(const fs::path& src, const fs::path& dst);
virtual s32 Unlink(const fs::path& path);
virtual s32 Flush(const int fd);
virtual s32 FSync(const int fd);
virtual s32 Truncate(const fs::path& path, u64 size);
virtual s32 FTruncate(const int fd, u64 size);
virtual s64 LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin);
virtual s64 Tell(const int fd);
virtual s64 Write(const int fd, const void* buf, u64 count);
virtual s64 PWrite(const int fd, const void* buf, u64 count, u64 offset);
virtual s64 Read(const int fd, void* buf, u64 count);
virtual s64 PRead(const int fd, void* buf, u64 count, u64 offset);
virtual int MKDir(const fs::path& path, u16 mode = 0755);
virtual int RMDir(const fs::path& path);
virtual s32 MKDir(const fs::path& path, u16 mode = 0755);
virtual s32 RMDir(const fs::path& path);
virtual int Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf);
virtual int FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf);
virtual s32 Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf);
virtual s32 FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf);
virtual int Chmod(const fs::path& path, u16 mode);
virtual int FChmod(const int fd, u16 mode);
virtual s32 Chmod(const fs::path& path, u16 mode);
virtual s32 FChmod(const int fd, u16 mode);
//
// Derived, complex functions are to be handled by main FS class
//

View File

@ -2,73 +2,72 @@
#include <cstdint>
#include <cstdio>
#include <dirent.h>
#include <dirent.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include "../../quasifs/quasi_types.h"
#include "core/file_sys/hostio/host_io_posix.h"
#include "core/file_sys/quasifs/quasi_types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
#include "core/file_sys/quasifs/quasifs_inode_symlink.h"
#include "core/file_sys/quasifs/quasifs_partition.h"
#include "../../quasifs/quasifs_inode_quasi_device.h"
#include "../../quasifs/quasifs_inode_quasi_directory.h"
#include "../../quasifs/quasifs_inode_quasi_file.h"
#include "../../quasifs/quasifs_inode_symlink.h"
#include "../../quasifs/quasifs_partition.h"
#include "../host_io_posix.h"
#include "host_io_base.h"
namespace HostIODriver {
int HostIO_POSIX::Open(const fs::path& path, int flags, u16 mode) {
s32 HostIO_POSIX::Open(const fs::path& path, int flags, u16 mode) {
errno = 0;
int status = open(path.c_str(), ToPOSIXOpenFlags(flags), ToPOSIXOpenMode(mode));
return status >= 0 ? status : -errno;
}
int HostIO_POSIX::Creat(const fs::path& path, u16 mode) {
s32 HostIO_POSIX::Creat(const fs::path& path, u16 mode) {
errno = 0;
int status = creat(path.c_str(), ToPOSIXOpenMode(mode));
return status >= 0 ? status : -errno;
}
int HostIO_POSIX::Close(const int fd) {
s32 HostIO_POSIX::Close(const int fd) {
errno = 0;
int status = close(fd);
return 0 == status ? status : -errno;
}
int HostIO_POSIX::Link(const fs::path& src, const fs::path& dst) {
s32 HostIO_POSIX::Link(const fs::path& src, const fs::path& dst) {
errno = 0;
int status = link(src.c_str(), dst.c_str());
return 0 == status ? status : -errno;
}
int HostIO_POSIX::Unlink(const fs::path& path) {
s32 HostIO_POSIX::Unlink(const fs::path& path) {
errno = 0;
int status = unlink(path.c_str());
return 0 == status ? status : -errno;
}
int HostIO_POSIX::LinkSymbolic(const fs::path& src, const fs::path& dst) {
s32 HostIO_POSIX::LinkSymbolic(const fs::path& src, const fs::path& dst) {
errno = 0;
int status = symlink(src.c_str(), dst.c_str());
return 0 == status ? status : -errno;
}
int HostIO_POSIX::Flush(const int fd) {
s32 HostIO_POSIX::Flush(const int fd) {
errno = 0;
return 0;
}
int HostIO_POSIX::FSync(const int fd) {
s32 HostIO_POSIX::FSync(const int fd) {
errno = 0;
int status = fsync(fd);
return 0 == status ? status : -errno;
}
u64 HostIO_POSIX::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) {
s64 HostIO_POSIX::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) {
errno = 0;
int status = lseek(fd, offset, ToPOSIXSeekOrigin(origin));
return status >= 0 ? status : -errno;
@ -78,13 +77,13 @@ s64 HostIO_POSIX::Tell(const int fd) {
return LSeek(fd, 0, SeekOrigin::CURRENT);
}
int HostIO_POSIX::Truncate(const fs::path& path, u64 size) {
s32 HostIO_POSIX::Truncate(const fs::path& path, u64 size) {
errno = 0;
int status = truncate(path.c_str(), size);
return status >= 0 ? status : -errno;
}
int HostIO_POSIX::FTruncate(const int fd, u64 size) {
s32 HostIO_POSIX::FTruncate(const int fd, u64 size) {
errno = 0;
int status = ftruncate(fd, size);
return status >= 0 ? status : -errno;
@ -114,19 +113,19 @@ s64 HostIO_POSIX::PRead(const int fd, void* buf, u64 count, u64 offset) {
return status >= 0 ? status : -errno;
}
int HostIO_POSIX::MKDir(const fs::path& path, u16 mode) {
s32 HostIO_POSIX::MKDir(const fs::path& path, u16 mode) {
errno = 0;
int status = mkdir(path.c_str(), mode);
return 0 == status ? status : -errno;
}
int HostIO_POSIX::RMDir(const fs::path& path) {
s32 HostIO_POSIX::RMDir(const fs::path& path) {
errno = 0;
int status = rmdir(path.c_str());
return 0 == status ? status : -errno;
}
int HostIO_POSIX::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 HostIO_POSIX::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
errno = 0;
struct stat st;
@ -160,7 +159,7 @@ int HostIO_POSIX::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat*
return 0;
}
int HostIO_POSIX::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 HostIO_POSIX::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
errno = 0;
struct stat st;
@ -188,13 +187,13 @@ int HostIO_POSIX::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbu
return 0;
}
int HostIO_POSIX::Chmod(const fs::path& path, u16 mode) {
s32 HostIO_POSIX::Chmod(const fs::path& path, u16 mode) {
errno = 0;
int status = chmod(path.c_str(), mode);
return 0 == status ? status : -errno;
}
int HostIO_POSIX::FChmod(const int fd, u16 mode) {
s32 HostIO_POSIX::FChmod(const int fd, u16 mode) {
errno = 0;
int status = fchmod(fd, mode);
return 0 == status ? status : -errno;

View File

@ -4,26 +4,26 @@
#include <filesystem>
#include "common/logging/log.h"
#include "core/file_sys/hostio/host_io_posix.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
#include "core/file_sys/quasifs/quasifs_inode_symlink.h"
#include "core/file_sys/quasifs/quasifs_partition.h"
#include "src/core/file_sys/hostio/host_io_virtual.h"
#include "src/core/file_sys/quasifs/quasifs_inode_quasi_device.h"
#include "src/core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "src/core/file_sys/quasifs/quasifs_inode_quasi_file.h"
#include "src/core/file_sys/quasifs/quasifs_inode_symlink.h"
#include "src/core/file_sys/quasifs/quasifs_inode_virtualfile.h"
#include "src/core/file_sys/quasifs/quasifs_partition.h"
#include "host_io_base.h"
#include "src/core/file_sys/quasifs/quasi_errno.h"
#include "src/core/file_sys/quasifs/quasi_sys_fcntl.h"
#include "src/core/file_sys/quasifs/quasi_types.h"
#include "src/core/file_sys/quasifs/quasifs_inode_virtualfile.h"
#include "host_io_base.h"
namespace HostIODriver {
HostIO_Virtual::HostIO_Virtual() = default;
HostIO_Virtual::~HostIO_Virtual() = default;
int HostIO_Virtual::Open(const fs::path& path, int flags, u16 mode) {
s32 HostIO_Virtual::Open(const fs::path& path, int flags, u16 mode) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -72,7 +72,7 @@ int HostIO_Virtual::Open(const fs::path& path, int flags, u16 mode) {
return 0;
}
int HostIO_Virtual::Creat(const fs::path& path, u16 mode) {
s32 HostIO_Virtual::Creat(const fs::path& path, u16 mode) {
if (nullptr == this->res)
return -QUASI_EINVAL;
if (!this->res->node->is_dir())
@ -84,12 +84,12 @@ int HostIO_Virtual::Creat(const fs::path& path, u16 mode) {
return this->res->mountpoint->touch(parent, path.filename().string(), new_file);
}
int HostIO_Virtual::Close(const int fd) {
s32 HostIO_Virtual::Close(const int fd) {
// N/A
return 0;
}
int HostIO_Virtual::Link(const fs::path& src, const fs::path& dst) {
s32 HostIO_Virtual::Link(const fs::path& src, const fs::path& dst) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -110,7 +110,7 @@ int HostIO_Virtual::Link(const fs::path& src, const fs::path& dst) {
return part->link(src_node, dst_parent, dst_name);
}
int HostIO_Virtual::Unlink(const fs::path& path) {
s32 HostIO_Virtual::Unlink(const fs::path& path) {
if (nullptr == this->res)
return -QUASI_EINVAL;
if ("." == this->res->leaf)
@ -124,7 +124,7 @@ int HostIO_Virtual::Unlink(const fs::path& path) {
return part->unlink(parent, this->res->leaf);
}
int HostIO_Virtual::LinkSymbolic(const fs::path& src, const fs::path& dst) {
s32 HostIO_Virtual::LinkSymbolic(const fs::path& src, const fs::path& dst) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -135,12 +135,12 @@ int HostIO_Virtual::LinkSymbolic(const fs::path& src, const fs::path& dst) {
return this->res->mountpoint->touch(this->res->parent, dst.filename().string(), sym);
}
int HostIO_Virtual::Flush(const int fd) {
s32 HostIO_Virtual::Flush(const int fd) {
// not applicable
return 0;
}
int HostIO_Virtual::FSync(const int fd) {
s32 HostIO_Virtual::FSync(const int fd) {
if (nullptr == handle)
return -QUASI_EINVAL;
@ -152,7 +152,7 @@ int HostIO_Virtual::FSync(const int fd) {
return handle->node->fsync();
}
u64 HostIO_Virtual::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) {
s64 HostIO_Virtual::LSeek(const int fd, u64 offset, QuasiFS::SeekOrigin origin) {
if (nullptr == handle)
return -QUASI_EINVAL;
@ -178,7 +178,7 @@ s64 HostIO_Virtual::Tell(const int fd) {
return LSeek(fd, 0, SeekOrigin::CURRENT);
}
int HostIO_Virtual::Truncate(const fs::path& path, u64 size) {
s32 HostIO_Virtual::Truncate(const fs::path& path, u64 size) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -196,7 +196,7 @@ int HostIO_Virtual::Truncate(const fs::path& path, u64 size) {
return node->ftruncate(size);
}
int HostIO_Virtual::FTruncate(const int fd, u64 size) {
s32 HostIO_Virtual::FTruncate(const int fd, u64 size) {
if (nullptr == handle)
return -QUASI_EINVAL;
@ -259,7 +259,7 @@ s64 HostIO_Virtual::PRead(const int fd, void* buf, u64 count, u64 offset) {
return node->pread(buf, count, offset);
}
int HostIO_Virtual::MKDir(const fs::path& path, u16 mode) {
s32 HostIO_Virtual::MKDir(const fs::path& path, u16 mode) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -267,7 +267,7 @@ int HostIO_Virtual::MKDir(const fs::path& path, u16 mode) {
return this->res->mountpoint->mkdir(this->res->parent, this->res->leaf, new_dir);
}
int HostIO_Virtual::RMDir(const fs::path& path) {
s32 HostIO_Virtual::RMDir(const fs::path& path) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -291,7 +291,7 @@ int HostIO_Virtual::RMDir(const fs::path& path) {
return 0;
}
int HostIO_Virtual::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 HostIO_Virtual::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -305,7 +305,7 @@ int HostIO_Virtual::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelSta
return 0;
}
int HostIO_Virtual::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 HostIO_Virtual::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
if (nullptr == this->handle)
return -QUASI_EINVAL;
@ -319,7 +319,7 @@ int HostIO_Virtual::FStat(const int fd, Libraries::Kernel::OrbisKernelStat* stat
return 0;
}
int HostIO_Virtual::Chmod(const fs::path& path, u16 mode) {
s32 HostIO_Virtual::Chmod(const fs::path& path, u16 mode) {
if (nullptr == this->res)
return -QUASI_EINVAL;
@ -331,7 +331,7 @@ int HostIO_Virtual::Chmod(const fs::path& path, u16 mode) {
return Partition::chmod(node, mode);
}
int HostIO_Virtual::FChmod(const int fd, u16 mode) {
s32 HostIO_Virtual::FChmod(const int fd, u16 mode) {
if (nullptr == this->handle)
return -QUASI_EINVAL;

View File

@ -1,23 +1,22 @@
// INAA License @marecl 2025
#include "common/logging/log.h"
#include "../host_io_win32.h"
#include "src/core/file_sys/hostio/host_io_win32.h"
namespace HostIODriver {
HostIO_Win32::HostIO_Win32() = default;
HostIO_Win32::~HostIO_Win32() = default;
int HostIO_Win32::Creat(const fs::path& path, u16 mode) {
s32 HostIO_Win32::Creat(const fs::path& path, u16 mode) {
LOG_ERROR(Kernel_Fs, "Stub called in HostIO_Base: {}:{}", __FILE__, __LINE__);
return -38;
}
int HostIO_Win32::Open(const fs::path& path, int flags, u16 mode) {
s32 HostIO_Win32::Open(const fs::path& path, int flags, u16 mode) {
LOG_ERROR(Kernel_Fs, "Stub called in HostIO_Base: {}:{}", __FILE__, __LINE__);
return -38;
}
int HostIO_Win32::Close(const int fd) {
s32 HostIO_Win32::Close(const int fd) {
LOG_ERROR(Kernel_Fs, "Stub called in HostIO_Base: {}:{}", __FILE__, __LINE__);
return -38;
}

View File

@ -61,30 +61,32 @@ private:
public:
OperationImpl(QFS& qfs) : qfs(qfs) {}
int Open(const fs::path& path, int flags, u16 mode = 0755) override;
int Creat(const fs::path& path, u16 mode = 0755) override;
int Close(const s32 fd) override;
int LinkSymbolic(const fs::path& src, const fs::path& dst) override;
int Link(const fs::path& src, const fs::path& dst) override;
int Unlink(const fs::path& path) override;
int Flush(const s32 fd) override;
int FSync(const s32 fd) override;
int Truncate(const fs::path& path, u64 size) override;
int FTruncate(const s32 fd, u64 size) override;
u64 LSeek(const s32 fd, u64 offset, SeekOrigin origin) override;
s32 Open(const fs::path& path, int flags, u16 mode = 0755) override;
s32 Creat(const fs::path& path, u16 mode = 0755) override;
s32 Close(const s32 fd) override;
s32 LinkSymbolic(const fs::path& src, const fs::path& dst) override;
s32 Link(const fs::path& src, const fs::path& dst) override;
s32 Unlink(const fs::path& path) override;
s32 Flush(const s32 fd) override;
s32 FSync(const s32 fd) override;
s32 Truncate(const fs::path& path, u64 size) override;
s32 FTruncate(const s32 fd, u64 size) override;
s64 LSeek(const s32 fd, u64 offset, SeekOrigin origin) override;
s64 Tell(const s32 fd) 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 Read(const s32 fd, void* buf, u64 count) override;
s64 PRead(const s32 fd, void* buf, u64 count, u64 offset) override;
int MKDir(const fs::path& path, u16 mode = 0755) override;
int RMDir(const fs::path& path) override;
s32 MKDir(const fs::path& path, u16 mode = 0755) override;
s32 RMDir(const fs::path& path) override;
int Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int FStat(const s32 fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) override;
s32 FStat(const s32 fd, Libraries::Kernel::OrbisKernelStat* statbuf) override;
int Chmod(const fs::path& path, u16 mode) override;
int FChmod(const s32 fd, u16 mode) override;
s32 Chmod(const fs::path& path, u16 mode) override;
s32 FChmod(const s32 fd, u16 mode) override;
s64 getdents(void* buf, u32 nbytes, s64* basep);
};
public:
@ -155,9 +157,9 @@ public:
// Additional binds
//
bool IsOpen(const int fd) noexcept;
int SetSize(const int fd, uint64_t size) noexcept;
s64 GetSize(const int fd) noexcept;
bool IsOpen(const s32 fd) noexcept;
int SetSize(const s32 fd, uint64_t size) noexcept;
s64 GetSize(const s32 fd) noexcept;
// Not a port, used by 2-3 functions that ;
s64 GetDirectorySize(const fs::path& path) noexcept;
@ -233,12 +235,13 @@ public:
return -QUASI_EINVAL;
};
fd_handle_ptr GetHandle(s32 fd);
private:
void SyncHostImpl(partition_ptr part);
// Get next available fd slot
int GetFreeHandleNo();
fd_handle_ptr GetHandle(s32 fd);
// partition by blkdev
// partition_ptr GetPartitionByBlockdev(uint64_t blkid);
mount_t* GetPartitionInfo(const partition_ptr part);
@ -246,5 +249,4 @@ private:
partition_ptr GetPartitionByParent(const dir_ptr dir);
int IsPartitionRO(const partition_ptr part);
};
}; // namespace QuasiFS

View File

@ -30,11 +30,11 @@ public:
}
virtual s64 read(void* buf, u64 count) {
return pread(buf, count, 0);
return -QUASI_EBADF;
}
virtual s64 write(const void* buf, u64 count) {
return pwrite(buf, count, 0);
return -QUASI_EBADF;
}
virtual s64 pread(void* buf, u64 count, s64 offset) {
@ -107,7 +107,7 @@ public:
}
virtual s64 getdents(void* buf, u32 nbytes, s64* basep) {
return -QUASI_EBADF;
return -QUASI_EINVAL;
}
// type helpers

View File

@ -21,6 +21,9 @@ public:
return std::make_shared<T>(std::forward<Args>(args)...);
UNREACHABLE();
}
s64 pread(void* buf, u64 count, s64 offset) override;
s64 pwrite(const void* buf, u64 count, s64 offset) override;
};
} // namespace QuasiFS

View File

@ -2,11 +2,9 @@
#include "common/logging/log.h"
#include "../quasi_errno.h"
#include "../quasi_types.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasi_types.h"
#include "core/file_sys/quasifs/quasifs.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
#include "core/file_sys/quasifs/quasifs_inode_symlink.h"
@ -331,21 +329,21 @@ int QFS::GetHostPath(fs::path& output, const fs::path& path) {
return res.mountpoint->GetHostPath(output, res.local_path);
}
bool QFS::IsOpen(const int fd) noexcept {
bool QFS::IsOpen(const s32 fd) noexcept {
fd_handle_ptr fh = this->GetHandle(fd);
if (nullptr == fh)
return false;
return fh->IsOpen();
}
int QFS::SetSize(const int fd, uint64_t size) noexcept {
int QFS::SetSize(const s32 fd, uint64_t size) noexcept {
fd_handle_ptr fh = this->GetHandle(fd);
if (nullptr == fh)
return -QUASI_EBADF;
return this->Operation.FTruncate(fd, size);
}
s64 QFS::GetSize(const int fd) noexcept {
s64 QFS::GetSize(const s32 fd) noexcept {
fd_handle_ptr fh = this->GetHandle(fd);
if (nullptr == fh)
return -QUASI_EBADF;
@ -438,7 +436,7 @@ int QFS::GetFreeHandleNo() {
return open_fd_size;
}
fd_handle_ptr QFS::GetHandle(int fd) {
fd_handle_ptr QFS::GetHandle(s32 fd) {
if (fd < 0 || fd >= this->open_fd.size())
return nullptr;
return this->open_fd.at(fd);

View File

@ -15,4 +15,12 @@ Device::Device() {
Device::~Device() = default;
s64 Device::pread(void* buf, u64 count, s64 offset) {
return read(buf, count);
}
s64 Device::pwrite(const void* buf, u64 count, s64 offset) {
return write(buf, count);
}
} // namespace QuasiFS

View File

@ -3,7 +3,7 @@
#include <map>
#include <string>
#include "../quasi_errno.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
namespace QuasiFS {

View File

@ -2,7 +2,7 @@
#include <vector>
#include "../quasi_errno.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
namespace QuasiFS {

View File

@ -2,7 +2,7 @@
#include <vector>
#include "../quasi_errno.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasifs_inode_virtualfile.h"
namespace QuasiFS {

View File

@ -1,11 +1,9 @@
// INAA License @marecl 2025
#include "common/logging/log.h"
// #include "common/string_util.h"
#include "../quasi_errno.h"
#include "../quasi_types.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasi_types.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
#include "core/file_sys/quasifs/quasifs_inode_symlink.h"

View File

@ -4,10 +4,9 @@
#include "common/logging/log.h"
#include "../quasi_errno.h"
#include "../quasi_sys_fcntl.h"
#include "../quasi_types.h"
#include "core/file_sys/quasifs/quasi_errno.h"
#include "core/file_sys/quasifs/quasi_sys_fcntl.h"
#include "core/file_sys/quasifs/quasi_types.h"
#include "core/file_sys/quasifs/quasifs.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_directory.h"
#include "core/file_sys/quasifs/quasifs_inode_quasi_file.h"
@ -16,7 +15,7 @@
namespace QuasiFS {
int QFS::OperationImpl::Open(const fs::path& path, int flags, u16 mode) {
s32 QFS::OperationImpl::Open(const fs::path& path, int flags, u16 mode) {
Resolved res;
// Resolve for parent dir to avoid treating ENOENT as missing just the end file
int resolve_status = qfs.Resolve(path, res);
@ -110,11 +109,11 @@ int QFS::OperationImpl::Open(const fs::path& path, int flags, u16 mode) {
return next_free_handle;
}
int QFS::OperationImpl::Creat(const fs::path& path, u16 mode) {
s32 QFS::OperationImpl::Creat(const fs::path& path, u16 mode) {
return Open(path, QUASI_O_CREAT | QUASI_O_WRONLY | QUASI_O_TRUNC, mode);
};
int QFS::OperationImpl::Close(s32 fd) {
s32 QFS::OperationImpl::Close(s32 fd) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -138,7 +137,7 @@ int QFS::OperationImpl::Close(s32 fd) {
return 0;
}
int QFS::OperationImpl::LinkSymbolic(const fs::path& src, const fs::path& dst) {
s32 QFS::OperationImpl::LinkSymbolic(const fs::path& src, const fs::path& dst) {
Resolved src_res;
Resolved dst_res;
int status_what = qfs.Resolve(src, src_res);
@ -201,7 +200,7 @@ int QFS::OperationImpl::LinkSymbolic(const fs::path& src, const fs::path& dst) {
return vio_status;
}
int QFS::OperationImpl::Link(const fs::path& src, const fs::path& dst) {
s32 QFS::OperationImpl::Link(const fs::path& src, const fs::path& dst) {
Resolved src_res;
Resolved dst_res;
int status_what = qfs.Resolve(src, src_res);
@ -258,7 +257,7 @@ int QFS::OperationImpl::Link(const fs::path& src, const fs::path& dst) {
return vio_status;
}
int QFS::OperationImpl::Unlink(const fs::path& path) {
s32 QFS::OperationImpl::Unlink(const fs::path& path) {
Resolved res;
int resolve_status;
@ -318,7 +317,7 @@ int QFS::OperationImpl::Unlink(const fs::path& path) {
return vio_status;
}
int QFS::OperationImpl::Flush(const s32 fd) {
s32 QFS::OperationImpl::Flush(const s32 fd) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -349,7 +348,7 @@ int QFS::OperationImpl::Flush(const s32 fd) {
return vio_status;
}
int QFS::OperationImpl::FSync(const s32 fd) {
s32 QFS::OperationImpl::FSync(const s32 fd) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -380,7 +379,7 @@ int QFS::OperationImpl::FSync(const s32 fd) {
return vio_status;
};
int QFS::OperationImpl::Truncate(const fs::path& path, u64 length) {
s32 QFS::OperationImpl::Truncate(const fs::path& path, u64 length) {
Resolved res;
int status = qfs.Resolve(path, res);
@ -417,7 +416,7 @@ int QFS::OperationImpl::Truncate(const fs::path& path, u64 length) {
return vio_status;
}
int QFS::OperationImpl::FTruncate(const s32 fd, u64 length) {
s32 QFS::OperationImpl::FTruncate(const s32 fd, u64 length) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -450,7 +449,7 @@ int QFS::OperationImpl::FTruncate(const s32 fd, u64 length) {
return vio_status;
}
u64 QFS::OperationImpl::LSeek(const s32 fd, u64 offset, SeekOrigin origin) {
s64 QFS::OperationImpl::LSeek(const s32 fd, u64 offset, SeekOrigin origin) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -616,7 +615,7 @@ s64 QFS::OperationImpl::PRead(const s32 fd, void* buf, u64 count, u64 offset) {
return vio_status;
};
int QFS::OperationImpl::MKDir(const fs::path& path, u16 mode) {
s32 QFS::OperationImpl::MKDir(const fs::path& path, u16 mode) {
Resolved res;
int resolve_status = qfs.Resolve(path, res);
@ -661,7 +660,7 @@ int QFS::OperationImpl::MKDir(const fs::path& path, u16 mode) {
return vio_status;
}
int QFS::OperationImpl::RMDir(const fs::path& path) {
s32 QFS::OperationImpl::RMDir(const fs::path& path) {
Resolved res;
int status = qfs.Resolve(path, res);
@ -696,7 +695,7 @@ int QFS::OperationImpl::RMDir(const fs::path& path) {
return status;
}
int QFS::OperationImpl::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 QFS::OperationImpl::Stat(const fs::path& path, Libraries::Kernel::OrbisKernelStat* statbuf) {
Resolved res;
int resolve_status = qfs.Resolve(path, res);
@ -753,7 +752,7 @@ int QFS::OperationImpl::Stat(const fs::path& path, Libraries::Kernel::OrbisKerne
return vio_status;
}
int QFS::OperationImpl::FStat(const s32 fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
s32 QFS::OperationImpl::FStat(const s32 fd, Libraries::Kernel::OrbisKernelStat* statbuf) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;
@ -797,7 +796,7 @@ int QFS::OperationImpl::FStat(const s32 fd, Libraries::Kernel::OrbisKernelStat*
return vio_status;
}
int QFS::OperationImpl::Chmod(const fs::path& path, u16 mode) {
s32 QFS::OperationImpl::Chmod(const fs::path& path, u16 mode) {
Resolved res;
int resolve_status = qfs.Resolve(path, res);
@ -835,7 +834,7 @@ int QFS::OperationImpl::Chmod(const fs::path& path, u16 mode) {
return vio_status;
}
int QFS::OperationImpl::FChmod(const s32 fd, u16 mode) {
s32 QFS::OperationImpl::FChmod(const s32 fd, u16 mode) {
fd_handle_ptr handle = qfs.GetHandle(fd);
if (nullptr == handle)
return -QUASI_EBADF;

View File

@ -39,42 +39,9 @@
#include <sys/select.h>
#endif
namespace D = Core::Devices;
namespace qfs = QuasiFS;
static QuasiFS::QFS* g_qfs = Common::Singleton<QuasiFS::QFS>::Instance();
// #define GET_DEVICE_FD(fd) \
// [](u32, const char*, int, u16) { \
// return Common::Singleton<Core::FileSys::HandleTable>::Instance()->GetFile(fd)->device; \
// }
// // prefix path, only dev devices
// static std::map<std::string, FactoryDevice> available_device = {
// // clang-format off
// {"/dev/stdin", GET_DEVICE_FD(0)},
// {"/dev/stdout", GET_DEVICE_FD(1)},
// {"/dev/stderr", GET_DEVICE_FD(2)},
// {"/dev/fd/0", GET_DEVICE_FD(0)},
// {"/dev/fd/1", GET_DEVICE_FD(1)},
// {"/dev/fd/2", GET_DEVICE_FD(2)},
// {"/dev/deci_stdin", GET_DEVICE_FD(0)},
// {"/dev/deci_stdout", GET_DEVICE_FD(1)},
// {"/dev/deci_stderr", GET_DEVICE_FD(2)},
// {"/dev/null", GET_DEVICE_FD(0)}, // fd0 (stdin) is a nop device
// {"/dev/urandom", &D::URandomDevice::Create },
// {"/dev/random", &D::RandomDevice::Create },
// {"/dev/srandom", &D::SRandomDevice::Create },
// {"/dev/console", &D::ConsoleDevice::Create },
// {"/dev/deci_tty6",&D::DeciTty6Device::Create },
// {"/dev/rng", &D::RngDevice::Create },
// // clang-format on
// };
namespace Libraries::Kernel {
s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
@ -140,43 +107,10 @@ s64 PS4_SYSV_ABI sceKernelWrite(s32 fd, const void* buf, u64 nbytes) {
return result;
}
s64 ReadFile(Common::FS::IOFile& file, void* buf, u64 nbytes) {
const auto* memory = Core::Memory::Instance();
// Invalidate up to the actual number of bytes that could be read.
const auto remaining = file.GetSize() - file.Tell();
memory->InvalidateMemory(reinterpret_cast<VAddr>(buf), std::min<u64>(nbytes, remaining));
return file.ReadRaw<u8>(buf, nbytes);
}
s64 PS4_SYSV_ABI readv(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
*__Error() = POSIX_EBADF;
return -1;
}
std::scoped_lock lk{file->m_mutex};
if (file->type == Core::FileSys::FileType::Device) {
s64 result = file->device->readv(iov, iovcnt);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
} else if (file->type == Core::FileSys::FileType::Directory) {
s64 result = file->directory->readv(iov, iovcnt);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
s64 total_read = 0;
for (s32 i = 0; i < iovcnt; i++) {
total_read += ReadFile(file->f, iov[i].iov_base, iov[i].iov_len);
total_read += read(fd, iov[i].iov_base, iov[i].iov_len);
}
return total_read;
}
@ -195,28 +129,11 @@ s64 PS4_SYSV_ABI sceKernelReadv(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt)
}
s64 PS4_SYSV_ABI writev(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
*__Error() = POSIX_EBADF;
return -1;
}
std::scoped_lock lk{file->m_mutex};
if (file->type == Core::FileSys::FileType::Device) {
s64 result = file->device->writev(iov, iovcnt);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
s64 total_written = 0;
s64 total_read = 0;
for (s32 i = 0; i < iovcnt; i++) {
total_written += file->f.WriteRaw<u8>(iov[i].iov_base, iov[i].iov_len);
total_read += write(fd, iov[i].iov_base, iov[i].iov_len);
}
return total_written;
return total_read;
}
s64 PS4_SYSV_ABI posix_writev(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt) {
@ -401,8 +318,6 @@ s32 PS4_SYSV_ABI sceKernelCheckReachability(const char* path) {
s32 PS4_SYSV_ABI fstat(s32 fd, OrbisKernelStat* sb) {
LOG_DEBUG(Kernel_Fs, "(PARTIAL) fd = {}", fd);
// Libraries::Kernel::OrbisKernelStat st;
int result = g_qfs->Operation.FStat(fd, sb);
if (result < 0) {
*__Error() = -result;
@ -575,46 +490,9 @@ s32 PS4_SYSV_ABI sceKernelRename(const char* from, const char* to) {
}
s64 PS4_SYSV_ABI posix_preadv(s32 fd, OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
if (offset < 0) {
*__Error() = POSIX_EINVAL;
return -1;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
*__Error() = POSIX_EBADF;
return -1;
}
std::scoped_lock lk{file->m_mutex};
if (file->type == Core::FileSys::FileType::Device) {
s64 result = file->device->preadv(iov, iovcnt, offset);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
} else if (file->type == Core::FileSys::FileType::Directory) {
s64 result = file->directory->preadv(iov, iovcnt, offset);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
const s64 pos = file->f.Tell();
SCOPE_EXIT {
file->f.Seek(pos);
};
if (!file->f.Seek(offset)) {
*__Error() = POSIX_EIO;
return -1;
}
s64 total_read = 0;
for (s32 i = 0; i < iovcnt; i++) {
total_read += ReadFile(file->f, iov[i].iov_base, iov[i].iov_len);
total_read += g_qfs->Operation.PRead(fd, iov[i].iov_base, iov[i].iov_len, offset);
}
return total_read;
}
@ -655,13 +533,14 @@ s32 PS4_SYSV_ABI sceKernelFsync(s32 fd) {
}
static s64 GetDents(s32 fd, char* buf, u64 nbytes, s64* basep) {
QuasiFS::fd_handle_ptr f = g_qfs->GetHandle(fd);
if (buf == nullptr) {
*__Error() = POSIX_EFAULT;
return -1;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
if (nullptr == f->node) {
*__Error() = POSIX_EBADF;
return -1;
}
@ -671,29 +550,12 @@ static s64 GetDents(s32 fd, char* buf, u64 nbytes, s64* basep) {
return -1;
}
switch (file->type) {
case Core::FileSys::FileType::Directory: {
s64 result = file->directory->getdents(buf, nbytes, basep);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
case Core::FileSys::FileType::Device: {
s64 result = file->device->getdents(buf, nbytes, basep);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
default: {
// Not directory or device
*__Error() = POSIX_EINVAL;
s32 result = f->node->getdents(buf, nbytes, basep);
LOG_TRACE(Lib_Kernel, "ioctl: fd = {:X} cmd = {:X} result = {}", fd, cmd, result);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
}
return ORBIS_OK;
}
@ -729,41 +591,11 @@ s64 PS4_SYSV_ABI sceKernelGetdirentries(s32 fd, char* buf, u64 nbytes, s64* base
}
s64 PS4_SYSV_ABI posix_pwritev(s32 fd, const OrbisKernelIovec* iov, s32 iovcnt, s64 offset) {
if (offset < 0) {
*__Error() = POSIX_EINVAL;
return -1;
}
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
*__Error() = POSIX_EBADF;
return -1;
}
std::scoped_lock lk{file->m_mutex};
if (file->type == Core::FileSys::FileType::Device) {
s64 result = file->device->pwritev(iov, iovcnt, offset);
if (result < 0) {
ErrSceToPosix(result);
return -1;
}
return result;
}
const s64 pos = file->f.Tell();
SCOPE_EXIT {
file->f.Seek(pos);
};
if (!file->f.Seek(offset)) {
*__Error() = POSIX_EIO;
return -1;
}
s64 total_written = 0;
s64 total_read = 0;
for (s32 i = 0; i < iovcnt; i++) {
total_written += file->f.WriteRaw<u8>(iov[i].iov_base, iov[i].iov_len);
total_read += g_qfs->Operation.PWrite(fd, iov[i].iov_base, iov[i].iov_len, offset);
}
return total_written;
return total_read;
}
s64 PS4_SYSV_ABI posix_pwrite(s32 fd, void* buf, u64 nbytes, s64 offset) {

View File

@ -12,6 +12,7 @@
#include "common/thread.h"
#include "common/va_ctx.h"
#include "core/file_sys/fs.h"
#include "core/file_sys/quasifs/quasifs.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/debug.h"
#include "core/libraries/kernel/equeue.h"
@ -189,20 +190,23 @@ s32 PS4_SYSV_ABI sceKernelUuidCreate(OrbisKernelUuid* orbisUuid) {
}
s32 PS4_SYSV_ABI kernel_ioctl(s32 fd, u64 cmd, VA_ARGS) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
if (file == nullptr) {
LOG_INFO(Lib_Kernel, "ioctl: fd = {:X} cmd = {:X} file == nullptr", fd, cmd);
LOG_WARNING(Lib_Kernel, "ioctl: fd = {:X} cmd = {:X}", fd, cmd);
QuasiFS::QFS* qfs = Common::Singleton<QuasiFS::QFS>::Instance();
QuasiFS::fd_handle_ptr f = qfs->GetHandle(fd);
if (nullptr == f->node) {
g_posix_errno = POSIX_EBADF;
return -1;
}
if (file->type != Core::FileSys::FileType::Device) {
LOG_WARNING(Lib_Kernel, "ioctl: fd = {:X} cmd = {:X} file->type != Device", fd, cmd);
g_posix_errno = ENOTTY;
if (!f->node->is_block()) {
g_posix_errno = POSIX_ENOTTY;
return -1;
}
VA_CTX(ctx);
s32 result = file->device->ioctl(cmd, &ctx);
s32 result = f->node->ioctl(cmd, &ctx);
LOG_TRACE(Lib_Kernel, "ioctl: fd = {:X} cmd = {:X} result = {}", fd, cmd, result);
if (result < 0) {
ErrSceToPosix(result);

View File

@ -53,6 +53,7 @@
#include "core/file_sys/devices/nop_device.h"
#include "core/file_sys/devices/null_device.h"
#include "core/file_sys/devices/random_device.h"
#include "core/file_sys/devices/rng_device.h"
#include "core/file_sys/devices/srandom_device.h"
#include "core/file_sys/devices/zero_device.h"
@ -168,6 +169,7 @@ void Emulator::LoadFilesystem(const std::string& id) {
qfs->ForceInsert("/dev", "srandom", qfs::Device::Create<Devices::SRandomDevice>());
qfs->ForceInsert("/dev", "zero", qfs::Device::Create<Devices::ZeroDevice>());
qfs->ForceInsert("/dev", "null", qfs::Device::Create<Devices::NullDevice>());
qfs->ForceInsert("/dev", "rng", qfs::Device::Create<Devices::RngDevice>());
qfs->Operation.Chmod("/dev/deci_stderr", 0666);
qfs->Operation.Chmod("/dev/deci_stdout", 0666);