[ox] Rename ValErr to Result
This commit is contained in:
@@ -110,7 +110,7 @@ class FileStoreTemplate {
|
||||
FsSize_t readSize, T *data,
|
||||
FsSize_t *size) const;
|
||||
|
||||
ValErr<StatInfo> stat(InodeId_t id);
|
||||
Result<StatInfo> stat(InodeId_t id);
|
||||
|
||||
Error resize();
|
||||
|
||||
@@ -126,7 +126,7 @@ class FileStoreTemplate {
|
||||
|
||||
Error walk(Error(*cb)(uint8_t, uint64_t, uint64_t));
|
||||
|
||||
ValErr<InodeId_t> generateInodeId();
|
||||
Result<InodeId_t> generateInodeId();
|
||||
|
||||
bool valid() const;
|
||||
|
||||
@@ -435,17 +435,17 @@ Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
ValErr<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
||||
Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
||||
auto inode = find(id);
|
||||
if (inode.valid()) {
|
||||
return ValErr<StatInfo>({
|
||||
return Result<StatInfo>({
|
||||
id,
|
||||
inode->links,
|
||||
inode->size(),
|
||||
inode->fileType,
|
||||
});
|
||||
}
|
||||
return ValErr<StatInfo>({}, OxError(0));
|
||||
return Result<StatInfo>({}, OxError(0));
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
@@ -477,7 +477,7 @@ Error FileStoreTemplate<size_t>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) {
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
ValErr<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>::generateInodeId() {
|
||||
Result<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>::generateInodeId() {
|
||||
auto fsData = fileStoreData();
|
||||
if (fsData) {
|
||||
for (auto i = 0; i < 100; i++) {
|
||||
|
8
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
8
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@@ -113,9 +113,9 @@ class Directory {
|
||||
template<typename F>
|
||||
Error ls(F cb) noexcept;
|
||||
|
||||
ValErr<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept;
|
||||
Result<typename FileStore::InodeId_t> findEntry(const FileName &name) const noexcept;
|
||||
|
||||
ValErr<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept;
|
||||
Result<typename FileStore::InodeId_t> find(PathIterator name, FileName *nameBuff = nullptr) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
@@ -314,7 +314,7 @@ ox::Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
|
||||
}
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
|
||||
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
|
||||
oxTrace("ox::fs::Directory::findEntry") << name.c_str();
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
@@ -339,7 +339,7 @@ ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry
|
||||
}
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
ValErr<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path, FileName *nameBuff) const noexcept {
|
||||
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::find(PathIterator path, FileName *nameBuff) const noexcept {
|
||||
// reuse nameBuff if it has already been allocated, as it is a rather large variable
|
||||
if (nameBuff == nullptr) {
|
||||
nameBuff = reinterpret_cast<FileName*>(ox_alloca(sizeof(FileName)));
|
||||
|
@@ -68,7 +68,7 @@ class FileAddress {
|
||||
}
|
||||
}
|
||||
|
||||
ValErr<uint64_t> getInode() const noexcept {
|
||||
Result<uint64_t> getInode() const noexcept {
|
||||
switch (m_type) {
|
||||
case FileAddressType::Inode:
|
||||
return m_data.inode;
|
||||
@@ -77,7 +77,7 @@ class FileAddress {
|
||||
}
|
||||
}
|
||||
|
||||
ValErr<const char*> getPath() const noexcept {
|
||||
Result<const char*> getPath() const noexcept {
|
||||
switch (m_type) {
|
||||
case FileAddressType::Path:
|
||||
return m_data.path;
|
||||
|
4
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
4
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
ValErr<uint8_t*> FileSystem::read(FileAddress addr) {
|
||||
Result<uint8_t*> FileSystem::read(FileAddress addr) {
|
||||
switch (addr.type()) {
|
||||
case FileAddressType::Inode:
|
||||
return read(addr.getInode().value);
|
||||
@@ -70,7 +70,7 @@ ox::Error FileSystem::write(FileAddress addr, void *buffer, uint64_t size, uint8
|
||||
}
|
||||
}
|
||||
|
||||
ox::ValErr<FileStat> FileSystem::stat(FileAddress addr) {
|
||||
ox::Result<FileStat> FileSystem::stat(FileAddress addr) {
|
||||
switch (addr.type()) {
|
||||
case FileAddressType::Inode:
|
||||
return stat(addr.getInode().value);
|
||||
|
40
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
40
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@@ -32,19 +32,19 @@ class FileSystem {
|
||||
|
||||
virtual Error read(const char *path, void *buffer, std::size_t buffSize) = 0;
|
||||
|
||||
virtual ValErr<uint8_t*> read(const char *path) = 0;
|
||||
virtual Result<uint8_t*> read(const char *path) = 0;
|
||||
|
||||
virtual Error read(uint64_t inode, 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) = 0;
|
||||
|
||||
virtual ValErr<uint8_t*> read(uint64_t inode) = 0;
|
||||
virtual Result<uint8_t*> read(uint64_t inode) = 0;
|
||||
|
||||
Error read(FileAddress addr, void *buffer, std::size_t size);
|
||||
|
||||
Error read(FileAddress addr, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size);
|
||||
|
||||
ValErr<uint8_t*> read(FileAddress addr);
|
||||
Result<uint8_t*> read(FileAddress addr);
|
||||
|
||||
virtual Error remove(const char *path, bool recursive = false) = 0;
|
||||
|
||||
@@ -58,11 +58,11 @@ class FileSystem {
|
||||
|
||||
Error write(FileAddress addr, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile);
|
||||
|
||||
virtual ValErr<FileStat> stat(uint64_t inode) = 0;
|
||||
virtual Result<FileStat> stat(uint64_t inode) = 0;
|
||||
|
||||
virtual ValErr<FileStat> stat(const char *path) = 0;
|
||||
virtual Result<FileStat> stat(const char *path) = 0;
|
||||
|
||||
ValErr<FileStat> stat(FileAddress addr);
|
||||
Result<FileStat> stat(FileAddress addr);
|
||||
|
||||
[[nodiscard]] virtual uint64_t spaceNeeded(uint64_t size) = 0;
|
||||
|
||||
@@ -113,13 +113,13 @@ class FileSystemTemplate: public FileSystem {
|
||||
|
||||
Error read(const char *path, void *buffer, std::size_t buffSize) override;
|
||||
|
||||
ValErr<uint8_t*> read(const char*) override;
|
||||
Result<uint8_t*> read(const char*) override;
|
||||
|
||||
Error read(uint64_t inode, 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) override;
|
||||
|
||||
ValErr<uint8_t*> read(uint64_t) override;
|
||||
Result<uint8_t*> read(uint64_t) override;
|
||||
|
||||
template<typename F>
|
||||
Error ls(const char *dir, F cb);
|
||||
@@ -137,9 +137,9 @@ class FileSystemTemplate: public FileSystem {
|
||||
|
||||
Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override;
|
||||
|
||||
ValErr<FileStat> stat(uint64_t inode) override;
|
||||
Result<FileStat> stat(uint64_t inode) override;
|
||||
|
||||
ValErr<FileStat> stat(const char *path) override;
|
||||
Result<FileStat> stat(const char *path) override;
|
||||
|
||||
uint64_t spaceNeeded(uint64_t size) override;
|
||||
|
||||
@@ -154,14 +154,14 @@ class FileSystemTemplate: public FileSystem {
|
||||
bool valid() const override;
|
||||
|
||||
private:
|
||||
ValErr<FileSystemData> fileSystemData() const noexcept;
|
||||
Result<FileSystemData> fileSystemData() const noexcept;
|
||||
|
||||
/**
|
||||
* Finds the inode ID at the given path.
|
||||
*/
|
||||
ValErr<uint64_t> find(const char *path) const noexcept;
|
||||
Result<uint64_t> find(const char *path) const noexcept;
|
||||
|
||||
ValErr<Directory> rootDir() const noexcept;
|
||||
Result<Directory> rootDir() const noexcept;
|
||||
|
||||
};
|
||||
|
||||
@@ -236,7 +236,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(const char *path, void
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(const char *path) {
|
||||
Result<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(const char *path) {
|
||||
auto fd = fileSystemData();
|
||||
oxReturnError(fd.error);
|
||||
Directory rootDir(m_fs, fd.value.rootDirInode);
|
||||
@@ -256,7 +256,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(uint64_t inode, std::si
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(uint64_t inode) {
|
||||
Result<uint8_t*> FileSystemTemplate<FileStore, Directory>::read(uint64_t inode) {
|
||||
auto data = m_fs.read(inode);
|
||||
if (!data.valid()) {
|
||||
return OxError(1);
|
||||
@@ -328,7 +328,7 @@ ox::Error FileSystemTemplate<FileStore, Directory>::write(uint64_t inode, void *
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) {
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) {
|
||||
auto s = m_fs.stat(inode);
|
||||
FileStat out;
|
||||
out.inode = s.value.inode;
|
||||
@@ -339,7 +339,7 @@ ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode)
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) {
|
||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) {
|
||||
auto inode = find(path);
|
||||
if (inode.error) {
|
||||
return {{}, inode.error};
|
||||
@@ -378,7 +378,7 @@ bool FileSystemTemplate<FileStore, Directory>::valid() const {
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
||||
Result<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSystemTemplate<FileStore, Directory>::fileSystemData() const noexcept {
|
||||
FileSystemData fd;
|
||||
auto err = m_fs.read(InodeFsData, &fd, sizeof(fd));
|
||||
if (err != 0) {
|
||||
@@ -388,7 +388,7 @@ ValErr<typename FileSystemTemplate<FileStore, Directory>::FileSystemData> FileSy
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
|
||||
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path) const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {0, fd.error};
|
||||
@@ -406,7 +406,7 @@ ValErr<uint64_t> FileSystemTemplate<FileStore, Directory>::find(const char *path
|
||||
}
|
||||
|
||||
template<typename FileStore, typename Directory>
|
||||
ValErr<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
||||
Result<Directory> FileSystemTemplate<FileStore, Directory>::rootDir() const noexcept {
|
||||
auto fd = fileSystemData();
|
||||
if (fd.error) {
|
||||
return {{}, fd.error};
|
||||
|
@@ -64,7 +64,7 @@ Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize)
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
ValErr<uint8_t*> PassThroughFS::read(const char*) {
|
||||
Result<uint8_t*> PassThroughFS::read(const char*) {
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ Error PassThroughFS::read(uint64_t, std::size_t, std::size_t, void*, std::size_t
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
ValErr<uint8_t*> PassThroughFS::read(uint64_t) {
|
||||
Result<uint8_t*> PassThroughFS::read(uint64_t) {
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
@@ -112,12 +112,12 @@ Error PassThroughFS::write(uint64_t, void*, uint64_t, uint8_t) {
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
ValErr<FileStat> PassThroughFS::stat(uint64_t) {
|
||||
Result<FileStat> PassThroughFS::stat(uint64_t) {
|
||||
// unsupported
|
||||
return {{}, OxError(1)};
|
||||
}
|
||||
|
||||
ValErr<FileStat> PassThroughFS::stat(const char *path) {
|
||||
Result<FileStat> PassThroughFS::stat(const char *path) {
|
||||
std::error_code ec;
|
||||
const auto p = m_path / stripSlash(path);
|
||||
uint8_t type = std::filesystem::is_directory(p, ec) ?
|
||||
|
@@ -43,13 +43,13 @@ class PassThroughFS: public FileSystem {
|
||||
|
||||
ox::Error read(const char *path, void *buffer, std::size_t buffSize) override;
|
||||
|
||||
ox::ValErr<uint8_t*> read(const char*) override;
|
||||
ox::Result<uint8_t*> read(const char*) override;
|
||||
|
||||
ox::Error read(uint64_t inode, void *buffer, std::size_t size) override;
|
||||
|
||||
ox::Error read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) override;
|
||||
|
||||
ox::ValErr<uint8_t*> read(uint64_t) override;
|
||||
ox::Result<uint8_t*> read(uint64_t) override;
|
||||
|
||||
template<typename F>
|
||||
ox::Error ls(const char *dir, F cb);
|
||||
@@ -62,9 +62,9 @@ class PassThroughFS: public FileSystem {
|
||||
|
||||
ox::Error write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType = FileType_NormalFile) override;
|
||||
|
||||
ox::ValErr<FileStat> stat(uint64_t inode) override;
|
||||
ox::Result<FileStat> stat(uint64_t inode) override;
|
||||
|
||||
ox::ValErr<FileStat> stat(const char *path) override;
|
||||
ox::Result<FileStat> stat(const char *path) override;
|
||||
|
||||
uint64_t spaceNeeded(uint64_t size) override;
|
||||
|
||||
|
@@ -140,7 +140,7 @@ Error PathIterator::next(BString<MaxFileNameLength> *fileName) {
|
||||
return next(fileName->data(), fileName->cap());
|
||||
}
|
||||
|
||||
ValErr<std::size_t> PathIterator::nextSize() const {
|
||||
Result<std::size_t> PathIterator::nextSize() const {
|
||||
std::size_t size = 0;
|
||||
auto retval = OxError(1);
|
||||
auto it = m_iterator;
|
||||
|
@@ -59,7 +59,7 @@ class PathIterator {
|
||||
/**
|
||||
* @return 0 if no error
|
||||
*/
|
||||
ValErr<std::size_t> nextSize() const;
|
||||
Result<std::size_t> nextSize() const;
|
||||
|
||||
bool hasNext() const;
|
||||
|
||||
|
Reference in New Issue
Block a user