vfs/dir_fs: allow opening empty dirs

Adapts Dir_file_system::open_composite_dirs in a way that it returns "success"
when the leaf node of the path is an empty directory but "lookup failed", as
usual, if one of the other directories on the way to the leaf node is empty.

I couldn't find a technical reason why we used to return "lookup failed" when
only the leaf node was empty.

The commit also adds a test for en empty root directory and empty
sub-directories to the fs_query run script.

Fixes #4198
This commit is contained in:
Martin Stein 2021-06-15 14:32:27 +02:00 committed by Christian Helmuth
parent 6bfdddd0b5
commit 16c4aacf34
2 changed files with 74 additions and 2 deletions

View File

@ -45,6 +45,13 @@ install_config {
<config verbose="yes"/>
</start>
<start name="report_rom_empty_vfs">
<binary name="report_rom"/>
<resource name="RAM" quantum="1M"/>
<provides> <service name="Report"/> <service name="ROM"/> </provides>
<config verbose="yes"/>
</start>
<start name="vfs">
<resource name="RAM" quantum="10M"/>
<provides><service name="File_system"/></provides>
@ -77,14 +84,41 @@ install_config {
</route>
</start>
<start name="fs_query_empty_vfs" caps="120">
<binary name="fs_query"/>
<resource name="RAM" quantum="2M"/>
<config>
<vfs/>
<query path="/non_existent_1"/>
<query path="/non_existent_1/non_existent_2"/>
<query path="/"/>
</config>
<route>
<service name="Report">
<child name="report_rom_empty_vfs"/>
</service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="fs_query" caps="120">
<resource name="RAM" quantum="2M"/>
<config>
<vfs> <dir name="fs"> <fs writeable="yes"/> </dir> </vfs>
<vfs>
<dir name="empty"/>
<dir name="fs"> <fs writeable="yes"/> </dir>
</vfs>
<query path="/fs/items/non_existent_1"/>
<query path="/fs/items" content="yes"/>
<query path="/fs/non_existent_2" content="yes"/>
<query path="/empty" content="yes"/>
</config>
<route>
<service name="Report">
<child name="report_rom"/>
</service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start>
<start name="test" caps="700">
@ -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] </file>
[init -> report_rom] <file name="4" writeable="yes">fourth</file>
[init -> report_rom] </dir>
[init -> report_rom] <dir path="/empty"/>
[init -> report_rom] </listing>
}
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] <listing>
[init -> report_rom_empty_vfs] <dir path="/"/>
[init -> report_rom_empty_vfs] </listing>
}

View File

@ -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;