summaryrefslogtreecommitdiff
path: root/kernel/vfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/vfile.cpp')
-rw-r--r--kernel/vfile.cpp85
1 files changed, 42 insertions, 43 deletions
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<vfile> &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<vfile> 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<vfile> &out, const utility::string &name
+ vfile &out, const utility::string &name
) const {
- std::optional<storage::dir_entry> 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<vfile> &out) const {
- std::optional<storage::dir_entry> 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<vfile> &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<vfile> 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);
}