[ox/fs] Cleanup
This commit is contained in:
77
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
77
deps/ox/src/ox/fs/filesystem/directory.hpp
vendored
@@ -55,7 +55,7 @@ struct OX_PACKED DirectoryEntry {
|
||||
}
|
||||
|
||||
ptrarith::Ptr<DirectoryEntryData, InodeId_t> data() {
|
||||
oxTrace("ox::fs::DirectoryEntry::data") << this->fullSize() << sizeof(*this) << this->size();
|
||||
oxTracef("ox::fs::DirectoryEntry::data", "{} {} {}", this->fullSize(), sizeof(*this), this->size());
|
||||
return ptrarith::Ptr<DirectoryEntryData, InodeId_t>(this, this->fullSize(), sizeof(*this), this->size(), this->size());
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ Directory<FileStore, InodeId_t>::Directory(FileStore fs, InodeId_t inodeId) {
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
Error Directory<FileStore, InodeId_t>::init() noexcept {
|
||||
constexpr auto Size = sizeof(Buffer);
|
||||
oxTrace("ox::fs::Directory::init") << "Initializing Directory with Inode ID:" << m_inodeId;
|
||||
oxTracef("ox::fs::Directory::init", "Initializing Directory with Inode ID: {}", m_inodeId);
|
||||
oxReturnError(m_fs.write(m_inodeId, nullptr, Size, static_cast<uint8_t>(FileType::Directory)));
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
@@ -147,7 +147,7 @@ Error Directory<FileStore, InodeId_t>::init() noexcept {
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, FileName *nameBuff) {
|
||||
if (path.valid()) {
|
||||
oxTrace("ox::fs::Directory::mkdir") << path.fullPath();
|
||||
oxTrace("ox::fs::Directory::mkdir", path.fullPath());
|
||||
// reuse nameBuff if it has already been allocated, as it is a rather large variable
|
||||
if (nameBuff == nullptr) {
|
||||
nameBuff = new (ox_alloca(sizeof(FileName))) FileName;
|
||||
@@ -164,7 +164,7 @@ Error Directory<FileStore, InodeId_t>::mkdir(PathIterator path, bool parents, Fi
|
||||
return OxError(1);
|
||||
}
|
||||
childInode = m_fs.generateInodeId();
|
||||
oxTrace("ox::fs::Directory::mkdir") << "Generated Inode ID:" << childInode.value;
|
||||
oxTracef("ox::fs::Directory::mkdir", "Generated Inode ID: {}", childInode.value);
|
||||
oxLogError(childInode.error);
|
||||
oxReturnError(childInode.error);
|
||||
|
||||
@@ -199,38 +199,34 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode,
|
||||
|
||||
if (path.next().hasNext()) { // not yet at target directory, recurse to next one
|
||||
oxReturnError(path.get(name));
|
||||
|
||||
oxTrace("ox::fs::Directory::write") << "Attempting to write to next sub-Directory: "
|
||||
<< name->c_str() << " of " << path.fullPath();
|
||||
|
||||
oxTracef("ox::fs::Directory::write", "Attempting to write to next sub-Directory: {} of {}",
|
||||
name->c_str(), path.fullPath());
|
||||
oxRequire(nextChild, findEntry(*name));
|
||||
oxTrace("ox::fs::Directory::write") << name->c_str() << ": " << nextChild;
|
||||
|
||||
oxTracef("ox::fs::Directory::write", "{}: {}", name->c_str(), nextChild);
|
||||
if (nextChild) {
|
||||
// reuse name because it is a rather large variable and will not be used again
|
||||
// be attentive that this remains true
|
||||
name = nullptr;
|
||||
return Directory(m_fs, nextChild).write(path.next(), inode, nameBuff);
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::write") << name->c_str()
|
||||
<< "not found and not allowed to create it.";
|
||||
return OxError(1);
|
||||
oxTracef("ox::fs::Directory::write", "{} not found and not allowed to create it.", name->c_str());
|
||||
return OxError(1, "File not found and not allowed to create it.");
|
||||
}
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::write") << path.fullPath();
|
||||
oxTrace("ox::fs::Directory::write", path.fullPath());
|
||||
// insert the new entry on this directory
|
||||
|
||||
// get the name
|
||||
oxReturnError(path.next(name));
|
||||
|
||||
// find existing version of directory
|
||||
oxTrace("ox::fs::Directory::write") << "Searching for directory inode" << m_inodeId;
|
||||
oxTracef("ox::fs::Directory::write", "Searching for directory inode {}", m_inodeId);
|
||||
oxRequire(oldStat, m_fs.stat(m_inodeId));
|
||||
oxTrace("ox::fs::Directory::write") << "Found existing directory of size" << oldStat.size;
|
||||
oxTracef("ox::fs::Directory::write", "Found existing directory of size {}", oldStat.size);
|
||||
auto old = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!old.valid()) {
|
||||
oxTrace("ox::fs::Directory::write::fail") << "Could not read existing version of Directory";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::write::fail", "Could not read existing version of Directory");
|
||||
return OxError(1, "Could not read existing version of Directory");
|
||||
}
|
||||
|
||||
const auto pathSize = name->len() + 1;
|
||||
@@ -238,20 +234,19 @@ Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t inode,
|
||||
const auto newSize = oldStat.size + Buffer::spaceNeeded(entryDataSize);
|
||||
auto cpy = ox_malloca(newSize, Buffer, *old, oldStat.size);
|
||||
if (cpy == nullptr) {
|
||||
oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for copy of Directory";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::write::fail", "Could not allocate memory for copy of Directory");
|
||||
return OxError(1, "Could not allocate memory for copy of Directory");
|
||||
}
|
||||
|
||||
// TODO: look for old version of this entry and delete it
|
||||
oxReturnError(cpy->setSize(newSize));
|
||||
auto val = cpy->malloc(entryDataSize);
|
||||
if (!val.valid()) {
|
||||
oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for new directory entry";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::write::fail", "Could not allocate memory for new directory entry");
|
||||
return OxError(1, "Could not allocate memory for new directory entry");
|
||||
}
|
||||
|
||||
oxTrace("ox::fs::Directory::write") << "Attempting to write Directory entry:" << name->data();
|
||||
oxTrace("ox::fs::Directory::write") << "Attempting to write Directory to FileStore";
|
||||
oxTracef("ox::fs::Directory::write", "Attempting to write Directory entry: {}", name->data());
|
||||
oxReturnError(val->init(inode, name->data(), val.size()));
|
||||
return m_fs.write(m_inodeId, cpy, cpy->size(), static_cast<uint8_t>(FileType::Directory));
|
||||
}
|
||||
@@ -266,10 +261,10 @@ Error Directory<FileStore, InodeId_t>::remove(PathIterator path, FileName *nameB
|
||||
auto &name = *nameBuff;
|
||||
oxReturnError(path.get(&name));
|
||||
|
||||
oxTrace("ox::fs::Directory::remove") << name.c_str();
|
||||
oxTrace("ox::fs::Directory::remove", name.c_str());
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (buff.valid()) {
|
||||
oxTrace("ox::fs::Directory::remove") << "Found directory buffer.";
|
||||
oxTrace("ox::fs::Directory::remove", "Found directory buffer.");
|
||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||
auto data = i->data();
|
||||
if (data.valid()) {
|
||||
@@ -277,12 +272,12 @@ Error Directory<FileStore, InodeId_t>::remove(PathIterator path, FileName *nameB
|
||||
oxReturnError(buff->free(i));
|
||||
}
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::remove") << "INVALID DIRECTORY ENTRY";
|
||||
oxTrace("ox::fs::Directory::remove", "INVALID DIRECTORY ENTRY");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::remove::fail") << "Could not find directory buffer";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::remove::fail", "Could not find directory buffer");
|
||||
return OxError(1, "Could not find directory buffer");
|
||||
}
|
||||
return OxError(0);
|
||||
}
|
||||
@@ -293,17 +288,17 @@ Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
|
||||
oxTrace("ox::fs::Directory::ls");
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
oxTrace("ox::fs::Directory::ls::fail") << "Could not directory buffer";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::ls::fail", "Could not directory buffer");
|
||||
return OxError(1, "Could not directory buffer");
|
||||
}
|
||||
|
||||
oxTrace("ox::fs::Directory::ls") << "Found directory buffer.";
|
||||
oxTrace("ox::fs::Directory::ls", "Found directory buffer.");
|
||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||
auto data = i->data();
|
||||
if (data.valid()) {
|
||||
oxReturnError(cb(data->name, data->inode));
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::ls") << "INVALID DIRECTORY ENTRY";
|
||||
oxTrace("ox::fs::Directory::ls", "INVALID DIRECTORY ENTRY");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,27 +307,27 @@ Error Directory<FileStore, InodeId_t>::ls(F cb) noexcept {
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
Result<typename FileStore::InodeId_t> Directory<FileStore, InodeId_t>::findEntry(const FileName &name) const noexcept {
|
||||
oxTrace("ox::fs::Directory::findEntry") << name.c_str();
|
||||
oxTrace("ox::fs::Directory::findEntry", name.c_str());
|
||||
auto buff = m_fs.read(m_inodeId).template to<Buffer>();
|
||||
if (!buff.valid()) {
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Could not findEntry directory buffer";
|
||||
return OxError(2);
|
||||
oxTrace("ox::fs::Directory::findEntry::fail", "Could not findEntry directory buffer");
|
||||
return OxError(2, "Could not findEntry directory buffer");
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry") << "Found directory buffer, size:" << buff.size();
|
||||
oxTracef("ox::fs::Directory::findEntry", "Found directory buffer, size: {}", buff.size());
|
||||
for (auto i = buff->iterator(); i.valid(); i.next()) {
|
||||
auto data = i->data();
|
||||
if (data.valid()) {
|
||||
oxTrace("ox::fs::Directory::findEntry").del("") << "Comparing \"" << name.c_str() << "\" to \"" << data->name << "\"";
|
||||
oxTracef("ox::fs::Directory::findEntry", "Comparing \"{}\" to \"{}\"", name.c_str(), data->name);
|
||||
if (ox_strncmp(data->name, name.c_str(), MaxFileNameLength) == 0) {
|
||||
oxTrace("ox::fs::Directory::findEntry").del("") << "\"" << name.c_str() << "\" match found.";
|
||||
oxTracef("ox::fs::Directory::findEntry", "\"{}\" match found.", name.c_str());
|
||||
return static_cast<InodeId_t>(data->inode);
|
||||
}
|
||||
} else {
|
||||
oxTrace("ox::fs::Directory::findEntry") << "INVALID DIRECTORY ENTRY";
|
||||
}
|
||||
}
|
||||
oxTrace("ox::fs::Directory::findEntry::fail") << "Entry not present";
|
||||
return OxError(1);
|
||||
oxTrace("ox::fs::Directory::findEntry::fail", "Entry not present");
|
||||
return OxError(1, "Entry not present");
|
||||
}
|
||||
|
||||
template<typename FileStore, typename InodeId_t>
|
||||
|
@@ -49,7 +49,7 @@ FileAddress::~FileAddress() noexcept {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
const FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
cleanup();
|
||||
m_type = other.m_type;
|
||||
switch (m_type) {
|
||||
@@ -70,7 +70,7 @@ const FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
return *this;
|
||||
}
|
||||
|
||||
const FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
|
||||
FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
|
||||
cleanup();
|
||||
m_type = other.m_type;
|
||||
memcpy(this, &other, sizeof(*this));
|
||||
|
@@ -58,9 +58,9 @@ class FileAddress {
|
||||
|
||||
~FileAddress() noexcept;
|
||||
|
||||
const FileAddress &operator=(const FileAddress &other) noexcept;
|
||||
FileAddress &operator=(const FileAddress &other) noexcept;
|
||||
|
||||
const FileAddress &operator=(FileAddress &&other) noexcept;
|
||||
FileAddress &operator=(FileAddress &&other) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr FileAddressType type() const noexcept {
|
||||
|
8
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
8
deps/ox/src/ox/fs/filesystem/filesystem.hpp
vendored
@@ -209,11 +209,11 @@ Error FileSystemTemplate<FileStore, Directory>::format(void *buff, uint64_t buff
|
||||
|
||||
FileSystemData fd;
|
||||
fd.rootDirInode = rootDirInode;
|
||||
oxTrace("ox::fs::FileSystemTemplate::format") << "rootDirInode:" << fd.rootDirInode;
|
||||
oxTracef("ox::fs::FileSystemTemplate::format", "rootDirInode: {}", fd.rootDirInode.get());
|
||||
oxReturnError(fs.write(InodeFsData, &fd, sizeof(fd)));
|
||||
|
||||
if (!fs.read(fd.rootDirInode).valid()) {
|
||||
oxTrace("ox::fs::FileSystemTemplate::format::error") << "FileSystemTemplate::format did not correctly create root directory";
|
||||
oxTrace("ox::fs::FileSystemTemplate::format::error", "FileSystemTemplate::format did not correctly create root directory");
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ Result<Vector<String>> FileSystemTemplate<FileStore, Directory>::ls(const char *
|
||||
template<typename FileStore, typename Directory>
|
||||
template<typename F>
|
||||
Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) {
|
||||
oxTrace("ox::fs::FileSystemTemplate::ls") << "path:" << path;
|
||||
oxTracef("ox::fs::FileSystemTemplate::ls", "path: {}", path);
|
||||
oxRequire(s, stat(path));
|
||||
Directory dir(m_fs, s.inode);
|
||||
return dir.ls(cb);
|
||||
@@ -304,7 +304,7 @@ Error FileSystemTemplate<FileStore, Directory>::remove(const char *path, bool re
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
oxTrace("FileSystemTemplate::remove::fail") << "Tried to remove directory without recursive setting.";
|
||||
oxTrace("FileSystemTemplate::remove::fail", "Tried to remove directory without recursive setting.");
|
||||
return OxError(1);
|
||||
}
|
||||
return OxError(0);
|
||||
|
10
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
10
deps/ox/src/ox/fs/filesystem/passthroughfs.cpp
vendored
@@ -31,7 +31,7 @@ Error PassThroughFS::mkdir(const char *path, bool recursive) noexcept {
|
||||
bool success = false;
|
||||
const auto p = m_path / stripSlash(path);
|
||||
const auto u8p = p.u8string();
|
||||
oxTrace("ox::fs::PassThroughFS::mkdir") << u8p.c_str();
|
||||
oxTrace("ox::fs::PassThroughFS::mkdir", u8p.c_str());
|
||||
if (recursive) {
|
||||
std::error_code ec;
|
||||
const auto isDir = std::filesystem::is_directory(p, ec);
|
||||
@@ -65,7 +65,7 @@ Error PassThroughFS::read(const char *path, void *buffer, std::size_t buffSize)
|
||||
const std::size_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
if (size > buffSize) {
|
||||
oxTrace("ox::fs::PassThroughFS::read::error") << "Read failed: Buffer too small:" << path;
|
||||
oxTracef("ox::fs::PassThroughFS::read::error", "Read failed: Buffer too small: {}", path);
|
||||
return OxError(1);
|
||||
}
|
||||
file.read(static_cast<char*>(buffer), buffSize);
|
||||
@@ -146,10 +146,10 @@ Result<FileStat> PassThroughFS::stat(const char *path) noexcept {
|
||||
const auto p = m_path / stripSlash(path);
|
||||
const FileType type = std::filesystem::is_directory(p, ec) ?
|
||||
FileType::Directory : FileType::NormalFile;
|
||||
oxTrace("ox::fs::PassThroughFS::stat") << ec.message().c_str() << path;
|
||||
oxTracef("ox::fs::PassThroughFS::stat", "{} {}", ec.message().c_str(), path);
|
||||
const uint64_t size = type == FileType::Directory ? 0 : std::filesystem::file_size(p, ec);
|
||||
oxTrace("ox::fs::PassThroughFS::stat") << ec.message().c_str() << path;
|
||||
oxTrace("ox::fs::PassThroughFS::stat::size") << path << size;
|
||||
oxTracef("ox::fs::PassThroughFS::stat", "{} {}", ec.message().c_str(), path);
|
||||
oxTracef("ox::fs::PassThroughFS::stat::size", "{} {}", path, size);
|
||||
oxReturnError(OxError(ec.value()));
|
||||
return FileStat{0, 0, size, type};
|
||||
}
|
||||
|
@@ -61,11 +61,11 @@ Error PathIterator::fileName(char *out, std::size_t outSize) {
|
||||
Error PathIterator::get(char *pathOut, std::size_t pathOutSize) {
|
||||
std::size_t size = 0;
|
||||
if (m_iterator >= m_maxSize) {
|
||||
oxTrace("ox::fs::PathIterator::get") << "m_iterator >= m_maxSize";
|
||||
oxTracef("ox::fs::PathIterator::get", "m_iterator ({}) >= m_maxSize ({})", m_iterator, m_maxSize);
|
||||
return OxError(1);
|
||||
}
|
||||
if (!ox_strlen(&m_path[m_iterator])) {
|
||||
oxTrace("ox::fs::PathIterator::get") << "!ox_strlen(&m_path[m_iterator])";
|
||||
oxTrace("ox::fs::PathIterator::get", "!ox_strlen(&m_path[m_iterator])");
|
||||
return OxError(1);
|
||||
}
|
||||
auto start = m_iterator;
|
||||
|
@@ -61,12 +61,16 @@ class PathIterator {
|
||||
*/
|
||||
Result<std::size_t> nextSize() const;
|
||||
|
||||
[[nodiscard]]
|
||||
bool hasNext() const;
|
||||
|
||||
[[nodiscard]]
|
||||
bool valid() const;
|
||||
|
||||
[[nodiscard]] PathIterator next() const;
|
||||
[[nodiscard]]
|
||||
PathIterator next() const;
|
||||
|
||||
[[nodiscard]]
|
||||
const char *fullPath() const;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user