1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

Kernel: Annotate VirtualFileSystem::rmdir() errors with spec comments

This commit is contained in:
Andreas Kling 2022-12-19 19:05:44 +01:00
parent 8619f2c6f3
commit 47b9e8e651

View file

@ -835,6 +835,7 @@ ErrorOr<void> VirtualFileSystem::symlink(Credentials const& credentials, StringV
return {}; return {};
} }
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html
ErrorOr<void> VirtualFileSystem::rmdir(Credentials const& credentials, StringView path, Custody& base) ErrorOr<void> VirtualFileSystem::rmdir(Credentials const& credentials, StringView path, Custody& base)
{ {
RefPtr<Custody> parent_custody; RefPtr<Custody> parent_custody;
@ -847,15 +848,22 @@ ErrorOr<void> VirtualFileSystem::rmdir(Credentials const& credentials, StringVie
if (last_component == "."sv) if (last_component == "."sv)
return EINVAL; return EINVAL;
// [ENOTDIR] A component of path names an existing file that is neither a directory
// nor a symbolic link to a directory.
if (!inode.is_directory()) if (!inode.is_directory())
return ENOTDIR; return ENOTDIR;
// [EBUSY] The directory to be removed is currently in use by the system or some process
// and the implementation considers this to be an error.
// NOTE: If there is no parent, that means we're trying to rmdir the root directory!
if (!parent_custody) if (!parent_custody)
return EBUSY; return EBUSY;
auto& parent_inode = parent_custody->inode(); auto& parent_inode = parent_custody->inode();
auto parent_metadata = parent_inode.metadata(); auto parent_metadata = parent_inode.metadata();
// [EACCES] Search permission is denied on a component of the path prefix,
// or write permission is denied on the parent directory of the directory to be removed.
if (!parent_metadata.may_write(credentials)) if (!parent_metadata.may_write(credentials))
return EACCES; return EACCES;
@ -870,9 +878,12 @@ ErrorOr<void> VirtualFileSystem::rmdir(Credentials const& credentials, StringVie
return {}; return {};
})); }));
// [ENOTEMPTY] The path argument names a directory that is not an empty directory,
// or there are hard links to the directory other than dot or a single entry in dot-dot.
if (child_count != 2) if (child_count != 2)
return ENOTEMPTY; return ENOTEMPTY;
// [EROFS] The directory entry to be removed resides on a read-only file system.
if (custody->is_readonly()) if (custody->is_readonly())
return EROFS; return EROFS;