Преглед изворни кода

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.
Andreas Kling пре 2 година
родитељ
комит
961e1e590b
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      Kernel/Syscalls/fallocate.cpp

+ 2 - 1
Kernel/Syscalls/fallocate.cpp

@@ -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());