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.
This commit is contained in:
Andreas Kling 2022-11-27 20:09:17 +01:00
parent 4dd148f07c
commit 961e1e590b

View file

@ -37,7 +37,8 @@ ErrorOr<FlatPtr> Process::sys$posix_fallocate(int fd, Userspace<off_t const*> 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());