diff options
Diffstat (limited to 'kernel/storage/fs/tarfs.cpp')
-rw-r--r-- | kernel/storage/fs/tarfs.cpp | 102 |
1 files changed, 43 insertions, 59 deletions
diff --git a/kernel/storage/fs/tarfs.cpp b/kernel/storage/fs/tarfs.cpp index fb1eff8..5986f62 100644 --- a/kernel/storage/fs/tarfs.cpp +++ b/kernel/storage/fs/tarfs.cpp @@ -5,27 +5,25 @@ namespace hilbert::kernel::storage::fs { -#define BD_TO_FS(expr) \ - { \ - bd_result _result = expr; \ - if (_result == bd_result::out_of_bounds) \ - return fs_result::fs_corrupt; \ - if (_result == bd_result::device_error) \ - return fs_result::device_error; \ - } + #define BD_TO_FS(expr) \ + { \ + bd_result _result = expr; \ + if (_result == bd_result::out_of_bounds) \ + return fs_result::fs_corrupt; \ + if (_result == bd_result::device_error) \ + return fs_result::device_error; \ + } -#define FS_TO_FS(expr) \ - { \ - fs_result _result = expr; \ - if (_result != fs_result::success) \ - return _result; \ - } + #define FS_TO_FS(expr) \ + { \ + fs_result _result = expr; \ + if (_result != fs_result::success) \ + return _result; \ + } tarfs_instance::tarfs_instance(block_device *bd) : bd(bd) {} - fs_result tarfs_instance::next_node( - node_id_t node, std::optional<node_id_t> &out - ) { + fs_result tarfs_instance::next_node(node_id_t node, node_id_t &out) { uint64_t bytes; FS_TO_FS(read_num(node + 124, 12, bytes)) @@ -37,8 +35,7 @@ namespace hilbert::kernel::storage::fs { if (sector[i] != 0) return fs_result::success; - out = {}; - return fs_result::success; + return fs_result::does_not_exist; } @@ -84,7 +81,7 @@ namespace hilbert::kernel::storage::fs { } fs_result tarfs_instance::first_child_starting_at( - node_id_t parent, node_id_t start, std::optional<node_id_t> &out + node_id_t parent, node_id_t start, node_id_t &out ) { utility::string parent_full_name; @@ -93,9 +90,9 @@ namespace hilbert::kernel::storage::fs { utility::string child_full_name; out = start; - do { + while (true) { - FS_TO_FS(read_full_name(*out, child_full_name)) + FS_TO_FS(read_full_name(out, child_full_name)) if (child_full_name.count > parent_full_name.count && child_full_name.starts_with(parent_full_name) @@ -110,11 +107,9 @@ namespace hilbert::kernel::storage::fs { } next: - next_node(*out, out); + FS_TO_FS(next_node(out, out)) - } while (out); - - return fs_result::success; + } } @@ -171,7 +166,7 @@ namespace hilbert::kernel::storage::fs { BD_TO_FS(bd->read_bytes(node + 157, 100, target.buffer)) while (target.count < 100 && target.buffer[target.count] != '\0') ++target.count; - entry.target = std::move(target); + entry.target = utility::move(target); } return fs_result::success; @@ -181,64 +176,53 @@ namespace hilbert::kernel::storage::fs { fs_result tarfs_instance::get_root_node(node_id_t &out) { utility::string full_name; - std::optional<node_id_t> on = 0; + node_id_t on = 0; - do { + while (true) { - FS_TO_FS(read_full_name(*on, full_name)) + FS_TO_FS(read_full_name(on, full_name)) if (full_name.count == 2) { - out = *on; + out = on; return fs_result::success; } - next_node(*on, on); - - } while (on); + fs_result result = next_node(on, on); + if (result == fs_result::does_not_exist) + return fs_result::fs_corrupt; + FS_TO_FS(result) - return fs_result::fs_corrupt; + } } fs_result tarfs_instance::get_first_child( - node_id_t node, std::optional<dir_entry> &out, directory_iter_t &iter_out + node_id_t node, dir_entry &out, directory_iter_t &iter_out ) { - std::optional<node_id_t> child; + node_id_t child; FS_TO_FS(first_child_starting_at(node, 0, child)) - if (!child) { - out = {}; - return fs_result::success; - } dir_entry entry; - FS_TO_FS(get_dir_entry(*child, entry)) - out = std::move(entry); - iter_out = (directory_iter_t)*child; + FS_TO_FS(get_dir_entry(child, entry)) + out = utility::move(entry); + iter_out = (directory_iter_t)child; return fs_result::success; } fs_result tarfs_instance::get_next_child( - node_id_t node, std::optional<dir_entry> &out, directory_iter_t &iter + node_id_t node, dir_entry &out, directory_iter_t &iter ) { - std::optional<node_id_t> start; + node_id_t start; FS_TO_FS(next_node((node_id_t)iter, start)) - if (!start) { - out = {}; - return fs_result::success; - } - std::optional<node_id_t> child; - FS_TO_FS(first_child_starting_at(node, *start, child)) - if (!child) { - out = {}; - return fs_result::success; - } + node_id_t child; + FS_TO_FS(first_child_starting_at(node, start, child)) dir_entry entry; - FS_TO_FS(get_dir_entry(*child, entry)) - out = std::move(entry); - iter = (directory_iter_t)*child; + FS_TO_FS(get_dir_entry(child, entry)) + out = utility::move(entry); + iter = (directory_iter_t)child; return fs_result::success; } |