From 47b9e8e6516d3608aca93426da6c42819c64d8e2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Dec 2022 19:05:44 +0100 Subject: [PATCH] Kernel: Annotate VirtualFileSystem::rmdir() errors with spec comments --- Kernel/FileSystem/VirtualFileSystem.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 4d0d7dbce0e..fe0b827db22 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -835,6 +835,7 @@ ErrorOr VirtualFileSystem::symlink(Credentials const& credentials, StringV return {}; } +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html ErrorOr VirtualFileSystem::rmdir(Credentials const& credentials, StringView path, Custody& base) { RefPtr parent_custody; @@ -847,15 +848,22 @@ ErrorOr VirtualFileSystem::rmdir(Credentials const& credentials, StringVie if (last_component == "."sv) 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()) 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) return EBUSY; auto& parent_inode = parent_custody->inode(); 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)) return EACCES; @@ -870,9 +878,12 @@ ErrorOr VirtualFileSystem::rmdir(Credentials const& credentials, StringVie 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) return ENOTEMPTY; + // [EROFS] The directory entry to be removed resides on a read-only file system. if (custody->is_readonly()) return EROFS;