Kernel: Ignore null parent custody without error in VFS::open

This modifies the error checks in VFS::open after the call to
resolve_path to ignore a null parent custody if there is no error, as
this is expected when the path to resolve points to "/". Rather, a null
parent custody only constitutes an error if it is accompanied by ENOENT.
This behavior is documented in the VFS::resolve_path_without_veil
method.

To accompany this change, the order of the error checks have been
changed to more naturally fit the new logic.
This commit is contained in:
Max Wipfli 2021-05-19 11:33:23 +02:00 committed by Andreas Kling
parent 73cb566041
commit 9cc201fb29

View file

@ -237,19 +237,16 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody, options);
if (options & O_CREAT) {
if (!parent_custody)
return ENOENT;
if (custody_or_error.is_error()) {
if (custody_or_error.error() != -ENOENT)
return custody_or_error.error();
if (custody_or_error.is_error()) {
// NOTE: ENOENT with a non-null parent custody signals us that the immediate parent
// of the file exists, but the file itself does not.
if ((options & O_CREAT) && custody_or_error.error() == -ENOENT && parent_custody)
return create(path, options, mode, *parent_custody, move(owner));
}
if (options & O_EXCL)
return EEXIST;
}
if (custody_or_error.is_error())
return custody_or_error.error();
}
if ((options & O_CREAT) && (options & O_EXCL))
return EEXIST;
auto& custody = *custody_or_error.value();
auto& inode = custody.inode();