mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
Kernel: Return correct error numbers for the mkdir syscall
Previously, VirtualFileSystem::mkdir() would always return ENOENT if no parent custody was returned by resolve_path(). This is incorrect when e.g. the user has no search permission in a component of the path prefix (=> EACCES), or if on component of the path prefix is a file (=> ENOTDIR). This patch fixes that behavior.
This commit is contained in:
parent
25e850ebb1
commit
29d53cbee2
1 changed files with 9 additions and 5 deletions
|
@ -388,16 +388,20 @@ KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
|
||||||
// path component (the one being created) that is allowed not to
|
// path component (the one being created) that is allowed not to
|
||||||
// exist, POSIX allows mkdir'ed path to have trailing slashes.
|
// exist, POSIX allows mkdir'ed path to have trailing slashes.
|
||||||
// Let's handle that case by trimming any trailing slashes.
|
// Let's handle that case by trimming any trailing slashes.
|
||||||
while (path.length() > 1 && path.ends_with("/"))
|
path = path.trim("/"sv, TrimMode::Right);
|
||||||
path = path.substring_view(0, path.length() - 1);
|
if (path.is_empty()) {
|
||||||
|
// NOTE: This means the path was a series of slashes, which resolves to "/".
|
||||||
|
path = "/";
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<Custody> parent_custody;
|
RefPtr<Custody> parent_custody;
|
||||||
if (auto result = resolve_path(path, base, &parent_custody); !result.is_error())
|
auto result = resolve_path(path, base, &parent_custody);
|
||||||
|
if (!result.is_error())
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
else if (!parent_custody)
|
else if (!parent_custody)
|
||||||
return ENOENT;
|
|
||||||
else if (result.error() != -ENOENT)
|
|
||||||
return result.error();
|
return result.error();
|
||||||
|
// NOTE: If resolve_path fails with a non-null parent custody, the error should be ENOENT.
|
||||||
|
VERIFY(result.error() == -ENOENT);
|
||||||
|
|
||||||
auto& parent_inode = parent_custody->inode();
|
auto& parent_inode = parent_custody->inode();
|
||||||
auto current_process = Process::current();
|
auto current_process = Process::current();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue