2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2020-09-15 13:24:14 +03:00
|
|
|
#include <AK/MemoryStream.h>
|
2021-01-25 18:07:10 +03:00
|
|
|
#include <Kernel/Debug.h>
|
2019-05-30 14:39:17 +03:00
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-05-30 19:58:59 +03:00
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
2019-04-06 21:29:48 +03:00
|
|
|
#include <Kernel/FileSystem/FIFO.h>
|
2019-06-07 10:36:51 +03:00
|
|
|
#include <Kernel/FileSystem/FileDescription.h>
|
2019-05-30 14:39:17 +03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
#include <Kernel/FileSystem/InodeFile.h>
|
2019-04-06 21:29:48 +03:00
|
|
|
#include <Kernel/Net/Socket.h>
|
2019-02-16 11:57:42 +03:00
|
|
|
#include <Kernel/Process.h>
|
2019-05-30 14:39:17 +03:00
|
|
|
#include <Kernel/TTY/MasterPTY.h>
|
|
|
|
#include <Kernel/TTY/TTY.h>
|
|
|
|
#include <Kernel/UnixTypes.h>
|
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
#include <LibC/errno_numbers.h>
|
2018-11-07 14:05:51 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-09-17 22:51:09 +03:00
|
|
|
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custody)
|
2018-11-05 21:01:22 +03:00
|
|
|
{
|
2021-04-23 17:46:57 +03:00
|
|
|
auto description = adopt_ref(*new FileDescription(InodeFile::create(custody.inode())));
|
2019-08-11 10:32:21 +03:00
|
|
|
description->m_custody = custody;
|
2020-09-17 22:51:09 +03:00
|
|
|
auto result = description->attach();
|
|
|
|
if (result.is_error()) {
|
2021-02-07 15:03:24 +03:00
|
|
|
dbgln_if(FILEDESCRIPTION_DEBUG, "Failed to create file description for custody: {}", result);
|
2020-09-17 22:51:09 +03:00
|
|
|
return result;
|
|
|
|
}
|
2019-06-13 23:03:04 +03:00
|
|
|
return description;
|
2019-01-16 14:57:07 +03:00
|
|
|
}
|
|
|
|
|
2020-09-17 22:51:09 +03:00
|
|
|
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
|
2019-01-16 14:57:07 +03:00
|
|
|
{
|
2021-04-23 17:46:57 +03:00
|
|
|
auto description = adopt_ref(*new FileDescription(file));
|
2020-09-17 22:51:09 +03:00
|
|
|
auto result = description->attach();
|
|
|
|
if (result.is_error()) {
|
2021-02-07 15:03:24 +03:00
|
|
|
dbgln_if(FILEDESCRIPTION_DEBUG, "Failed to create file description for file: {}", result);
|
2020-09-17 22:51:09 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return description;
|
2019-02-14 16:17:38 +03:00
|
|
|
}
|
|
|
|
|
2019-08-11 16:38:20 +03:00
|
|
|
FileDescription::FileDescription(File& file)
|
2019-08-11 10:32:21 +03:00
|
|
|
: m_file(file)
|
2019-02-14 16:17:38 +03:00
|
|
|
{
|
2019-08-11 10:32:21 +03:00
|
|
|
if (file.is_inode())
|
|
|
|
m_inode = static_cast<InodeFile&>(file).inode();
|
2020-09-17 22:51:09 +03:00
|
|
|
|
2019-10-25 10:22:22 +03:00
|
|
|
m_is_directory = metadata().is_directory();
|
2019-02-14 16:17:38 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
FileDescription::~FileDescription()
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2020-09-17 22:51:09 +03:00
|
|
|
m_file->detach(*this);
|
2019-04-29 05:55:54 +03:00
|
|
|
if (is_fifo())
|
|
|
|
static_cast<FIFO*>(m_file.ptr())->detach(m_fifo_direction);
|
2020-08-05 12:13:30 +03:00
|
|
|
// FIXME: Should this error path be observed somehow?
|
2020-09-17 22:51:09 +03:00
|
|
|
(void)m_file->close();
|
|
|
|
if (m_inode)
|
|
|
|
m_inode->detach(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
KResult FileDescription::attach()
|
|
|
|
{
|
|
|
|
if (m_inode) {
|
|
|
|
auto result = m_inode->attach(*this);
|
|
|
|
if (result.is_error())
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return m_file->attach(*this);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2020-11-30 02:05:27 +03:00
|
|
|
Thread::FileBlocker::BlockFlags FileDescription::should_unblock(Thread::FileBlocker::BlockFlags block_flags) const
|
|
|
|
{
|
2021-03-07 14:01:11 +03:00
|
|
|
using BlockFlags = Thread::FileBlocker::BlockFlags;
|
|
|
|
BlockFlags unblock_flags = BlockFlags::None;
|
|
|
|
if (has_flag(block_flags, BlockFlags::Read) && can_read())
|
|
|
|
unblock_flags |= BlockFlags::Read;
|
|
|
|
if (has_flag(block_flags, BlockFlags::Write) && can_write())
|
|
|
|
unblock_flags |= BlockFlags::Write;
|
2020-11-30 02:05:27 +03:00
|
|
|
// TODO: Implement Thread::FileBlocker::BlockFlags::Exception
|
|
|
|
|
2021-03-07 14:01:11 +03:00
|
|
|
if (has_flag(block_flags, BlockFlags::SocketFlags)) {
|
2020-11-30 02:05:27 +03:00
|
|
|
auto* sock = socket();
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(sock);
|
2021-03-07 14:01:11 +03:00
|
|
|
if (has_flag(block_flags, BlockFlags::Accept) && sock->can_accept())
|
|
|
|
unblock_flags |= BlockFlags::Accept;
|
|
|
|
if (has_flag(block_flags, BlockFlags::Connect) && sock->setup_state() == Socket::SetupState::Completed)
|
|
|
|
unblock_flags |= BlockFlags::Connect;
|
2020-11-30 02:05:27 +03:00
|
|
|
}
|
2021-03-07 14:01:11 +03:00
|
|
|
return unblock_flags;
|
2020-11-30 02:05:27 +03:00
|
|
|
}
|
|
|
|
|
2020-09-06 19:17:07 +03:00
|
|
|
KResult FileDescription::stat(::stat& buffer)
|
2018-10-14 23:57:41 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2020-09-06 19:31:51 +03:00
|
|
|
// 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);
|
2018-10-14 23:57:41 +03:00
|
|
|
}
|
|
|
|
|
2021-03-19 12:43:58 +03:00
|
|
|
KResultOr<off_t> FileDescription::seek(off_t offset, int whence)
|
2018-10-14 22:19:27 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2019-05-30 14:39:17 +03:00
|
|
|
if (!m_file->is_seekable())
|
2021-03-19 12:43:58 +03:00
|
|
|
return ESPIPE;
|
2018-10-14 22:19:27 +03:00
|
|
|
|
2019-05-30 14:39:17 +03:00
|
|
|
off_t new_offset;
|
2018-10-14 22:19:27 +03:00
|
|
|
|
2018-10-14 23:57:41 +03:00
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
2019-05-30 14:39:17 +03:00
|
|
|
new_offset = offset;
|
2018-10-14 22:19:27 +03:00
|
|
|
break;
|
2018-10-14 23:57:41 +03:00
|
|
|
case SEEK_CUR:
|
2021-02-21 17:23:37 +03:00
|
|
|
if (Checked<off_t>::addition_would_overflow(m_current_offset, offset))
|
2021-03-19 12:43:58 +03:00
|
|
|
return EOVERFLOW;
|
2019-05-30 14:39:17 +03:00
|
|
|
new_offset = m_current_offset + offset;
|
2018-10-14 22:19:27 +03:00
|
|
|
break;
|
2018-10-14 23:57:41 +03:00
|
|
|
case SEEK_END:
|
2020-04-06 11:54:21 +03:00
|
|
|
if (!metadata().is_valid())
|
2021-03-19 12:43:58 +03:00
|
|
|
return EIO;
|
2020-04-06 11:54:21 +03:00
|
|
|
new_offset = metadata().size;
|
2018-10-14 22:19:27 +03:00
|
|
|
break;
|
|
|
|
default:
|
2021-03-19 12:43:58 +03:00
|
|
|
return EINVAL;
|
2018-10-14 22:19:27 +03:00
|
|
|
}
|
|
|
|
|
2019-05-30 14:39:17 +03:00
|
|
|
if (new_offset < 0)
|
2021-03-19 12:43:58 +03:00
|
|
|
return EINVAL;
|
|
|
|
// FIXME: Return EINVAL if attempting to seek past the end of a seekable device.
|
2019-05-16 16:44:01 +03:00
|
|
|
|
2019-05-30 14:39:17 +03:00
|
|
|
m_current_offset = new_offset;
|
2020-09-17 22:51:09 +03:00
|
|
|
|
|
|
|
m_file->did_seek(*this, new_offset);
|
|
|
|
if (m_inode)
|
|
|
|
m_inode->did_seek(*this, new_offset);
|
2020-11-30 02:05:27 +03:00
|
|
|
evaluate_block_conditions();
|
2018-12-03 02:39:25 +03:00
|
|
|
return m_current_offset;
|
2018-10-14 22:19:27 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 06:11:07 +03:00
|
|
|
KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, size_t count)
|
2018-10-14 22:19:27 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2021-02-03 12:54:35 +03:00
|
|
|
if (Checked<off_t>::addition_would_overflow(m_current_offset, count))
|
|
|
|
return EOVERFLOW;
|
2020-08-04 19:02:23 +03:00
|
|
|
auto nread_or_error = m_file->read(*this, offset(), buffer, count);
|
2020-11-30 02:05:27 +03:00
|
|
|
if (!nread_or_error.is_error()) {
|
|
|
|
if (m_file->is_seekable())
|
|
|
|
m_current_offset += nread_or_error.value();
|
|
|
|
evaluate_block_conditions();
|
|
|
|
}
|
2020-08-04 19:02:23 +03:00
|
|
|
return nread_or_error;
|
2018-10-14 22:19:27 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 06:11:07 +03:00
|
|
|
KResultOr<size_t> FileDescription::write(const UserOrKernelBuffer& data, size_t size)
|
2018-10-30 17:33:37 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2021-02-03 12:54:35 +03:00
|
|
|
if (Checked<off_t>::addition_would_overflow(m_current_offset, size))
|
|
|
|
return EOVERFLOW;
|
2020-08-04 19:02:23 +03:00
|
|
|
auto nwritten_or_error = m_file->write(*this, offset(), data, size);
|
2020-11-30 02:05:27 +03:00
|
|
|
if (!nwritten_or_error.is_error()) {
|
|
|
|
if (m_file->is_seekable())
|
|
|
|
m_current_offset += nwritten_or_error.value();
|
|
|
|
evaluate_block_conditions();
|
|
|
|
}
|
2020-08-04 19:02:23 +03:00
|
|
|
return nwritten_or_error;
|
2018-10-30 17:33:37 +03:00
|
|
|
}
|
|
|
|
|
2019-07-19 14:19:47 +03:00
|
|
|
bool FileDescription::can_write() const
|
2018-11-12 03:28:46 +03:00
|
|
|
{
|
2020-04-10 12:44:42 +03:00
|
|
|
return m_file->can_write(*this, offset());
|
2018-11-12 03:28:46 +03:00
|
|
|
}
|
|
|
|
|
2019-07-19 14:19:47 +03:00
|
|
|
bool FileDescription::can_read() const
|
2018-10-25 14:07:59 +03:00
|
|
|
{
|
2020-04-10 12:44:42 +03:00
|
|
|
return m_file->can_read(*this, offset());
|
2018-10-25 14:07:59 +03:00
|
|
|
}
|
|
|
|
|
2020-12-18 16:10:10 +03:00
|
|
|
KResultOr<NonnullOwnPtr<KBuffer>> FileDescription::read_entire_file()
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2019-04-28 16:02:55 +03:00
|
|
|
// HACK ALERT: (This entire function)
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(m_file->is_inode());
|
|
|
|
VERIFY(m_inode);
|
2019-01-16 14:57:07 +03:00
|
|
|
return m_inode->read_entire(this);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 06:11:07 +03:00
|
|
|
ssize_t FileDescription::get_dir_entries(UserOrKernelBuffer& buffer, ssize_t size)
|
2018-10-24 13:43:52 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock, Lock::Mode::Shared);
|
2019-10-25 10:22:22 +03:00
|
|
|
if (!is_directory())
|
|
|
|
return -ENOTDIR;
|
|
|
|
|
2019-01-16 14:57:07 +03:00
|
|
|
auto metadata = this->metadata();
|
2019-01-31 19:31:23 +03:00
|
|
|
if (!metadata.is_valid())
|
2018-10-24 13:43:52 +03:00
|
|
|
return -EIO;
|
|
|
|
|
2020-02-20 14:54:15 +03:00
|
|
|
if (size < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-05-23 16:27:33 +03:00
|
|
|
size_t size_to_allocate = max(static_cast<size_t>(PAGE_SIZE), static_cast<size_t>(metadata.size));
|
2019-03-20 20:31:12 +03:00
|
|
|
|
|
|
|
auto temp_buffer = ByteBuffer::create_uninitialized(size_to_allocate);
|
2020-09-15 13:24:14 +03:00
|
|
|
OutputMemoryStream stream { temp_buffer };
|
|
|
|
|
2020-08-29 21:25:01 +03:00
|
|
|
KResult result = VFS::the().traverse_directory_inode(*m_inode, [&stream, this](auto& entry) {
|
2021-02-12 11:18:47 +03:00
|
|
|
stream << (u32)entry.inode.index().value();
|
2020-08-29 21:25:01 +03:00
|
|
|
stream << m_inode->fs().internal_file_type_to_directory_entry_type(entry);
|
2020-08-18 13:41:27 +03:00
|
|
|
stream << (u32)entry.name.length();
|
2020-09-15 13:24:14 +03:00
|
|
|
stream << entry.name.bytes();
|
2018-10-24 13:43:52 +03:00
|
|
|
return true;
|
|
|
|
});
|
2020-08-05 12:07:31 +03:00
|
|
|
|
|
|
|
if (result.is_error())
|
2020-08-08 22:17:35 +03:00
|
|
|
return result;
|
2020-08-05 12:07:31 +03:00
|
|
|
|
2020-09-16 17:55:29 +03:00
|
|
|
if (stream.handle_recoverable_error())
|
2020-02-20 14:54:15 +03:00
|
|
|
return -EINVAL;
|
2018-10-24 15:28:22 +03:00
|
|
|
|
2020-09-15 13:24:14 +03:00
|
|
|
if (!buffer.write(stream.bytes()))
|
2020-09-12 06:11:07 +03:00
|
|
|
return -EFAULT;
|
2020-09-15 13:24:14 +03:00
|
|
|
|
|
|
|
return stream.size();
|
2018-10-24 13:43:52 +03:00
|
|
|
}
|
2019-01-16 14:57:07 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
bool FileDescription::is_device() const
|
2019-04-28 16:02:55 +03:00
|
|
|
{
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->is_device();
|
2019-04-28 16:02:55 +03:00
|
|
|
}
|
|
|
|
|
2020-01-12 18:28:23 +03:00
|
|
|
const Device* FileDescription::device() const
|
|
|
|
{
|
|
|
|
if (!is_device())
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<const Device*>(m_file.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
Device* FileDescription::device()
|
|
|
|
{
|
|
|
|
if (!is_device())
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<Device*>(m_file.ptr());
|
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
bool FileDescription::is_tty() const
|
2018-10-31 00:03:02 +03:00
|
|
|
{
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->is_tty();
|
2018-10-31 00:03:02 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
const TTY* FileDescription::tty() const
|
2018-10-31 00:03:02 +03:00
|
|
|
{
|
2019-01-16 14:57:07 +03:00
|
|
|
if (!is_tty())
|
2018-11-12 03:28:46 +03:00
|
|
|
return nullptr;
|
2019-04-28 16:02:55 +03:00
|
|
|
return static_cast<const TTY*>(m_file.ptr());
|
2018-10-31 00:03:02 +03:00
|
|
|
}
|
2018-11-01 16:00:28 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
TTY* FileDescription::tty()
|
2018-11-02 15:14:25 +03:00
|
|
|
{
|
2019-01-16 14:57:07 +03:00
|
|
|
if (!is_tty())
|
2018-11-12 03:28:46 +03:00
|
|
|
return nullptr;
|
2019-04-28 16:02:55 +03:00
|
|
|
return static_cast<TTY*>(m_file.ptr());
|
2018-11-02 15:14:25 +03:00
|
|
|
}
|
2019-01-15 08:30:19 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
bool FileDescription::is_master_pty() const
|
2019-01-15 08:30:19 +03:00
|
|
|
{
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->is_master_pty();
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
const MasterPTY* FileDescription::master_pty() const
|
2019-01-15 08:30:19 +03:00
|
|
|
{
|
|
|
|
if (!is_master_pty())
|
|
|
|
return nullptr;
|
2019-04-28 16:02:55 +03:00
|
|
|
return static_cast<const MasterPTY*>(m_file.ptr());
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
MasterPTY* FileDescription::master_pty()
|
2019-01-15 08:30:19 +03:00
|
|
|
{
|
|
|
|
if (!is_master_pty())
|
|
|
|
return nullptr;
|
2019-04-28 16:02:55 +03:00
|
|
|
return static_cast<MasterPTY*>(m_file.ptr());
|
2019-01-15 08:30:19 +03:00
|
|
|
}
|
2018-11-02 15:14:25 +03:00
|
|
|
|
2020-06-02 19:20:05 +03:00
|
|
|
KResult FileDescription::close()
|
2018-11-01 16:00:28 +03:00
|
|
|
{
|
2021-04-30 11:33:33 +03:00
|
|
|
if (m_file->attach_count() > 0)
|
2020-06-02 19:20:05 +03:00
|
|
|
return KSuccess;
|
|
|
|
return m_file->close();
|
2018-11-01 16:00:28 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
String FileDescription::absolute_path() const
|
2018-11-01 16:00:28 +03:00
|
|
|
{
|
2019-05-30 19:58:59 +03:00
|
|
|
if (m_custody)
|
|
|
|
return m_custody->absolute_path();
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->absolute_path(*this);
|
2018-11-01 16:00:28 +03:00
|
|
|
}
|
2018-11-12 03:28:46 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
InodeMetadata FileDescription::metadata() const
|
2019-01-16 14:57:07 +03:00
|
|
|
{
|
|
|
|
if (m_inode)
|
|
|
|
return m_inode->metadata();
|
2019-06-07 12:43:58 +03:00
|
|
|
return {};
|
2019-01-16 14:57:07 +03:00
|
|
|
}
|
2019-02-16 11:57:42 +03:00
|
|
|
|
2021-03-19 00:57:25 +03:00
|
|
|
KResultOr<Region*> FileDescription::mmap(Process& process, const Range& range, u64 offset, int prot, bool shared)
|
2019-02-16 11:57:42 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2021-01-25 16:52:36 +03:00
|
|
|
return m_file->mmap(process, *this, range, offset, prot, shared);
|
2019-02-16 11:57:42 +03:00
|
|
|
}
|
|
|
|
|
2020-02-08 14:07:04 +03:00
|
|
|
KResult FileDescription::truncate(u64 length)
|
2019-04-09 02:10:00 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->truncate(length);
|
2019-04-09 02:10:00 +03:00
|
|
|
}
|
2019-04-28 23:31:31 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
bool FileDescription::is_fifo() const
|
2019-04-29 05:55:54 +03:00
|
|
|
{
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->is_fifo();
|
2019-04-29 05:55:54 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
FIFO* FileDescription::fifo()
|
2019-04-29 05:55:54 +03:00
|
|
|
{
|
|
|
|
if (!is_fifo())
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<FIFO*>(m_file.ptr());
|
|
|
|
}
|
2019-05-03 21:42:43 +03:00
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
bool FileDescription::is_socket() const
|
2019-05-03 21:42:43 +03:00
|
|
|
{
|
2019-05-30 14:39:17 +03:00
|
|
|
return m_file->is_socket();
|
2019-05-03 21:42:43 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
Socket* FileDescription::socket()
|
2019-05-03 21:42:43 +03:00
|
|
|
{
|
|
|
|
if (!is_socket())
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<Socket*>(m_file.ptr());
|
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
const Socket* FileDescription::socket() const
|
2019-05-03 21:42:43 +03:00
|
|
|
{
|
|
|
|
if (!is_socket())
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<const Socket*>(m_file.ptr());
|
|
|
|
}
|
2019-05-30 16:37:51 +03:00
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
void FileDescription::set_file_flags(u32 flags)
|
2019-05-30 16:37:51 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2019-05-30 16:37:51 +03:00
|
|
|
m_is_blocking = !(flags & O_NONBLOCK);
|
|
|
|
m_should_append = flags & O_APPEND;
|
2019-11-05 21:35:12 +03:00
|
|
|
m_direct = flags & O_DIRECT;
|
2019-05-30 16:37:51 +03:00
|
|
|
m_file_flags = flags;
|
|
|
|
}
|
2019-06-01 21:31:36 +03:00
|
|
|
|
2020-01-03 22:14:56 +03:00
|
|
|
KResult FileDescription::chmod(mode_t mode)
|
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2020-05-28 17:32:20 +03:00
|
|
|
return m_file->chmod(*this, mode);
|
2020-01-03 22:14:56 +03:00
|
|
|
}
|
|
|
|
|
2019-06-07 10:36:51 +03:00
|
|
|
KResult FileDescription::chown(uid_t uid, gid_t gid)
|
2019-06-01 21:31:36 +03:00
|
|
|
{
|
2021-04-25 01:27:32 +03:00
|
|
|
Locker locker(m_lock);
|
2020-05-28 17:32:20 +03:00
|
|
|
return m_file->chown(*this, uid, gid);
|
2019-06-01 21:31:36 +03:00
|
|
|
}
|
2020-02-16 03:27:42 +03:00
|
|
|
|
2020-11-30 02:05:27 +03:00
|
|
|
FileBlockCondition& FileDescription::block_condition()
|
|
|
|
{
|
|
|
|
return m_file->block_condition();
|
|
|
|
}
|
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|