diff --git a/repos/gems/run/fs_query.run b/repos/gems/run/fs_query.run
index c928de15e3..2492146f73 100644
--- a/repos/gems/run/fs_query.run
+++ b/repos/gems/run/fs_query.run
@@ -45,6 +45,13 @@ install_config {
+
+
+
+
+
+
+
@@ -77,14 +84,41 @@ install_config {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -197,6 +231,8 @@ append qemu_args " -nographic "
run_genode_until {.*child "test" exited with exit value 0.*\n} 50
+set original_output $output
+
grep_output {\[init -> report_rom\].*}
set num_listings [regexp -all {report 'fs_query -> listing'} $output dummy]
@@ -222,5 +258,17 @@ compare_output_to {
[init -> report_rom]
[init -> report_rom] fourth
[init -> report_rom]
+[init -> report_rom]
[init -> report_rom]
}
+
+set output $original_output
+
+grep_output {\[init -> report_rom_empty_vfs\].*}
+
+compare_output_to {
+[init -> report_rom_empty_vfs] report 'fs_query_empty_vfs -> listing'
+[init -> report_rom_empty_vfs]
+[init -> report_rom_empty_vfs]
+[init -> report_rom_empty_vfs]
+}
diff --git a/repos/os/include/vfs/dir_file_system.h b/repos/os/include/vfs/dir_file_system.h
index a7c240538d..9665be3e4a 100644
--- a/repos/os/include/vfs/dir_file_system.h
+++ b/repos/os/include/vfs/dir_file_system.h
@@ -617,7 +617,31 @@ class Vfs::Dir_file_system : public File_system
Opendir_result open_composite_dirs(char const *sub_path,
Dir_vfs_handle &dir_vfs_handle)
{
- Opendir_result res = OPENDIR_ERR_LOOKUP_FAILED;
+ Opendir_result res;
+ if (strcmp(sub_path, "/")) {
+
+ /*
+ * If there are still directory names in the sub-path, we have
+ * not reached the leaf node of the original path so far.
+ * Therefore, if the current directory is empty, this means
+ * that the original path refers to a directory that doesn't
+ * exist. Consequently, the result defaults to a
+ * "lookup failed" error.
+ */
+ res = OPENDIR_ERR_LOOKUP_FAILED;
+
+ } else {
+
+ /*
+ * We have reached the leaf node of the original path.
+ * Therefore the directory referenced by the original path is
+ * the one that we are at. Consequently, we can let the result
+ * default to "success" regardless of whether the directory is
+ * empty. However, if there are any sub-file-systems, we will
+ * go on and store handles for them in the registry.
+ */
+ res = OPENDIR_OK;
+ }
try {
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
Vfs_handle *sub_dir_handle = nullptr;