diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.cpp b/deps/ox/src/ox/fs/filesystem/filesystem.cpp index f2712790..607e0ceb 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.cpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.cpp @@ -10,7 +10,7 @@ namespace ox { -Result FileSystem::read(FileAddress addr) { +Result FileSystem::read(FileAddress addr) noexcept { switch (addr.type()) { case FileAddressType::Inode: return read(addr.getInode().value); @@ -22,7 +22,7 @@ Result FileSystem::read(FileAddress addr) { } } -Error FileSystem::read(FileAddress addr, void *buffer, std::size_t size) { +Error FileSystem::read(FileAddress addr, void *buffer, std::size_t size) noexcept { switch (addr.type()) { case FileAddressType::Inode: return read(addr.getInode().value, buffer, size); @@ -34,7 +34,7 @@ Error FileSystem::read(FileAddress addr, void *buffer, std::size_t size) { } } -Error FileSystem::read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) { +Error FileSystem::read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept { switch (addr.type()) { case FileAddressType::Inode: return read(addr.getInode().value, readStart, readSize, buffer, size); @@ -46,7 +46,7 @@ Error FileSystem::read(FileAddress addr, std::size_t readStart, std::size_t read } } -Error FileSystem::remove(FileAddress addr, bool recursive) { +Error FileSystem::remove(FileAddress addr, bool recursive) noexcept { switch (addr.type()) { case FileAddressType::Inode: return remove(addr.getInode().value, recursive); @@ -58,7 +58,7 @@ Error FileSystem::remove(FileAddress addr, bool recursive) { } } -Error FileSystem::write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType) { +Error FileSystem::write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType) noexcept { switch (addr.type()) { case FileAddressType::Inode: return write(addr.getInode().value, buffer, size, fileType); @@ -70,7 +70,7 @@ Error FileSystem::write(FileAddress addr, void *buffer, uint64_t size, uint8_t f } } -Result FileSystem::stat(FileAddress addr) { +Result FileSystem::stat(FileAddress addr) noexcept { switch (addr.type()) { case FileAddressType::Inode: return stat(addr.getInode().value); diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.hpp b/deps/ox/src/ox/fs/filesystem/filesystem.hpp index 5c472346..4b32ee31 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.hpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.hpp @@ -19,62 +19,67 @@ namespace ox { class FileSystem { public: - virtual ~FileSystem() = default; + virtual ~FileSystem() noexcept = default; - virtual Error mkdir(const char *path, bool recursive = false) = 0; + virtual Error mkdir(const char *path, bool recursive = false) noexcept = 0; /** * Moves an entry from one directory to another. * @param src the path to the file * @param dest the path of the destination directory */ - virtual Error move(const char *src, const char *dest) = 0; + virtual Error move(const char *src, const char *dest) noexcept = 0; - virtual Error read(const char *path, void *buffer, std::size_t buffSize) = 0; + virtual Error read(const char *path, void *buffer, std::size_t buffSize) noexcept = 0; - virtual Result read(const char *path) = 0; + virtual Result read(const char *path) noexcept = 0; - virtual Error read(uint64_t inode, void *buffer, std::size_t size) = 0; + virtual Error read(uint64_t inode, void *buffer, std::size_t size) noexcept = 0; - virtual Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) = 0; + virtual Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept = 0; - virtual Result read(uint64_t inode) = 0; + virtual Result read(uint64_t inode) noexcept = 0; - Error read(FileAddress addr, void *buffer, std::size_t size); + Error read(FileAddress addr, void *buffer, std::size_t size) noexcept; - Error read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size); + Error read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept; - Result read(FileAddress addr); + Result read(FileAddress addr) noexcept; - virtual Error remove(const char *path, bool recursive = false) = 0; + virtual Error remove(const char *path, bool recursive = false) noexcept = 0; - Error remove(FileAddress addr, bool recursive = false); + Error remove(FileAddress addr, bool recursive = false) noexcept; - virtual Error resize(uint64_t size, void *buffer = nullptr) = 0; + virtual Error resize(uint64_t size, void *buffer = nullptr) noexcept = 0; - virtual Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) = 0; + virtual Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept = 0; - virtual Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) = 0; + virtual Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept = 0; - Error write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile); + Error write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept; - virtual Result stat(uint64_t inode) = 0; + virtual Result stat(uint64_t inode) noexcept = 0; - virtual Result stat(const char *path) = 0; + virtual Result stat(const char *path) noexcept = 0; - Result stat(FileAddress addr); + Result stat(FileAddress addr) noexcept; - [[nodiscard]] virtual uint64_t spaceNeeded(uint64_t size) = 0; + [[nodiscard]] + virtual uint64_t spaceNeeded(uint64_t size) noexcept = 0; - [[nodiscard]] virtual Result available() = 0; + [[nodiscard]] + virtual Result available() noexcept = 0; - [[nodiscard]] virtual Result size() const = 0; + [[nodiscard]] + virtual Result size() const noexcept = 0; - [[nodiscard]] virtual char *buff() = 0; + [[nodiscard]] + virtual char *buff() noexcept = 0; - virtual Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) = 0; + virtual Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) noexcept = 0; - [[nodiscard]] virtual bool valid() const = 0; + [[nodiscard]] + virtual bool valid() const noexcept = 0; }; @@ -107,51 +112,51 @@ class FileSystemTemplate: public FileSystem { static Error format(void *buff, uint64_t buffSize); - Error mkdir(const char *path, bool recursive = false) override; + Error mkdir(const char *path, bool recursive = false) noexcept override; - Error move(const char *src, const char *dest) override; + Error move(const char *src, const char *dest) noexcept override; - Error read(const char *path, void *buffer, std::size_t buffSize) override; + Error read(const char *path, void *buffer, std::size_t buffSize) noexcept override; - Result read(const char*) override; + Result read(const char*) noexcept override; - Error read(uint64_t inode, void *buffer, std::size_t size) override; + Error read(uint64_t inode, void *buffer, std::size_t size) noexcept override; - Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) override; + Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override; - Result read(uint64_t) override; + Result read(uint64_t) noexcept override; template - Error ls(const char *dir, F cb); + Error ls(const char *dir, F cb) noexcept; - Error remove(const char *path, bool recursive = false) override; + Error remove(const char *path, bool recursive = false) noexcept override; /** * Resizes FileSystem to minimum possible size. */ - Error resize(); + Error resize() noexcept; - Error resize(uint64_t size, void *buffer = nullptr) override; + Error resize(uint64_t size, void *buffer = nullptr) noexcept override; - Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; + Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept override; - Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; + Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept override; - Result stat(uint64_t inode) override; + Result stat(uint64_t inode) noexcept override; - Result stat(const char *path) override; + Result stat(const char *path) noexcept override; - uint64_t spaceNeeded(uint64_t size) override; + uint64_t spaceNeeded(uint64_t size) noexcept override; - Result available() override; + Result available() noexcept override; - Result size() const override; + Result size() const noexcept override; - char *buff() override; + char *buff() noexcept override; - Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) override; + Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) noexcept override; - bool valid() const override; + bool valid() const noexcept override; private: Result fileSystemData() const noexcept; @@ -206,7 +211,7 @@ Error FileSystemTemplate::format(void *buff, uint64_t buff } template -Error FileSystemTemplate::mkdir(const char *path, bool recursive) { +Error FileSystemTemplate::mkdir(const char *path, bool recursive) noexcept { oxTrace("ox::fs::FileSystemTemplate::mkdir") << "path:" << path << "recursive:" << recursive; auto rootDir = this->rootDir(); oxReturnError(rootDir.error); @@ -214,7 +219,7 @@ Error FileSystemTemplate::mkdir(const char *path, bool rec } template -Error FileSystemTemplate::move(const char *src, const char *dest) { +Error FileSystemTemplate::move(const char *src, const char *dest) noexcept { auto fd = fileSystemData(); oxReturnError(fd.error); Directory rootDir(m_fs, fd.value.rootDirInode); @@ -226,7 +231,7 @@ Error FileSystemTemplate::move(const char *src, const char } template -Error FileSystemTemplate::read(const char *path, void *buffer, std::size_t buffSize) { +Error FileSystemTemplate::read(const char *path, void *buffer, std::size_t buffSize) noexcept { auto fd = fileSystemData(); oxReturnError(fd.error); Directory rootDir(m_fs, fd.value.rootDirInode); @@ -236,7 +241,7 @@ Error FileSystemTemplate::read(const char *path, void *buf } template -Result FileSystemTemplate::read(const char *path) { +Result FileSystemTemplate::read(const char *path) noexcept { auto fd = fileSystemData(); oxReturnError(fd.error); Directory rootDir(m_fs, fd.value.rootDirInode); @@ -246,17 +251,17 @@ Result FileSystemTemplate::read(const char *path } template -Error FileSystemTemplate::read(uint64_t inode, void *buffer, std::size_t buffSize) { +Error FileSystemTemplate::read(uint64_t inode, void *buffer, std::size_t buffSize) noexcept { return m_fs.read(inode, buffer, buffSize); } template -Error FileSystemTemplate::read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) { +Error FileSystemTemplate::read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept { return m_fs.read(inode, readStart, readSize, reinterpret_cast(buffer), size); } template -Result FileSystemTemplate::read(uint64_t inode) { +Result FileSystemTemplate::read(uint64_t inode) noexcept { auto data = m_fs.read(inode); if (!data.valid()) { return OxError(1); @@ -266,7 +271,7 @@ Result FileSystemTemplate::read(uint64_t inode) template template -Error FileSystemTemplate::ls(const char *path, F cb) { +Error FileSystemTemplate::ls(const char *path, F cb) noexcept { oxTrace("ox::FileSystemTemplate::ls") << "path:" << path; auto [s, err] = stat(path); oxReturnError(err); @@ -275,7 +280,7 @@ Error FileSystemTemplate::ls(const char *path, F cb) { } template -Error FileSystemTemplate::remove(const char *path, bool recursive) { +Error FileSystemTemplate::remove(const char *path, bool recursive) noexcept { auto fd = fileSystemData(); oxReturnError(fd.error); Directory rootDir(m_fs, fd.value.rootDirInode); @@ -297,18 +302,18 @@ Error FileSystemTemplate::remove(const char *path, bool re } template -Error FileSystemTemplate::resize() { +Error FileSystemTemplate::resize() noexcept { return m_fs.resize(); } template -Error FileSystemTemplate::resize(uint64_t size, void *buffer) { +Error FileSystemTemplate::resize(uint64_t size, void *buffer) noexcept { oxReturnError(m_fs.resize(size, buffer)); return OxError(0); } template -Error FileSystemTemplate::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) { +Error FileSystemTemplate::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) noexcept { auto [inode, err] = find(path); if (err) { auto generated = m_fs.generateInodeId(); @@ -323,12 +328,12 @@ Error FileSystemTemplate::write(const char *path, void *bu } template -Error FileSystemTemplate::write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType) { +Error FileSystemTemplate::write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType) noexcept { return m_fs.write(inode, buffer, size, fileType); } template -Result FileSystemTemplate::stat(uint64_t inode) { +Result FileSystemTemplate::stat(uint64_t inode) noexcept { auto s = m_fs.stat(inode); FileStat out; out.inode = s.value.inode; @@ -339,7 +344,7 @@ Result FileSystemTemplate::stat(uint64_t inode) } template -Result FileSystemTemplate::stat(const char *path) { +Result FileSystemTemplate::stat(const char *path) noexcept { auto inode = find(path); if (inode.error) { return {{}, inode.error}; @@ -348,32 +353,32 @@ Result FileSystemTemplate::stat(const char *path } template -uint64_t FileSystemTemplate::spaceNeeded(uint64_t size) { +uint64_t FileSystemTemplate::spaceNeeded(uint64_t size) noexcept { return m_fs.spaceNeeded(size); } template -Result FileSystemTemplate::available() { +Result FileSystemTemplate::available() noexcept { return m_fs.available(); } template -Result FileSystemTemplate::size() const { +Result FileSystemTemplate::size() const noexcept { return m_fs.size(); } template -char *FileSystemTemplate::buff() { +char *FileSystemTemplate::buff() noexcept { return m_fs.buff(); } template -Error FileSystemTemplate::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) { +Error FileSystemTemplate::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) noexcept { return m_fs.walk(cb); } template -bool FileSystemTemplate::valid() const { +bool FileSystemTemplate::valid() const noexcept { return m_fs.valid(); } diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp index d60e9404..3933d8f8 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.cpp @@ -25,7 +25,7 @@ ox::String PassThroughFS::basePath() { return m_path.string().c_str(); } -Error PassThroughFS::mkdir(const char *path, bool recursive) { +Error PassThroughFS::mkdir(const char *path, bool recursive) noexcept { bool success = false; const auto p = m_path / stripSlash(path); const auto u8p = p.u8string(); @@ -48,7 +48,7 @@ Error PassThroughFS::mkdir(const char *path, bool recursive) { return OxError(success ? 0 : 1); } -Error PassThroughFS::move(const char *src, const char *dest) { +Error PassThroughFS::move(const char *src, const char *dest) noexcept { std::error_code ec; std::filesystem::rename(m_path / stripSlash(src), m_path / stripSlash(dest), ec); if (ec.value()) { @@ -57,7 +57,7 @@ Error PassThroughFS::move(const char *src, const char *dest) { return OxError(0); } -Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize) { +Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize) noexcept { try { std::ifstream file((m_path / stripSlash(path)), std::ios::binary | std::ios::ate); const std::size_t size = file.tellg(); @@ -74,25 +74,25 @@ Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize) return OxError(0); } -Result PassThroughFS::read(const char*) { +Result PassThroughFS::read(const char*) noexcept { return OxError(1); } -Error PassThroughFS::read(uint64_t, void*, std::size_t) { +Error PassThroughFS::read(uint64_t, void*, std::size_t) noexcept { // unsupported return OxError(1); } -Error PassThroughFS::read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) { +Error PassThroughFS::read(uint64_t, std::size_t, std::size_t, void*, std::size_t*) noexcept { // unsupported return OxError(1); } -Result PassThroughFS::read(uint64_t) { +Result PassThroughFS::read(uint64_t) noexcept { return OxError(1); } -Error PassThroughFS::remove(const char *path, bool recursive) { +Error PassThroughFS::remove(const char *path, bool recursive) noexcept { if (recursive) { return OxError(std::filesystem::remove_all(m_path / stripSlash(path)) != 0); } else { @@ -100,12 +100,12 @@ Error PassThroughFS::remove(const char *path, bool recursive) { } } -Error PassThroughFS::resize(uint64_t, void*) { +Error PassThroughFS::resize(uint64_t, void*) noexcept { // unsupported return OxError(1); } -Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_t) { +Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_t) noexcept { auto p = (m_path / stripSlash(path)); try { std::ofstream f(p, std::ios::binary); @@ -117,17 +117,17 @@ Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_ return OxError(0); } -Error PassThroughFS::write(uint64_t, void*, uint64_t, uint8_t) { +Error PassThroughFS::write(uint64_t, void*, uint64_t, uint8_t) noexcept { // unsupported return OxError(1); } -Result PassThroughFS::stat(uint64_t) { +Result PassThroughFS::stat(uint64_t) noexcept { // unsupported return OxError(1); } -Result PassThroughFS::stat(const char *path) { +Result PassThroughFS::stat(const char *path) noexcept { std::error_code ec; const auto p = m_path / stripSlash(path); uint8_t type = std::filesystem::is_directory(p, ec) ? @@ -139,33 +139,33 @@ Result PassThroughFS::stat(const char *path) { return {{0, 0, size, type}, OxError(ec.value())}; } -uint64_t PassThroughFS::spaceNeeded(uint64_t size) { +uint64_t PassThroughFS::spaceNeeded(uint64_t size) noexcept { return size; } -Result PassThroughFS::available() { +Result PassThroughFS::available() noexcept { std::error_code ec; auto s = std::filesystem::space(m_path, ec); oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); return s.available; } -Result PassThroughFS::size() const { +Result PassThroughFS::size() const noexcept { std::error_code ec; auto s = std::filesystem::space(m_path, ec); oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size")); return s.capacity; } -char *PassThroughFS::buff() { +char *PassThroughFS::buff() noexcept { return nullptr; } -Error PassThroughFS::walk(Error(*)(uint8_t, uint64_t, uint64_t)) { +Error PassThroughFS::walk(Error(*)(uint8_t, uint64_t, uint64_t)) noexcept { return OxError(1); } -bool PassThroughFS::valid() const { +bool PassThroughFS::valid() const noexcept { std::error_code ec; auto out = std::filesystem::is_directory(m_path, ec); if (!ec.value()) { @@ -174,7 +174,7 @@ bool PassThroughFS::valid() const { return false; } -const char *PassThroughFS::stripSlash(const char *path) { +const char *PassThroughFS::stripSlash(const char *path) noexcept { auto pathLen = ox_strlen(path); for (decltype(pathLen) i = 0; i < pathLen && path[0] == '/'; i++) { path++; diff --git a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp index 7e7fc517..37524889 100644 --- a/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp +++ b/deps/ox/src/ox/fs/filesystem/passthroughfs.hpp @@ -39,57 +39,57 @@ class PassThroughFS: public FileSystem { [[nodiscard]] ox::String basePath(); - Error mkdir(const char *path, bool recursive = false) override; + Error mkdir(const char *path, bool recursive = false) noexcept override; - Error move(const char *src, const char *dest) override; + Error move(const char *src, const char *dest) noexcept override; - Error read(const char *path, void *buffer, std::size_t buffSize) override; + Error read(const char *path, void *buffer, std::size_t buffSize) noexcept override; - Result read(const char*) override; + Result read(const char*) noexcept override; - Error read(uint64_t inode, void *buffer, std::size_t size) override; + Error read(uint64_t inode, void *buffer, std::size_t size) noexcept override; - Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) override; + Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) noexcept override; - Result read(uint64_t) override; + Result read(uint64_t) noexcept override; template - Error ls(const char *dir, F cb); + Error ls(const char *dir, F cb) noexcept; - Error remove(const char *path, bool recursive = false) override; + Error remove(const char *path, bool recursive = false) noexcept override; - Error resize(uint64_t size, void *buffer = nullptr) override; + Error resize(uint64_t size, void *buffer = nullptr) noexcept override; - Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; + Error write(const char *path, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept override; - Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override; + Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) noexcept override; - Result stat(uint64_t inode) override; + Result stat(uint64_t inode) noexcept override; - Result stat(const char *path) override; + Result stat(const char *path) noexcept override; - uint64_t spaceNeeded(uint64_t size) override; + uint64_t spaceNeeded(uint64_t size) noexcept override; - Result available() override; + Result available() noexcept override; - Result size() const override; + Result size() const noexcept override; - char *buff() override; + char *buff() noexcept override; - Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) override; + Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) noexcept override; - bool valid() const override; + bool valid() const noexcept override; private: /** * Strips the leading slashes from a string. */ - const char *stripSlash(const char *path); + const char *stripSlash(const char *path) noexcept; }; template -Error PassThroughFS::ls(const char *dir, F cb) { +Error PassThroughFS::ls(const char *dir, F cb) noexcept { std::error_code ec; const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec); oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed"));