mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
Kernel: Rename FileDescriptor to FileDescription.
After reading a bunch of POSIX specs, I've learned that a file descriptor is the number that refers to a file description, not the description itself. So this patch renames FileDescriptor to FileDescription, and Process now has FileDescription* file_description(int fd).
This commit is contained in:
parent
69a6ce90df
commit
08cd75ac4b
70 changed files with 373 additions and 373 deletions
|
@ -479,7 +479,7 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
|
|||
return new_inode;
|
||||
}
|
||||
|
||||
ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor*) const
|
||||
ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription*) const
|
||||
{
|
||||
Locker inode_locker(m_lock);
|
||||
ASSERT(offset >= 0);
|
||||
|
@ -585,7 +585,7 @@ bool Ext2FSInode::resize(qword new_size)
|
|||
return true;
|
||||
}
|
||||
|
||||
ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescriptor*)
|
||||
ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescription*)
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(count >= 0);
|
||||
|
|
|
@ -25,12 +25,12 @@ public:
|
|||
|
||||
private:
|
||||
// ^Inode
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||
virtual InodeMetadata metadata() const override;
|
||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||
virtual InodeIdentifier lookup(StringView name) override;
|
||||
virtual void flush_metadata() override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) override;
|
||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||
virtual KResult remove_child(const String& name) override;
|
||||
virtual int set_atime(time_t) override;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/Lock.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Thread.h>
|
||||
|
@ -30,9 +30,9 @@ Retained<FIFO> FIFO::create(uid_t uid)
|
|||
return adopt(*new FIFO(uid));
|
||||
}
|
||||
|
||||
Retained<FileDescriptor> FIFO::open_direction(FIFO::Direction direction)
|
||||
Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
|
||||
{
|
||||
auto descriptor = FileDescriptor::create(this);
|
||||
auto descriptor = FileDescription::create(this);
|
||||
attach(direction);
|
||||
descriptor->set_fifo_direction({ }, direction);
|
||||
return descriptor;
|
||||
|
@ -83,17 +83,17 @@ void FIFO::detach(Direction direction)
|
|||
}
|
||||
}
|
||||
|
||||
bool FIFO::can_read(FileDescriptor&) const
|
||||
bool FIFO::can_read(FileDescription&) const
|
||||
{
|
||||
return !m_buffer.is_empty() || !m_writers;
|
||||
}
|
||||
|
||||
bool FIFO::can_write(FileDescriptor&) const
|
||||
bool FIFO::can_write(FileDescription&) const
|
||||
{
|
||||
return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers;
|
||||
}
|
||||
|
||||
ssize_t FIFO::read(FileDescriptor&, byte* buffer, ssize_t size)
|
||||
ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size)
|
||||
{
|
||||
if (!m_writers && m_buffer.is_empty())
|
||||
return 0;
|
||||
|
@ -107,7 +107,7 @@ ssize_t FIFO::read(FileDescriptor&, byte* buffer, ssize_t size)
|
|||
return nread;
|
||||
}
|
||||
|
||||
ssize_t FIFO::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
||||
ssize_t FIFO::write(FileDescription&, const byte* buffer, ssize_t size)
|
||||
{
|
||||
if (!m_readers) {
|
||||
current->process().send_signal(SIGPIPE, ¤t->process());
|
||||
|
@ -119,7 +119,7 @@ ssize_t FIFO::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
|||
return m_buffer.write(buffer, size);
|
||||
}
|
||||
|
||||
String FIFO::absolute_path(const FileDescriptor&) const
|
||||
String FIFO::absolute_path(const FileDescription&) const
|
||||
{
|
||||
return String::format("fifo:%u", this);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <Kernel/File.h>
|
||||
#include <Kernel/UnixTypes.h>
|
||||
|
||||
class FileDescriptor;
|
||||
class FileDescription;
|
||||
|
||||
class FIFO final : public File {
|
||||
public:
|
||||
|
@ -22,18 +22,18 @@ public:
|
|||
|
||||
uid_t uid() const { return m_uid; }
|
||||
|
||||
Retained<FileDescriptor> open_direction(Direction);
|
||||
Retained<FileDescription> open_direction(Direction);
|
||||
|
||||
void attach(Direction);
|
||||
void detach(Direction);
|
||||
|
||||
private:
|
||||
// ^File
|
||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
||||
virtual bool can_read(FileDescriptor&) const override;
|
||||
virtual bool can_write(FileDescriptor&) const override;
|
||||
virtual String absolute_path(const FileDescriptor&) const override;
|
||||
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||
virtual bool can_read(FileDescription&) const override;
|
||||
virtual bool can_write(FileDescription&) const override;
|
||||
virtual String absolute_path(const FileDescription&) const override;
|
||||
virtual const char* class_name() const override { return "FIFO"; }
|
||||
virtual bool is_fifo() const override { return true; }
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <Kernel/Devices/CharacterDevice.h>
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/InodeFile.h>
|
||||
#include <Kernel/Net/Socket.h>
|
||||
|
@ -15,19 +15,19 @@
|
|||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
|
||||
Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Custody>&& custody)
|
||||
Retained<FileDescription> FileDescription::create(RetainPtr<Custody>&& custody)
|
||||
{
|
||||
auto descriptor = adopt(*new FileDescriptor(InodeFile::create(custody->inode())));
|
||||
auto descriptor = adopt(*new FileDescription(InodeFile::create(custody->inode())));
|
||||
descriptor->m_custody = move(custody);
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
Retained<FileDescriptor> FileDescriptor::create(RetainPtr<File>&& file, SocketRole role)
|
||||
Retained<FileDescription> FileDescription::create(RetainPtr<File>&& file, SocketRole role)
|
||||
{
|
||||
return adopt(*new FileDescriptor(move(file), role));
|
||||
return adopt(*new FileDescription(move(file), role));
|
||||
}
|
||||
|
||||
FileDescriptor::FileDescriptor(RetainPtr<File>&& file, SocketRole role)
|
||||
FileDescription::FileDescription(RetainPtr<File>&& file, SocketRole role)
|
||||
: m_file(move(file))
|
||||
{
|
||||
if (m_file->is_inode())
|
||||
|
@ -35,7 +35,7 @@ FileDescriptor::FileDescriptor(RetainPtr<File>&& file, SocketRole role)
|
|||
set_socket_role(role);
|
||||
}
|
||||
|
||||
FileDescriptor::~FileDescriptor()
|
||||
FileDescription::~FileDescription()
|
||||
{
|
||||
if (is_socket())
|
||||
socket()->detach(*this);
|
||||
|
@ -46,7 +46,7 @@ FileDescriptor::~FileDescriptor()
|
|||
m_inode = nullptr;
|
||||
}
|
||||
|
||||
void FileDescriptor::set_socket_role(SocketRole role)
|
||||
void FileDescription::set_socket_role(SocketRole role)
|
||||
{
|
||||
if (role == m_socket_role)
|
||||
return;
|
||||
|
@ -58,13 +58,13 @@ void FileDescriptor::set_socket_role(SocketRole role)
|
|||
socket()->attach(*this);
|
||||
}
|
||||
|
||||
Retained<FileDescriptor> FileDescriptor::clone()
|
||||
Retained<FileDescription> FileDescription::clone()
|
||||
{
|
||||
RetainPtr<FileDescriptor> descriptor;
|
||||
RetainPtr<FileDescription> descriptor;
|
||||
if (is_fifo()) {
|
||||
descriptor = fifo()->open_direction(m_fifo_direction);
|
||||
} else {
|
||||
descriptor = FileDescriptor::create(m_file.copy_ref(), m_socket_role);
|
||||
descriptor = FileDescription::create(m_file.copy_ref(), m_socket_role);
|
||||
descriptor->m_custody = m_custody.copy_ref();
|
||||
descriptor->m_inode = m_inode.copy_ref();
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ Retained<FileDescriptor> FileDescriptor::clone()
|
|||
return *descriptor;
|
||||
}
|
||||
|
||||
KResult FileDescriptor::fstat(stat& buffer)
|
||||
KResult FileDescription::fstat(stat& buffer)
|
||||
{
|
||||
ASSERT(!is_fifo());
|
||||
if (!m_inode)
|
||||
|
@ -84,14 +84,14 @@ KResult FileDescriptor::fstat(stat& buffer)
|
|||
return metadata().stat(buffer);
|
||||
}
|
||||
|
||||
KResult FileDescriptor::fchmod(mode_t mode)
|
||||
KResult FileDescription::fchmod(mode_t mode)
|
||||
{
|
||||
if (!m_inode)
|
||||
return KResult(-EBADF);
|
||||
return VFS::the().chmod(*m_inode, mode);
|
||||
}
|
||||
|
||||
off_t FileDescriptor::seek(off_t offset, int whence)
|
||||
off_t FileDescription::seek(off_t offset, int whence)
|
||||
{
|
||||
if (!m_file->is_seekable())
|
||||
return -EINVAL;
|
||||
|
@ -127,7 +127,7 @@ off_t FileDescriptor::seek(off_t offset, int whence)
|
|||
return m_current_offset;
|
||||
}
|
||||
|
||||
ssize_t FileDescriptor::read(byte* buffer, ssize_t count)
|
||||
ssize_t FileDescription::read(byte* buffer, ssize_t count)
|
||||
{
|
||||
int nread = m_file->read(*this, buffer, count);
|
||||
if (m_file->is_seekable())
|
||||
|
@ -135,7 +135,7 @@ ssize_t FileDescriptor::read(byte* buffer, ssize_t count)
|
|||
return nread;
|
||||
}
|
||||
|
||||
ssize_t FileDescriptor::write(const byte* data, ssize_t size)
|
||||
ssize_t FileDescription::write(const byte* data, ssize_t size)
|
||||
{
|
||||
int nwritten = m_file->write(*this, data, size);
|
||||
if (m_file->is_seekable())
|
||||
|
@ -143,17 +143,17 @@ ssize_t FileDescriptor::write(const byte* data, ssize_t size)
|
|||
return nwritten;
|
||||
}
|
||||
|
||||
bool FileDescriptor::can_write()
|
||||
bool FileDescription::can_write()
|
||||
{
|
||||
return m_file->can_write(*this);
|
||||
}
|
||||
|
||||
bool FileDescriptor::can_read()
|
||||
bool FileDescription::can_read()
|
||||
{
|
||||
return m_file->can_read(*this);
|
||||
}
|
||||
|
||||
ByteBuffer FileDescriptor::read_entire_file()
|
||||
ByteBuffer FileDescription::read_entire_file()
|
||||
{
|
||||
// HACK ALERT: (This entire function)
|
||||
ASSERT(m_file->is_inode());
|
||||
|
@ -161,13 +161,13 @@ ByteBuffer FileDescriptor::read_entire_file()
|
|||
return m_inode->read_entire(this);
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_directory() const
|
||||
bool FileDescription::is_directory() const
|
||||
{
|
||||
ASSERT(!is_fifo());
|
||||
return metadata().is_directory();
|
||||
}
|
||||
|
||||
ssize_t FileDescriptor::get_dir_entries(byte* buffer, ssize_t size)
|
||||
ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size)
|
||||
{
|
||||
auto metadata = this->metadata();
|
||||
if (!metadata.is_valid())
|
||||
|
@ -195,137 +195,137 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, ssize_t size)
|
|||
return stream.offset();
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_device() const
|
||||
bool FileDescription::is_device() const
|
||||
{
|
||||
return m_file->is_device();
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_tty() const
|
||||
bool FileDescription::is_tty() const
|
||||
{
|
||||
return m_file->is_tty();
|
||||
}
|
||||
|
||||
const TTY* FileDescriptor::tty() const
|
||||
const TTY* FileDescription::tty() const
|
||||
{
|
||||
if (!is_tty())
|
||||
return nullptr;
|
||||
return static_cast<const TTY*>(m_file.ptr());
|
||||
}
|
||||
|
||||
TTY* FileDescriptor::tty()
|
||||
TTY* FileDescription::tty()
|
||||
{
|
||||
if (!is_tty())
|
||||
return nullptr;
|
||||
return static_cast<TTY*>(m_file.ptr());
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_master_pty() const
|
||||
bool FileDescription::is_master_pty() const
|
||||
{
|
||||
return m_file->is_master_pty();
|
||||
}
|
||||
|
||||
const MasterPTY* FileDescriptor::master_pty() const
|
||||
const MasterPTY* FileDescription::master_pty() const
|
||||
{
|
||||
if (!is_master_pty())
|
||||
return nullptr;
|
||||
return static_cast<const MasterPTY*>(m_file.ptr());
|
||||
}
|
||||
|
||||
MasterPTY* FileDescriptor::master_pty()
|
||||
MasterPTY* FileDescription::master_pty()
|
||||
{
|
||||
if (!is_master_pty())
|
||||
return nullptr;
|
||||
return static_cast<MasterPTY*>(m_file.ptr());
|
||||
}
|
||||
|
||||
int FileDescriptor::close()
|
||||
int FileDescription::close()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
String FileDescriptor::absolute_path() const
|
||||
String FileDescription::absolute_path() const
|
||||
{
|
||||
if (m_custody)
|
||||
return m_custody->absolute_path();
|
||||
dbgprintf("FileDescriptor::absolute_path() for FD without custody, File type: %s\n", m_file->class_name());
|
||||
dbgprintf("FileDescription::absolute_path() for FD without custody, File type: %s\n", m_file->class_name());
|
||||
return m_file->absolute_path(*this);
|
||||
}
|
||||
|
||||
InodeMetadata FileDescriptor::metadata() const
|
||||
InodeMetadata FileDescription::metadata() const
|
||||
{
|
||||
if (m_inode)
|
||||
return m_inode->metadata();
|
||||
return { };
|
||||
}
|
||||
|
||||
KResultOr<Region*> FileDescriptor::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
|
||||
KResultOr<Region*> FileDescription::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
|
||||
{
|
||||
return m_file->mmap(process, *this, laddr, offset, size, prot);
|
||||
}
|
||||
|
||||
KResult FileDescriptor::truncate(off_t length)
|
||||
KResult FileDescription::truncate(off_t length)
|
||||
{
|
||||
return m_file->truncate(length);
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_shared_memory() const
|
||||
bool FileDescription::is_shared_memory() const
|
||||
{
|
||||
return m_file->is_shared_memory();
|
||||
}
|
||||
|
||||
SharedMemory* FileDescriptor::shared_memory()
|
||||
SharedMemory* FileDescription::shared_memory()
|
||||
{
|
||||
if (!is_shared_memory())
|
||||
return nullptr;
|
||||
return static_cast<SharedMemory*>(m_file.ptr());
|
||||
}
|
||||
|
||||
const SharedMemory* FileDescriptor::shared_memory() const
|
||||
const SharedMemory* FileDescription::shared_memory() const
|
||||
{
|
||||
if (!is_shared_memory())
|
||||
return nullptr;
|
||||
return static_cast<const SharedMemory*>(m_file.ptr());
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_fifo() const
|
||||
bool FileDescription::is_fifo() const
|
||||
{
|
||||
return m_file->is_fifo();
|
||||
}
|
||||
|
||||
FIFO* FileDescriptor::fifo()
|
||||
FIFO* FileDescription::fifo()
|
||||
{
|
||||
if (!is_fifo())
|
||||
return nullptr;
|
||||
return static_cast<FIFO*>(m_file.ptr());
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_socket() const
|
||||
bool FileDescription::is_socket() const
|
||||
{
|
||||
return m_file->is_socket();
|
||||
}
|
||||
|
||||
Socket* FileDescriptor::socket()
|
||||
Socket* FileDescription::socket()
|
||||
{
|
||||
if (!is_socket())
|
||||
return nullptr;
|
||||
return static_cast<Socket*>(m_file.ptr());
|
||||
}
|
||||
|
||||
const Socket* FileDescriptor::socket() const
|
||||
const Socket* FileDescription::socket() const
|
||||
{
|
||||
if (!is_socket())
|
||||
return nullptr;
|
||||
return static_cast<const Socket*>(m_file.ptr());
|
||||
}
|
||||
|
||||
void FileDescriptor::set_file_flags(dword flags)
|
||||
void FileDescription::set_file_flags(dword flags)
|
||||
{
|
||||
m_is_blocking = !(flags & O_NONBLOCK);
|
||||
m_should_append = flags & O_APPEND;
|
||||
m_file_flags = flags;
|
||||
}
|
||||
|
||||
KResult FileDescriptor::chown(uid_t uid, gid_t gid)
|
||||
KResult FileDescription::chown(uid_t uid, gid_t gid)
|
||||
{
|
||||
if (!m_inode)
|
||||
return KResult(-EINVAL);
|
|
@ -19,13 +19,13 @@ class Region;
|
|||
class CharacterDevice;
|
||||
class SharedMemory;
|
||||
|
||||
class FileDescriptor : public Retainable<FileDescriptor> {
|
||||
class FileDescription : public Retainable<FileDescription> {
|
||||
public:
|
||||
static Retained<FileDescriptor> create(RetainPtr<Custody>&&);
|
||||
static Retained<FileDescriptor> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||
~FileDescriptor();
|
||||
static Retained<FileDescription> create(RetainPtr<Custody>&&);
|
||||
static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||
~FileDescription();
|
||||
|
||||
Retained<FileDescriptor> clone();
|
||||
Retained<FileDescription> clone();
|
||||
|
||||
int close();
|
||||
|
||||
|
@ -105,8 +105,8 @@ public:
|
|||
|
||||
private:
|
||||
friend class VFS;
|
||||
FileDescriptor(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||
FileDescriptor(FIFO&, FIFO::Direction);
|
||||
FileDescription(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||
FileDescription(FIFO&, FIFO::Direction);
|
||||
|
||||
RetainPtr<Custody> m_custody;
|
||||
RetainPtr<Inode> m_inode;
|
|
@ -19,7 +19,7 @@
|
|||
static const dword mepoch = 476763780;
|
||||
|
||||
class Inode;
|
||||
class FileDescriptor;
|
||||
class FileDescription;
|
||||
class LocalSocket;
|
||||
class VMObject;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ void Inode::sync()
|
|||
}
|
||||
}
|
||||
|
||||
ByteBuffer Inode::read_entire(FileDescriptor* descriptor) const
|
||||
ByteBuffer Inode::read_entire(FileDescription* descriptor) const
|
||||
{
|
||||
size_t initial_size = metadata().size ? metadata().size : 4096;
|
||||
StringBuilder builder(initial_size);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <Kernel/KResult.h>
|
||||
#include <Kernel/Lock.h>
|
||||
|
||||
class FileDescriptor;
|
||||
class FileDescription;
|
||||
class LocalSocket;
|
||||
class VMObject;
|
||||
|
||||
|
@ -37,12 +37,12 @@ public:
|
|||
InodeIdentifier identifier() const { return { fsid(), index() }; }
|
||||
virtual InodeMetadata metadata() const = 0;
|
||||
|
||||
ByteBuffer read_entire(FileDescriptor* = nullptr) const;
|
||||
ByteBuffer read_entire(FileDescription* = nullptr) const;
|
||||
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const = 0;
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const = 0;
|
||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const = 0;
|
||||
virtual InodeIdentifier lookup(StringView name) = 0;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) = 0;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) = 0;
|
||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) = 0;
|
||||
virtual KResult remove_child(const String& name) = 0;
|
||||
virtual size_t directory_entry_count() const = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <Kernel/FileSystem/InodeFile.h>
|
||||
#include <Kernel/FileSystem/Inode.h>
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/Process.h>
|
||||
|
||||
|
@ -13,17 +13,17 @@ InodeFile::~InodeFile()
|
|||
{
|
||||
}
|
||||
|
||||
ssize_t InodeFile::read(FileDescriptor& descriptor, byte* buffer, ssize_t count)
|
||||
ssize_t InodeFile::read(FileDescription& descriptor, byte* buffer, ssize_t count)
|
||||
{
|
||||
return m_inode->read_bytes(descriptor.offset(), count, buffer, &descriptor);
|
||||
}
|
||||
|
||||
ssize_t InodeFile::write(FileDescriptor& descriptor, const byte* data, ssize_t count)
|
||||
ssize_t InodeFile::write(FileDescription& descriptor, const byte* data, ssize_t count)
|
||||
{
|
||||
return m_inode->write_bytes(descriptor.offset(), count, data, &descriptor);
|
||||
}
|
||||
|
||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescriptor& descriptor, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptor, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
||||
{
|
||||
ASSERT(offset == 0);
|
||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||
|
@ -34,7 +34,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescriptor& descriptor,
|
|||
return region;
|
||||
}
|
||||
|
||||
String InodeFile::absolute_path(const FileDescriptor& descriptor) const
|
||||
String InodeFile::absolute_path(const FileDescription& descriptor) const
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
ASSERT(descriptor.custody());
|
||||
|
|
|
@ -16,14 +16,14 @@ public:
|
|||
const Inode& inode() const { return *m_inode; }
|
||||
Inode& inode() { return *m_inode; }
|
||||
|
||||
virtual bool can_read(FileDescriptor&) const override { return true; }
|
||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
||||
virtual bool can_read(FileDescription&) const override { return true; }
|
||||
virtual bool can_write(FileDescription&) const override { return true; }
|
||||
|
||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescriptor&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot) override;
|
||||
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot) override;
|
||||
|
||||
virtual String absolute_path(const FileDescriptor&) const override;
|
||||
virtual String absolute_path(const FileDescription&) const override;
|
||||
|
||||
virtual KResult truncate(off_t) override;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "ProcFS.h"
|
||||
#include "Process.h"
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/VM/MemoryManager.h>
|
||||
#include "StdLib.h"
|
||||
|
@ -189,7 +189,7 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
|
|||
return { };
|
||||
StringBuilder builder;
|
||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||
auto* descriptor = process.file_descriptor(i);
|
||||
auto* descriptor = process.file_description(i);
|
||||
if (!descriptor)
|
||||
continue;
|
||||
builder.appendf("% 3u %s\n", i, descriptor->absolute_path().characters());
|
||||
|
@ -204,7 +204,7 @@ ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)
|
|||
return { };
|
||||
auto& process = handle->process();
|
||||
int fd = to_fd(identifier);
|
||||
auto* descriptor = process.file_descriptor(fd);
|
||||
auto* descriptor = process.file_description(fd);
|
||||
if (!descriptor)
|
||||
return { };
|
||||
return descriptor->absolute_path().to_byte_buffer();
|
||||
|
@ -835,7 +835,7 @@ InodeMetadata ProcFSInode::metadata() const
|
|||
return metadata;
|
||||
}
|
||||
|
||||
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const
|
||||
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
||||
{
|
||||
#ifdef PROCFS_DEBUG
|
||||
dbgprintf("ProcFS: read_bytes %u\n", index());
|
||||
|
@ -941,7 +941,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
|||
return false;
|
||||
auto& process = handle->process();
|
||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||
auto* descriptor = process.file_descriptor(i);
|
||||
auto* descriptor = process.file_description(i);
|
||||
if (!descriptor)
|
||||
continue;
|
||||
char name[16];
|
||||
|
@ -1027,7 +1027,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
|||
{
|
||||
InterruptDisabler disabler;
|
||||
if (auto* process = Process::from_pid(to_pid(identifier())))
|
||||
fd_exists = process->file_descriptor(name_as_number);
|
||||
fd_exists = process->file_description(name_as_number);
|
||||
|
||||
}
|
||||
if (fd_exists)
|
||||
|
@ -1041,7 +1041,7 @@ void ProcFSInode::flush_metadata()
|
|||
{
|
||||
}
|
||||
|
||||
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*)
|
||||
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*)
|
||||
{
|
||||
auto* directory_entry = fs().get_directory_entry(identifier());
|
||||
if (!directory_entry || !directory_entry->write_callback)
|
||||
|
|
|
@ -80,12 +80,12 @@ public:
|
|||
|
||||
private:
|
||||
// ^Inode
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||
virtual InodeMetadata metadata() const override;
|
||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||
virtual InodeIdentifier lookup(StringView name) override;
|
||||
virtual void flush_metadata() override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override;
|
||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||
virtual KResult remove_child(const String& name) override;
|
||||
virtual size_t directory_entry_count() const override;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <Kernel/FileSystem/SyntheticFileSystem.h>
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <LibC/errno_numbers.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
|
@ -185,7 +185,7 @@ InodeMetadata SynthFSInode::metadata() const
|
|||
return m_metadata;
|
||||
}
|
||||
|
||||
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const
|
||||
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
#ifdef SYNTHFS_DEBUG
|
||||
|
@ -250,7 +250,7 @@ void SynthFSInode::flush_metadata()
|
|||
{
|
||||
}
|
||||
|
||||
ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*)
|
||||
ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
if (!m_write_callback)
|
||||
|
|
|
@ -57,12 +57,12 @@ public:
|
|||
|
||||
private:
|
||||
// ^Inode
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||
virtual InodeMetadata metadata() const override;
|
||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||
virtual InodeIdentifier lookup(StringView name) override;
|
||||
virtual void flush_metadata() override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override;
|
||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override;
|
||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||
virtual KResult remove_child(const String& name) override;
|
||||
virtual size_t directory_entry_count() const override;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "VirtualFileSystem.h"
|
||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include "FileSystem.h"
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
@ -149,7 +149,7 @@ KResult VFS::stat(StringView path, int options, Custody& base, struct stat& stat
|
|||
return custody_or_error.value()->inode().metadata().stat(statbuf);
|
||||
}
|
||||
|
||||
KResultOr<Retained<FileDescriptor>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
|
||||
KResultOr<Retained<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
|
||||
{
|
||||
auto custody_or_error = resolve_path(path, base, nullptr, options);
|
||||
if (options & O_CREAT) {
|
||||
|
@ -194,7 +194,7 @@ KResultOr<Retained<FileDescriptor>> VFS::open(StringView path, int options, mode
|
|||
}
|
||||
if (should_truncate_file)
|
||||
inode.truncate(0);
|
||||
return FileDescriptor::create(custody);
|
||||
return FileDescription::create(custody);
|
||||
}
|
||||
|
||||
KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
|
||||
|
@ -224,7 +224,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
|
|||
return KSuccess;
|
||||
}
|
||||
|
||||
KResultOr<Retained<FileDescriptor>> VFS::create(StringView path, int options, mode_t mode, Custody& base)
|
||||
KResultOr<Retained<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& base)
|
||||
{
|
||||
(void)options;
|
||||
|
||||
|
@ -253,7 +253,7 @@ KResultOr<Retained<FileDescriptor>> VFS::create(StringView path, int options, mo
|
|||
return KResult(error);
|
||||
|
||||
auto new_custody = Custody::create(parent_custody, p.basename(), *new_file);
|
||||
return FileDescriptor::create(*new_custody);
|
||||
return FileDescription::create(*new_custody);
|
||||
}
|
||||
|
||||
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
class Custody;
|
||||
class Device;
|
||||
class FileDescriptor;
|
||||
class FileDescription;
|
||||
|
||||
class VFS {
|
||||
AK_MAKE_ETERNAL
|
||||
|
@ -59,9 +59,9 @@ public:
|
|||
bool mount_root(Retained<FS>&&);
|
||||
bool mount(Retained<FS>&&, StringView path);
|
||||
|
||||
KResultOr<Retained<FileDescriptor>> open(RetainPtr<Device>&&, int options);
|
||||
KResultOr<Retained<FileDescriptor>> open(StringView path, int options, mode_t mode, Custody& base);
|
||||
KResultOr<Retained<FileDescriptor>> create(StringView path, int options, mode_t mode, Custody& base);
|
||||
KResultOr<Retained<FileDescription>> open(RetainPtr<Device>&&, int options);
|
||||
KResultOr<Retained<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
||||
KResultOr<Retained<FileDescription>> create(StringView path, int options, mode_t mode, Custody& base);
|
||||
KResult mkdir(StringView path, mode_t mode, Custody& base);
|
||||
KResult link(StringView old_path, StringView new_path, Custody& base);
|
||||
KResult unlink(StringView path, Custody& base);
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
KResultOr<Retained<Custody>> resolve_path(StringView path, Custody& base, RetainPtr<Custody>* parent = nullptr, int options = 0);
|
||||
|
||||
private:
|
||||
friend class FileDescriptor;
|
||||
friend class FileDescription;
|
||||
|
||||
RetainPtr<Inode> get_inode(InodeIdentifier);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue