diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/entry.cpp | 45 | ||||
-rw-r--r-- | kernel/fs/tarfs.cpp | 9 | ||||
-rw-r--r-- | kernel/storage.cpp | 21 |
3 files changed, 49 insertions, 26 deletions
diff --git a/kernel/entry.cpp b/kernel/entry.cpp index fb85ad2..915bc8b 100644 --- a/kernel/entry.cpp +++ b/kernel/entry.cpp @@ -184,6 +184,30 @@ extern "C" [[noreturn]] void entry() { ; } +static void find_file(const char *path, size_t path_len) { + + storage::canon_path cp; + storage::canonize_path(path, path_len, cp); + + storage::block_device *bd; + storage::node_id_t node_id; + storage::canon_path cp_without_symlinks; + + if (storage::look_up_absolute_path(cp, bd, node_id, true, + cp_without_symlinks) != storage::io_result::success) { + terminal::put_string_sz("failed to look up "); + terminal::put_string(path, path_len); + terminal::put_string_sz(" in vfs."); + halt(); + } + + terminal::put_string(path, path_len); + terminal::put_string_sz(" has node id "); + terminal::put_int_decimal(node_id); + terminal::put_string_sz(" in its file system.\n"); + +} + [[noreturn]] static void with_kernel_p4() { terminal::init_terminal(); @@ -211,23 +235,10 @@ extern "C" [[noreturn]] void entry() { terminal::put_int_decimal(free_pram_kib); terminal::put_string_sz(" kiB physical memory free.\n"); - storage::canon_path test_path; - storage::canonize_path("/test.txt", 9, test_path); - - storage::block_device *test_bd; - storage::node_id_t test_node_id; - storage::canon_path test_path_without_symlinks; - - if (storage::look_up_absolute_path( - test_path, test_bd, test_node_id, true, test_path_without_symlinks) != - storage::io_result::success) { - terminal::put_string_sz("failed to look up /test.txt in vfs."); - halt(); - } - - terminal::put_string_sz("/test.txt has node id "); - terminal::put_int_decimal(test_node_id); - terminal::put_string_sz(" in its file system."); + find_file("/", 1); + find_file("/test.txt", 9); + find_file("/dir", 4); + find_file("/dir/dir2", 9); halt(); diff --git a/kernel/fs/tarfs.cpp b/kernel/fs/tarfs.cpp index 706280e..7ab0de5 100644 --- a/kernel/fs/tarfs.cpp +++ b/kernel/fs/tarfs.cpp @@ -48,6 +48,8 @@ namespace mercury::kernel::fs { //len <= 12 char buffer[12]; storage::io_result result = bd->read_bytes(offset, len, buffer); + if (result != storage::io_result::success) + return result; out = 0; for (size_t i = 0; i < len; ++i) { @@ -134,7 +136,7 @@ namespace mercury::kernel::fs { char full_name[255]; size_t full_name_len; - RETURN_MAYBE_NOT_FOUND(read_name(out, full_name, full_name_len)) + RETURN_MAYBE_NOT_FOUND(read_name(node, full_name, full_name_len)) if (full_name_len + name_len > 255) return storage::io_result::not_supported; @@ -150,11 +152,14 @@ namespace mercury::kernel::fs { size_t cand_name_len; RETURN_MAYBE_NOT_FOUND(read_name(out, cand_name, cand_name_len)) - if (cand_name_len != full_name_len) + if (cand_name_len != full_name_len && cand_name_len != full_name_len + 1) goto next_iter; for (size_t i = 0; i < full_name_len; ++i) if (cand_name[i] != full_name[i]) goto next_iter; + if (cand_name_len == full_name_len + 1 && + cand_name[full_name_len] != '/') + goto next_iter; return storage::io_result::success; diff --git a/kernel/storage.cpp b/kernel/storage.cpp index ff86896..29ae6cf 100644 --- a/kernel/storage.cpp +++ b/kernel/storage.cpp @@ -122,7 +122,7 @@ namespace mercury::kernel::storage { while (len != 0) { size_t segment_len = utility::find(str, len, '/'); - size_t to_skip = segment_len == len ? len : len + 1; + size_t to_skip = segment_len == len ? segment_len : segment_len + 1; if (segment_len == 0) ; @@ -211,6 +211,9 @@ namespace mercury::kernel::storage { for (unsigned i = 0; i < prefix_length; ++i) path_without_symlinks_out.segments.add_end(path.segments.buffer[i]); + if (path.segments.count == 0) + goto on_final_node; + for (unsigned i = prefix_length; i < path.segments.count - 1; ++i) { path_without_symlinks_out.segments.add_end(path.segments.buffer[i]); @@ -228,13 +231,17 @@ namespace mercury::kernel::storage { } - const utility::string &last_segment = - path.segments.buffer[path.segments.count - 1]; - path_without_symlinks_out.segments.add_end(last_segment); - - RETURN_IF_NOT_SUCCESS(bd_out->mounted_as->get_child( - node_out, node_out, last_segment.buffer, last_segment.count)) + { + //in a block so that compiler sees last_segment + //isn't needed after this and allows the goto above. + const utility::string &last_segment = + path.segments.buffer[path.segments.count - 1]; + path_without_symlinks_out.segments.add_end(last_segment); + RETURN_IF_NOT_SUCCESS(bd_out->mounted_as->get_child( + node_out, node_out, last_segment.buffer, last_segment.count)) + } + on_final_node: if (resolve_final_node) RETURN_IF_NOT_SUCCESS(resolve_symlinks( bd_out, node_out, path_without_symlinks_out)) |