Kernel: Virtualize the File::stat() operation

Instead of FileDescriptor branching on the type of File it's wrapping,
add a File::stat() function that can be overridden to provide custom
behavior for the stat syscalls.
This commit is contained in:
Andreas Kling 2020-09-06 18:31:51 +02:00
commit 22831033d0
Notes: sideshowbarker 2024-07-19 02:53:06 +09:00
6 changed files with 28 additions and 20 deletions

View file

@ -77,20 +77,11 @@ FileDescription::~FileDescription()
KResult FileDescription::stat(::stat& buffer)
{
if (is_fifo()) {
memset(&buffer, 0, sizeof(buffer));
buffer.st_mode = S_IFIFO;
return KSuccess;
}
if (is_socket()) {
memset(&buffer, 0, sizeof(buffer));
buffer.st_mode = S_IFSOCK;
return KSuccess;
}
if (!m_inode)
return KResult(-EBADF);
return metadata().stat(buffer);
LOCKER(m_lock);
// FIXME: This is a little awkward, why can't we always forward to File::stat()?
if (m_inode)
return metadata().stat(buffer);
return m_file->stat(buffer);
}
off_t FileDescription::seek(off_t offset, int whence)