From 7199e74aa22e592a3b77bdd81f735edca5470596 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 20 Jan 2024 17:59:40 -0500 Subject: update --- kernel/vfile.cpp | 85 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 43 deletions(-) (limited to 'kernel/vfile.cpp') diff --git a/kernel/vfile.cpp b/kernel/vfile.cpp index 74cfbf9..028db6d 100644 --- a/kernel/vfile.cpp +++ b/kernel/vfile.cpp @@ -63,7 +63,7 @@ namespace hilbert::kernel::vfile { else { utility::string segment(str, segment_len); - out.segments.add_end(std::move(segment)); + out.segments.add_end(utility::move(segment)); } str += to_skip; @@ -80,9 +80,7 @@ namespace hilbert::kernel::vfile { return _result; \ } - storage::fs_result vfile::follow_symlinks( - const vfile &root, std::optional &out - ) const { + storage::fs_result vfile::follow_symlinks(vfile &out) const { if (dir_entry.type != storage::file_type::symlink) { out = *this; @@ -95,37 +93,33 @@ namespace hilbert::kernel::vfile { full_path.parent(); full_path.rel(target_path); - std::optional next; - RET_NOT_SUC(lookup_path(root, full_path, next)) - if (!next) { - out = {}; - return storage::fs_result::success; - } + vfile next; + RET_NOT_SUC(lookup_path(full_path, next)) - next->path = path; - return next->follow_symlinks(root, out); + next.path = path; + return next.follow_symlinks(out); } storage::fs_result vfile::get_child( - std::optional &out, const utility::string &name + vfile &out, const utility::string &name ) const { - std::optional entry; + storage::dir_entry entry; storage::directory_iter_t iter; RET_NOT_SUC(bd->mounted_as->get_first_child(dir_entry.node, entry, iter)) - while (entry) { + while (true) { - if (entry->name == name) { + if (entry.name == name) { vfile vf; vf.bd = bd; - vf.dir_entry = std::move(*entry); + vf.dir_entry = utility::move(entry); vf.path = path; vf.path.segments.add_end(name); - out = std::move(vf); + out = utility::move(vf); return storage::fs_result::success; } @@ -134,33 +128,37 @@ namespace hilbert::kernel::vfile { } - out = {}; - return storage::fs_result::success; - } storage::fs_result vfile::get_children(utility::vector &out) const { - std::optional entry; + storage::dir_entry entry; storage::directory_iter_t iter; - RET_NOT_SUC(bd->mounted_as->get_first_child(dir_entry.node, entry, iter)) + storage::fs_result result = + bd->mounted_as->get_first_child(dir_entry.node, entry, iter); + if (result == storage::fs_result::does_not_exist) + return storage::fs_result::success; + else if (result != storage::fs_result::success) + return result; - while (entry) { + while (true) { vfile vf; vf.bd = bd; vf.path = path; - vf.path.segments.add_end(entry->name); - vf.dir_entry = std::move(*entry); - out.add_end(std::move(vf)); + vf.path.segments.add_end(entry.name); + vf.dir_entry = utility::move(entry); + out.add_end(utility::move(vf)); - RET_NOT_SUC(bd->mounted_as->get_next_child(dir_entry.node, entry, iter)) + result = bd->mounted_as->get_next_child(dir_entry.node, entry, iter); + if (result == storage::fs_result::does_not_exist) + return storage::fs_result::success; + else if (result != storage::fs_result::success) + return result; } - return storage::fs_result::success; - } storage::fs_result vfile::read_file( @@ -170,25 +168,26 @@ namespace hilbert::kernel::vfile { dir_entry.node, start, length, into); } - storage::fs_result lookup_path( - const vfile &root, const canon_path &path, std::optional &out - ) { + //TODO: see comment at top of vfile.hpp. + static const vfile *root; + + void set_root(const vfile &root) { + kernel::vfile::root = new vfile(root); + } + + storage::fs_result lookup_path(const canon_path &path, vfile &out) { //assume path is absolute. - out = root; + out = *root; for (unsigned i = 0; i < path.segments.count; ++i) { - std::optional result; - RET_NOT_SUC(out->follow_symlinks(root, result)) - out = std::move(result); - if (!out) - return storage::fs_result::success; + vfile result; + RET_NOT_SUC(out.follow_symlinks(result)) + out = utility::move(result); - RET_NOT_SUC(out->get_child(result, path.segments.buffer[i])) - out = std::move(result); - if (!out) - return storage::fs_result::success; + RET_NOT_SUC(out.get_child(result, path.segments.buffer[i])) + out = utility::move(result); } -- cgit v1.2.3