From 961e1e590b7c2d01effeda15fb10a064e6bfa8e7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 27 Nov 2022 20:09:17 +0100 Subject: [PATCH] Kernel: Make sys$posix_fallocate() fail with ENODEV on non-regular files Previously we tried to determine if `fd` refers to a non-regular file by doing a stat() operation on the file. This didn't work out very well since many File subclasses don't actually implement stat() but instead fall back to failing with EBADF. This patch fixes the issue by checking for regular files with File::is_regular_file() instead. --- Kernel/Syscalls/fallocate.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/fallocate.cpp b/Kernel/Syscalls/fallocate.cpp index 820d86301c..18269c061d 100644 --- a/Kernel/Syscalls/fallocate.cpp +++ b/Kernel/Syscalls/fallocate.cpp @@ -37,7 +37,8 @@ ErrorOr Process::sys$posix_fallocate(int fd, Userspace us if (description->is_fifo()) return ESPIPE; - if (!S_ISREG(TRY(description->file().stat()).st_mode)) + // [ENODEV] The fd argument does not refer to a regular file. + if (!description->file().is_regular_file()) return ENODEV; VERIFY(description->file().is_inode());