[ox/fs] Improve const-correctness of FileSystem
This commit is contained in:
parent
9ee7cd5d53
commit
f687134943
@ -110,20 +110,20 @@ class FileStoreTemplate {
|
|||||||
FsSize_t readSize, T *data,
|
FsSize_t readSize, T *data,
|
||||||
FsSize_t *size) const;
|
FsSize_t *size) const;
|
||||||
|
|
||||||
Result<StatInfo> stat(InodeId_t id);
|
Result<StatInfo> stat(InodeId_t id) const;
|
||||||
|
|
||||||
Error resize();
|
Error resize();
|
||||||
|
|
||||||
Error resize(std::size_t size, void *newBuff = nullptr);
|
Error resize(std::size_t size, void *newBuff = nullptr);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
InodeId_t spaceNeeded(FsSize_t size);
|
InodeId_t spaceNeeded(FsSize_t size) const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
InodeId_t size() const;
|
InodeId_t size() const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
InodeId_t available();
|
InodeId_t available() const;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
char *buff();
|
char *buff();
|
||||||
@ -414,7 +414,7 @@ Error FileStoreTemplate<size_t>::resize(std::size_t size, void *newBuff) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) const {
|
||||||
oxRequire(inode, find(id).validate());
|
oxRequire(inode, find(id).validate());
|
||||||
return StatInfo {
|
return StatInfo {
|
||||||
id,
|
id,
|
||||||
@ -425,7 +425,7 @@ Result<StatInfo> FileStoreTemplate<size_t>::stat(InodeId_t id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
typename FileStoreTemplate<size_t>::InodeId_t FileStoreTemplate<size_t>::spaceNeeded(FsSize_t size) {
|
typename FileStoreTemplate<size_t>::InodeId_t FileStoreTemplate<size_t>::spaceNeeded(FsSize_t size) const {
|
||||||
return m_buffer->spaceNeeded(size);
|
return m_buffer->spaceNeeded(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ typename FileStoreTemplate<size_t>::InodeId_t FileStoreTemplate<size_t>::size()
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
typename FileStoreTemplate<size_t>::InodeId_t FileStoreTemplate<size_t>::available() {
|
typename FileStoreTemplate<size_t>::InodeId_t FileStoreTemplate<size_t>::available() const {
|
||||||
return m_buffer->available();
|
return m_buffer->available();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
4
deps/ox/src/ox/fs/filesystem/filesystem.cpp
vendored
@ -56,7 +56,7 @@ Error FileSystem::read(const FileAddress &addr, std::size_t readStart, std::size
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Vector<String>> FileSystem::ls(const String &dir) noexcept {
|
Result<Vector<String>> FileSystem::ls(const String &dir) const noexcept {
|
||||||
return ls(dir.c_str());
|
return ls(dir.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ Error FileSystem::write(const FileAddress &addr, const void *buffer, uint64_t si
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileStat> FileSystem::stat(const FileAddress &addr) noexcept {
|
Result<FileStat> FileSystem::stat(const FileAddress &addr) const noexcept {
|
||||||
switch (addr.type()) {
|
switch (addr.type()) {
|
||||||
case FileAddressType::Inode:
|
case FileAddressType::Inode:
|
||||||
return stat(addr.getInode().value);
|
return stat(addr.getInode().value);
|
||||||
|
38
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
38
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@ -51,9 +51,9 @@ class FileSystem {
|
|||||||
[[maybe_unused]]
|
[[maybe_unused]]
|
||||||
Result<const char*> directAccess(const FileAddress &addr) noexcept;
|
Result<const char*> directAccess(const FileAddress &addr) noexcept;
|
||||||
|
|
||||||
Result<Vector<String>> ls(const String &dir) noexcept;
|
Result<Vector<String>> ls(const String &dir) const noexcept;
|
||||||
|
|
||||||
virtual Result<Vector<String>> ls(const char *dir) noexcept = 0;
|
virtual Result<Vector<String>> ls(const char *dir) const noexcept = 0;
|
||||||
|
|
||||||
virtual Error remove(const char *path, bool recursive) noexcept = 0;
|
virtual Error remove(const char *path, bool recursive) noexcept = 0;
|
||||||
|
|
||||||
@ -67,16 +67,16 @@ class FileSystem {
|
|||||||
|
|
||||||
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
|
Error write(const FileAddress &addr, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept;
|
||||||
|
|
||||||
virtual Result<FileStat> stat(uint64_t inode) noexcept = 0;
|
virtual Result<FileStat> stat(uint64_t inode) const noexcept = 0;
|
||||||
|
|
||||||
virtual Result<FileStat> stat(const char *path) noexcept = 0;
|
virtual Result<FileStat> stat(const char *path) const noexcept = 0;
|
||||||
|
|
||||||
Result<FileStat> stat(const FileAddress &addr) noexcept;
|
Result<FileStat> stat(const FileAddress &addr) const noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual uint64_t spaceNeeded(uint64_t size) noexcept = 0;
|
virtual uint64_t spaceNeeded(uint64_t size) const noexcept = 0;
|
||||||
|
|
||||||
virtual Result<uint64_t> available() noexcept = 0;
|
virtual Result<uint64_t> available() const noexcept = 0;
|
||||||
|
|
||||||
virtual Result<uint64_t> size() const noexcept = 0;
|
virtual Result<uint64_t> size() const noexcept = 0;
|
||||||
|
|
||||||
@ -133,10 +133,10 @@ class FileSystemTemplate: public FileSystem {
|
|||||||
|
|
||||||
Result<const char*> directAccess(uint64_t) noexcept override;
|
Result<const char*> directAccess(uint64_t) noexcept override;
|
||||||
|
|
||||||
Result<Vector<String>> ls(const char *path) noexcept override;
|
Result<Vector<String>> ls(const char *path) const noexcept override;
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Error ls(const char *path, F cb);
|
Error ls(const char *path, F cb) const;
|
||||||
|
|
||||||
Error remove(const char *path, bool recursive) noexcept override;
|
Error remove(const char *path, bool recursive) noexcept override;
|
||||||
|
|
||||||
@ -151,13 +151,13 @@ class FileSystemTemplate: public FileSystem {
|
|||||||
|
|
||||||
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept override;
|
||||||
|
|
||||||
Result<FileStat> stat(uint64_t inode) noexcept override;
|
Result<FileStat> stat(uint64_t inode) const noexcept override;
|
||||||
|
|
||||||
Result<FileStat> stat(const char *path) noexcept override;
|
Result<FileStat> stat(const char *path) const noexcept override;
|
||||||
|
|
||||||
uint64_t spaceNeeded(uint64_t size) noexcept override;
|
uint64_t spaceNeeded(uint64_t size) const noexcept override;
|
||||||
|
|
||||||
Result<uint64_t> available() noexcept override;
|
Result<uint64_t> available() const noexcept override;
|
||||||
|
|
||||||
Result<uint64_t> size() const noexcept override;
|
Result<uint64_t> size() const noexcept override;
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ Result<const char*> FileSystemTemplate<FileStore, Directory>::directAccess(uint6
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(const char *path) noexcept {
|
Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(const char *path) const noexcept {
|
||||||
Vector<String> out;
|
Vector<String> out;
|
||||||
oxReturnError(ls(path, [&out](const char *name, typename FileStore::InodeId_t) {
|
oxReturnError(ls(path, [&out](const char *name, typename FileStore::InodeId_t) {
|
||||||
out.emplace_back(name);
|
out.emplace_back(name);
|
||||||
@ -284,7 +284,7 @@ Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(const char *
|
|||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) {
|
Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) const {
|
||||||
oxTracef("ox::fs::FileSystemTemplate::ls", "path: {}", path);
|
oxTracef("ox::fs::FileSystemTemplate::ls", "path: {}", path);
|
||||||
oxRequire(s, stat(path));
|
oxRequire(s, stat(path));
|
||||||
Directory dir(m_fs, s.inode);
|
Directory dir(m_fs, s.inode);
|
||||||
@ -340,7 +340,7 @@ Error FileSystemTemplate<FileStore, Directory>::write(uint64_t inode, const void
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) noexcept {
|
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode) const noexcept {
|
||||||
oxRequire(s, m_fs.stat(inode));
|
oxRequire(s, m_fs.stat(inode));
|
||||||
FileStat out;
|
FileStat out;
|
||||||
out.inode = s.inode;
|
out.inode = s.inode;
|
||||||
@ -351,18 +351,18 @@ Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(uint64_t inode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) noexcept {
|
Result<FileStat> FileSystemTemplate<FileStore, Directory>::stat(const char *path) const noexcept {
|
||||||
oxRequire(inode, find(path));
|
oxRequire(inode, find(path));
|
||||||
return stat(inode);
|
return stat(inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
uint64_t FileSystemTemplate<FileStore, Directory>::spaceNeeded(uint64_t size) noexcept {
|
uint64_t FileSystemTemplate<FileStore, Directory>::spaceNeeded(uint64_t size) const noexcept {
|
||||||
return m_fs.spaceNeeded(size);
|
return m_fs.spaceNeeded(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename FileStore, typename Directory>
|
template<typename FileStore, typename Directory>
|
||||||
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::available() noexcept {
|
Result<uint64_t> FileSystemTemplate<FileStore, Directory>::available() const noexcept {
|
||||||
return m_fs.available();
|
return m_fs.available();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
10
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
@ -94,7 +94,7 @@ Result<const char*> PassThroughFS::directAccess(uint64_t) noexcept {
|
|||||||
return OxError(1, "PassThroughFS::directAccess not supported");
|
return OxError(1, "PassThroughFS::directAccess not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Vector<String>> PassThroughFS::ls(const char *dir) noexcept {
|
Result<Vector<String>> PassThroughFS::ls(const char *dir) const noexcept {
|
||||||
Vector<String> out;
|
Vector<String> out;
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
||||||
@ -136,12 +136,12 @@ Error PassThroughFS::write(uint64_t, const void*, uint64_t, FileType) noexcept {
|
|||||||
return OxError(1, "write(uint64_t, void*, uint64_t, uint8_t) is not supported by PassThroughFS");
|
return OxError(1, "write(uint64_t, void*, uint64_t, uint8_t) is not supported by PassThroughFS");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileStat> PassThroughFS::stat(uint64_t) noexcept {
|
Result<FileStat> PassThroughFS::stat(uint64_t) const noexcept {
|
||||||
// unsupported
|
// unsupported
|
||||||
return OxError(1, "stat(uint64_t) is not supported by PassThroughFS");
|
return OxError(1, "stat(uint64_t) is not supported by PassThroughFS");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileStat> PassThroughFS::stat(const char *path) noexcept {
|
Result<FileStat> PassThroughFS::stat(const char *path) const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto p = m_path / stripSlash(path);
|
const auto p = m_path / stripSlash(path);
|
||||||
const FileType type = std::filesystem::is_directory(p, ec) ?
|
const FileType type = std::filesystem::is_directory(p, ec) ?
|
||||||
@ -154,11 +154,11 @@ Result<FileStat> PassThroughFS::stat(const char *path) noexcept {
|
|||||||
return FileStat{0, 0, size, type};
|
return FileStat{0, 0, size, type};
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t PassThroughFS::spaceNeeded(uint64_t size) noexcept {
|
uint64_t PassThroughFS::spaceNeeded(uint64_t size) const noexcept {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<uint64_t> PassThroughFS::available() noexcept {
|
Result<uint64_t> PassThroughFS::available() const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto s = std::filesystem::space(m_path, ec);
|
const auto s = std::filesystem::space(m_path, ec);
|
||||||
oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size"));
|
oxReturnError(OxError(ec.value(), "PassThroughFS: could not get FS size"));
|
||||||
|
14
deps/ox/src/ox/fs/filesystem/passthroughfs.hpp
vendored
14
deps/ox/src/ox/fs/filesystem/passthroughfs.hpp
vendored
@ -51,10 +51,10 @@ class PassThroughFS: public FileSystem {
|
|||||||
|
|
||||||
Result<const char*> directAccess(uint64_t) noexcept override;
|
Result<const char*> directAccess(uint64_t) noexcept override;
|
||||||
|
|
||||||
Result<Vector<String>> ls(const char *dir) noexcept override;
|
Result<Vector<String>> ls(const char *dir) const noexcept override;
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Error ls(const char *dir, F cb) noexcept;
|
Error ls(const char *dir, F cb) const noexcept;
|
||||||
|
|
||||||
Error remove(const char *path, bool recursive = false) noexcept override;
|
Error remove(const char *path, bool recursive = false) noexcept override;
|
||||||
|
|
||||||
@ -64,13 +64,13 @@ class PassThroughFS: public FileSystem {
|
|||||||
|
|
||||||
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept override;
|
Error write(uint64_t inode, const void *buffer, uint64_t size, FileType fileType = FileType::NormalFile) noexcept override;
|
||||||
|
|
||||||
Result<FileStat> stat(uint64_t inode) noexcept override;
|
Result<FileStat> stat(uint64_t inode) const noexcept override;
|
||||||
|
|
||||||
Result<FileStat> stat(const char *path) noexcept override;
|
Result<FileStat> stat(const char *path) const noexcept override;
|
||||||
|
|
||||||
uint64_t spaceNeeded(uint64_t size) noexcept override;
|
uint64_t spaceNeeded(uint64_t size) const noexcept override;
|
||||||
|
|
||||||
Result<uint64_t> available() noexcept override;
|
Result<uint64_t> available() const noexcept override;
|
||||||
|
|
||||||
Result<uint64_t> size() const noexcept override;
|
Result<uint64_t> size() const noexcept override;
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ class PassThroughFS: public FileSystem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Error PassThroughFS::ls(const char *dir, F cb) noexcept {
|
Error PassThroughFS::ls(const char *dir, F cb) const noexcept {
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
const auto di = std::filesystem::directory_iterator(m_path / stripSlash(dir), ec);
|
||||||
oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed"));
|
oxReturnError(OxError(ec.value(), "PassThroughFS: ls failed"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user