2023-06-23 02:28:14 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-07-29 18:53:34 +02:00
|
|
|
#include "orbis/KernelAllocator.hpp"
|
|
|
|
|
#include "orbis/file.hpp"
|
2023-06-23 02:28:14 +02:00
|
|
|
#include "orbis/utils/Rc.hpp"
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
enum OpenFlags {
|
|
|
|
|
kOpenFlagReadOnly = 0x0,
|
|
|
|
|
kOpenFlagWriteOnly = 0x1,
|
|
|
|
|
kOpenFlagReadWrite = 0x2,
|
|
|
|
|
kOpenFlagNonBlock = 0x4,
|
|
|
|
|
kOpenFlagAppend = 0x8,
|
|
|
|
|
kOpenFlagShLock = 0x10,
|
|
|
|
|
kOpenFlagExLock = 0x20,
|
|
|
|
|
kOpenFlagAsync = 0x40,
|
|
|
|
|
kOpenFlagFsync = 0x80,
|
|
|
|
|
kOpenFlagCreat = 0x200,
|
|
|
|
|
kOpenFlagTrunc = 0x400,
|
|
|
|
|
kOpenFlagExcl = 0x800,
|
|
|
|
|
kOpenFlagDSync = 0x1000,
|
|
|
|
|
kOpenFlagDirect = 0x10000,
|
2023-07-23 16:40:35 +02:00
|
|
|
kOpenFlagDirectory = 0x20000,
|
2023-06-23 02:28:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct IoDevice : orbis::RcBase {
|
2023-07-29 18:53:34 +02:00
|
|
|
virtual orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path,
|
2023-07-29 21:46:28 +02:00
|
|
|
std::uint32_t flags, std::uint32_t mode,
|
|
|
|
|
orbis::Thread *thread) = 0;
|
2023-11-11 15:52:27 +01:00
|
|
|
virtual orbis::ErrorCode unlink(const char *path, bool recursive,
|
|
|
|
|
orbis::Thread *thread) {
|
2023-07-29 21:46:28 +02:00
|
|
|
return orbis::ErrorCode::NOTSUP;
|
|
|
|
|
}
|
2023-11-11 15:52:27 +01:00
|
|
|
virtual orbis::ErrorCode createSymlink(const char *target, const char *linkPath,
|
|
|
|
|
orbis::Thread *thread) {
|
|
|
|
|
return orbis::ErrorCode::NOTSUP;
|
|
|
|
|
}
|
|
|
|
|
virtual orbis::ErrorCode mkdir(const char *path, int mode,
|
|
|
|
|
orbis::Thread *thread) {
|
2023-10-29 10:30:37 +01:00
|
|
|
return orbis::ErrorCode::NOTSUP;
|
|
|
|
|
}
|
|
|
|
|
virtual orbis::ErrorCode rmdir(const char *path, orbis::Thread *thread) {
|
|
|
|
|
return orbis::ErrorCode::NOTSUP;
|
|
|
|
|
}
|
2023-11-11 15:52:27 +01:00
|
|
|
virtual orbis::ErrorCode rename(const char *from, const char *to,
|
|
|
|
|
orbis::Thread *thread) {
|
2023-10-29 10:30:37 +01:00
|
|
|
return orbis::ErrorCode::NOTSUP;
|
|
|
|
|
}
|
2023-06-23 02:28:14 +02:00
|
|
|
};
|
|
|
|
|
|
2023-12-31 12:30:49 +01:00
|
|
|
struct HostFsDevice : IoDevice {
|
|
|
|
|
orbis::kstring hostPath;
|
|
|
|
|
orbis::kstring virtualPath;
|
|
|
|
|
|
|
|
|
|
HostFsDevice(orbis::kstring path, orbis::kstring virtualPath) : hostPath(std::move(path)), virtualPath(std::move(virtualPath)) {}
|
|
|
|
|
orbis::ErrorCode open(orbis::Ref<orbis::File> *file, const char *path,
|
|
|
|
|
std::uint32_t flags, std::uint32_t mode,
|
|
|
|
|
orbis::Thread *thread) override;
|
|
|
|
|
orbis::ErrorCode unlink(const char *path, bool recursive,
|
|
|
|
|
orbis::Thread *thread) override;
|
|
|
|
|
orbis::ErrorCode createSymlink(const char *target, const char *linkPath,
|
|
|
|
|
orbis::Thread *thread) override;
|
|
|
|
|
orbis::ErrorCode mkdir(const char *path, int mode,
|
|
|
|
|
orbis::Thread *thread) override;
|
|
|
|
|
orbis::ErrorCode rmdir(const char *path, orbis::Thread *thread) override;
|
|
|
|
|
orbis::ErrorCode rename(const char *from, const char *to,
|
|
|
|
|
orbis::Thread *thread) override;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-11 18:31:12 +01:00
|
|
|
orbis::ErrorCode convertErrno();
|
2023-12-31 12:30:49 +01:00
|
|
|
IoDevice *createHostIoDevice(orbis::kstring hostPath, orbis::kstring virtualPath);
|
|
|
|
|
orbis::Ref<orbis::File> wrapSocket(int hostFd, orbis::kstring name, int dom, int type, int prot);
|
2023-07-29 18:53:34 +02:00
|
|
|
orbis::ErrorCode createSocket(orbis::Ref<orbis::File> *file,
|
|
|
|
|
orbis::kstring name, int dom, int type, int prot);
|
2023-12-31 12:30:49 +01:00
|
|
|
orbis::File *createHostFile(int hostFd, orbis::Ref<IoDevice> device, bool alignTruncate = false);
|
2023-07-29 18:53:34 +02:00
|
|
|
IoDevice *createFdWrapDevice(int fd);
|