[ox/fs] Enforce error handling in Directory

This commit is contained in:
Gary Talent 2019-06-22 11:50:44 -05:00
parent 74d1bb08fe
commit baff558ff2
2 changed files with 19 additions and 24 deletions

View File

@ -41,11 +41,7 @@ struct __attribute__((packed)) DirectoryEntry {
public:
DirectoryEntry() = default;
DirectoryEntry(InodeId_t inode, const char *name, InodeId_t bufferSize) {
init(inode, name, bufferSize);
}
ox::Error init(InodeId_t inode, const char *name, InodeId_t bufferSize) {
[[nodiscard]] ox::Error init(InodeId_t inode, const char *name, InodeId_t bufferSize) {
m_bufferSize = bufferSize;
auto d = data();
if (d.valid()) {
@ -241,7 +237,7 @@ ox::Error Directory<FileStore, InodeId_t>::write(PathIterator path, InodeId_t in
auto val = cpy->malloc(entryDataSize);
if (val.valid()) {
oxTrace("ox::fs::Directory::write") << "Attempting to write Directory to FileStore";
val->init(inode, name->data(), entrySize);
oxReturnError(val->init(inode, name->data(), entrySize));
return m_fs.write(m_inodeId, cpy, cpy->size());
} else {
oxTrace("ox::fs::Directory::write::fail") << "Could not allocate memory for new directory entry";
@ -294,22 +290,22 @@ template<typename F>
ox::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") << "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::fail");
return OxError(1);
} else {
if (!buff.valid()) {
oxTrace("ox::fs::Directory::ls::fail") << "Could not directory buffer";
return OxError(2);
return OxError(1);
}
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";
}
}
return OxError(0);
}
template<typename FileStore, typename InodeId_t>

View File

@ -209,10 +209,9 @@ ox::Error FileSystemTemplate<FileStore, Directory>::read(uint64_t inode, std::si
template<typename FileStore, typename Directory>
template<typename F>
ox::Error FileSystemTemplate<FileStore, Directory>::ls(const char *path, F cb) {
auto s = stat(path);
oxReturnError(s.error);
Directory dir(m_fs, s.value.inode);
auto [s, err] = stat(path);
oxReturnError(err);
Directory dir(m_fs, s.inode);
return dir.ls(cb);
}