diff options
Diffstat (limited to 'Kernel/FileSystem')
37 files changed, 262 insertions, 262 deletions
diff --git a/Kernel/FileSystem/AnonymousFile.cpp b/Kernel/FileSystem/AnonymousFile.cpp index b56cd2966b..0c6ba54945 100644 --- a/Kernel/FileSystem/AnonymousFile.cpp +++ b/Kernel/FileSystem/AnonymousFile.cpp @@ -19,7 +19,7 @@ AnonymousFile::~AnonymousFile() { } -KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, FileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) +KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) { if (offset != 0) return EINVAL; diff --git a/Kernel/FileSystem/AnonymousFile.h b/Kernel/FileSystem/AnonymousFile.h index bbca01859d..5909763339 100644 --- a/Kernel/FileSystem/AnonymousFile.h +++ b/Kernel/FileSystem/AnonymousFile.h @@ -20,15 +20,15 @@ public: virtual ~AnonymousFile() override; - virtual KResultOr<Memory::Region*> mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override; + virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override; private: virtual StringView class_name() const override { return "AnonymousFile"; } - virtual String absolute_path(const FileDescription&) const override { return ":anonymous-file:"; } - virtual bool can_read(const FileDescription&, size_t) const override { return false; } - virtual bool can_write(const FileDescription&, size_t) const override { return false; } - virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; } - virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; } + virtual String absolute_path(const OpenFileDescription&) const override { return ":anonymous-file:"; } + virtual bool can_read(const OpenFileDescription&, size_t) const override { return false; } + virtual bool can_write(const OpenFileDescription&, size_t) const override { return false; } + virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; } + virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return ENOTSUP; } explicit AnonymousFile(NonnullRefPtr<Memory::AnonymousVMObject>); diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index cfc02a650b..34bf759db6 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -104,7 +104,7 @@ private: bool m_dirty { false }; }; -BlockBasedFileSystem::BlockBasedFileSystem(FileDescription& file_description) +BlockBasedFileSystem::BlockBasedFileSystem(OpenFileDescription& file_description) : FileBackedFileSystem(file_description) { VERIFY(file_description.file().is_seekable()); diff --git a/Kernel/FileSystem/BlockBasedFileSystem.h b/Kernel/FileSystem/BlockBasedFileSystem.h index f9856b6c52..12f8d4ee9d 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.h +++ b/Kernel/FileSystem/BlockBasedFileSystem.h @@ -24,7 +24,7 @@ public: void flush_writes_impl(); protected: - explicit BlockBasedFileSystem(FileDescription&); + explicit BlockBasedFileSystem(OpenFileDescription&); KResult read_block(BlockIndex, UserOrKernelBuffer*, size_t count, size_t offset = 0, bool allow_cache = true) const; KResult read_blocks(BlockIndex, unsigned count, UserOrKernelBuffer&, bool allow_cache = true) const; diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 3b2f5a12d6..b1d2a93b15 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -80,7 +80,7 @@ DevFSInode::DevFSInode(DevFS& fs) { } -KResultOr<size_t> DevFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const +KResultOr<size_t> DevFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } @@ -99,7 +99,7 @@ void DevFSInode::flush_metadata() { } -KResultOr<size_t> DevFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, FileDescription*) +KResultOr<size_t> DevFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { VERIFY_NOT_REACHED(); } @@ -149,7 +149,7 @@ DevFSLinkInode::DevFSLinkInode(DevFS& fs, NonnullOwnPtr<KString> name) { } -KResultOr<size_t> DevFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, FileDescription*) const +KResultOr<size_t> DevFSLinkInode::read_bytes(off_t offset, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const { MutexLocker locker(m_inode_lock); VERIFY(offset == 0); @@ -170,7 +170,7 @@ InodeMetadata DevFSLinkInode::metadata() const return metadata; } -KResultOr<size_t> DevFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, FileDescription*) +KResultOr<size_t> DevFSLinkInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription*) { auto new_string = TRY(buffer.try_copy_into_kstring(count)); @@ -326,7 +326,7 @@ StringView DevFSDeviceInode::name() const return m_name->view(); } -KResultOr<size_t> DevFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* description) const +KResultOr<size_t> DevFSDeviceInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const { MutexLocker locker(m_inode_lock); VERIFY(!!description); @@ -352,7 +352,7 @@ InodeMetadata DevFSDeviceInode::metadata() const metadata.minor_device = m_attached_device->minor(); return metadata; } -KResultOr<size_t> DevFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, FileDescription* description) +KResultOr<size_t> DevFSDeviceInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* description) { MutexLocker locker(m_inode_lock); VERIFY(!!description); diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h index ddf64c4f64..9c76ba3427 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevFS.h @@ -53,11 +53,11 @@ public: protected: DevFSInode(DevFS&); - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode&, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; @@ -77,9 +77,9 @@ public: private: DevFSDeviceInode(DevFS&, Device const&, NonnullOwnPtr<KString> name); // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; virtual KResult chown(UserID, GroupID) override; NonnullRefPtr<Device> m_attached_device; @@ -100,9 +100,9 @@ public: protected: DevFSLinkInode(DevFS&, NonnullOwnPtr<KString>); // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; NonnullOwnPtr<KString> m_name; OwnPtr<KString> m_link; diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index fd960674ba..9543c26ff2 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -84,12 +84,12 @@ DevPtsFSInode::~DevPtsFSInode() { } -KResultOr<size_t> DevPtsFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const +KResultOr<size_t> DevPtsFSInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } -KResultOr<size_t> DevPtsFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, FileDescription*) +KResultOr<size_t> DevPtsFSInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { VERIFY_NOT_REACHED(); } diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS.h index af2549a222..11a336039b 100644 --- a/Kernel/FileSystem/DevPtsFS.h +++ b/Kernel/FileSystem/DevPtsFS.h @@ -47,12 +47,12 @@ private: DevPtsFSInode(DevPtsFS&, InodeIndex, SlavePTY*); // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode&, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index cc023aabc2..567412d45c 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -12,7 +12,7 @@ #include <Kernel/Debug.h> #include <Kernel/Devices/BlockDevice.h> #include <Kernel/FileSystem/Ext2FileSystem.h> -#include <Kernel/FileSystem/FileDescription.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/FileSystem/ext2_fs.h> #include <Kernel/Process.h> #include <Kernel/UnixTypes.h> @@ -54,12 +54,12 @@ static unsigned divide_rounded_up(unsigned a, unsigned b) return (a / b) + (a % b != 0); } -KResultOr<NonnullRefPtr<Ext2FS>> Ext2FS::try_create(FileDescription& file_description) +KResultOr<NonnullRefPtr<Ext2FS>> Ext2FS::try_create(OpenFileDescription& file_description) { return adopt_nonnull_ref_or_enomem(new (nothrow) Ext2FS(file_description)); } -Ext2FS::Ext2FS(FileDescription& file_description) +Ext2FS::Ext2FS(OpenFileDescription& file_description) : BlockBasedFileSystem(file_description) { } @@ -827,7 +827,7 @@ KResultOr<NonnullRefPtr<Inode>> Ext2FS::get_inode(InodeIdentifier inode) const return new_inode; } -KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* description) const +KResultOr<size_t> Ext2FSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const { MutexLocker inode_locker(m_inode_lock); VERIFY(offset >= 0); @@ -965,7 +965,7 @@ KResult Ext2FSInode::resize(u64 new_size) return KSuccess; } -KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& data, FileDescription* description) +KResultOr<size_t> Ext2FSInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& data, OpenFileDescription* description) { VERIFY(offset >= 0); diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index 1ed08416c0..1da3ccf9aa 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -38,12 +38,12 @@ public: private: // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode& child, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; @@ -89,7 +89,7 @@ public: FileSize64bits = 1 << 1, }; - static KResultOr<NonnullRefPtr<Ext2FS>> try_create(FileDescription&); + static KResultOr<NonnullRefPtr<Ext2FS>> try_create(OpenFileDescription&); virtual ~Ext2FS() override; virtual KResult initialize() override; @@ -110,7 +110,7 @@ public: private: TYPEDEF_DISTINCT_ORDERED_ID(unsigned, GroupIndex); - explicit Ext2FS(FileDescription&); + explicit Ext2FS(OpenFileDescription&); const ext2_super_block& super_block() const { return m_super_block; } const ext2_group_desc& group_descriptor(GroupIndex) const; diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index c728748326..a9cfd1e7fa 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -7,7 +7,7 @@ #include <AK/Atomic.h> #include <AK/StdLibExtras.h> #include <Kernel/FileSystem/FIFO.h> -#include <Kernel/FileSystem/FileDescription.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/Locking/Mutex.h> #include <Kernel/Process.h> #include <Kernel/Thread.h> @@ -24,15 +24,15 @@ RefPtr<FIFO> FIFO::try_create(UserID uid) return {}; } -KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction(FIFO::Direction direction) +KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction) { - auto description = TRY(FileDescription::try_create(*this)); + auto description = TRY(OpenFileDescription::try_create(*this)); attach(direction); description->set_fifo_direction({}, direction); return description; } -KResultOr<NonnullRefPtr<FileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction) +KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction_blocking(FIFO::Direction direction) { MutexLocker locker(m_open_lock); @@ -101,17 +101,17 @@ void FIFO::detach(Direction direction) evaluate_block_conditions(); } -bool FIFO::can_read(const FileDescription&, size_t) const +bool FIFO::can_read(const OpenFileDescription&, size_t) const { return !m_buffer->is_empty() || !m_writers; } -bool FIFO::can_write(const FileDescription&, size_t) const +bool FIFO::can_write(const OpenFileDescription&, size_t) const { return m_buffer->space_for_writing() || !m_readers; } -KResultOr<size_t> FIFO::read(FileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size) +KResultOr<size_t> FIFO::read(OpenFileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size) { if (m_buffer->is_empty()) { if (!m_writers) @@ -122,7 +122,7 @@ KResultOr<size_t> FIFO::read(FileDescription& fd, u64, UserOrKernelBuffer& buffe return m_buffer->read(buffer, size); } -KResultOr<size_t> FIFO::write(FileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size) +KResultOr<size_t> FIFO::write(OpenFileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size) { if (!m_readers) { Thread::current()->send_signal(SIGPIPE, &Process::current()); @@ -134,7 +134,7 @@ KResultOr<size_t> FIFO::write(FileDescription& fd, u64, const UserOrKernelBuffer return m_buffer->write(buffer, size); } -String FIFO::absolute_path(const FileDescription&) const +String FIFO::absolute_path(const OpenFileDescription&) const { return String::formatted("fifo:{}", m_fifo_id); } diff --git a/Kernel/FileSystem/FIFO.h b/Kernel/FileSystem/FIFO.h index 84c35b7d44..55d2649a03 100644 --- a/Kernel/FileSystem/FIFO.h +++ b/Kernel/FileSystem/FIFO.h @@ -14,7 +14,7 @@ namespace Kernel { -class FileDescription; +class OpenFileDescription; class FIFO final : public File { public: @@ -29,8 +29,8 @@ public: UserID uid() const { return m_uid; } - KResultOr<NonnullRefPtr<FileDescription>> open_direction(Direction); - KResultOr<NonnullRefPtr<FileDescription>> open_direction_blocking(Direction); + KResultOr<NonnullRefPtr<OpenFileDescription>> open_direction(Direction); + KResultOr<NonnullRefPtr<OpenFileDescription>> open_direction_blocking(Direction); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Woverloaded-virtual" @@ -40,12 +40,12 @@ public: private: // ^File - virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override; - virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override; + virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override; + virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual KResult stat(::stat&) const override; - virtual bool can_read(const FileDescription&, size_t) const override; - virtual bool can_write(const FileDescription&, size_t) const override; - virtual String absolute_path(const FileDescription&) const override; + virtual bool can_read(const OpenFileDescription&, size_t) const override; + virtual bool can_write(const OpenFileDescription&, size_t) const override; + virtual String absolute_path(const OpenFileDescription&) const override; virtual StringView class_name() const override { return "FIFO"; } virtual bool is_fifo() const override { return true; } diff --git a/Kernel/FileSystem/File.cpp b/Kernel/FileSystem/File.cpp index e9f44cefd2..ac03665b9c 100644 --- a/Kernel/FileSystem/File.cpp +++ b/Kernel/FileSystem/File.cpp @@ -7,7 +7,7 @@ #include <AK/StringView.h> #include <AK/Userspace.h> #include <Kernel/FileSystem/File.h> -#include <Kernel/FileSystem/FileDescription.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/Process.h> namespace Kernel { @@ -28,9 +28,9 @@ bool File::unref() const return true; } -KResultOr<NonnullRefPtr<FileDescription>> File::open(int options) +KResultOr<NonnullRefPtr<OpenFileDescription>> File::open(int options) { - auto description = FileDescription::try_create(*this); + auto description = OpenFileDescription::try_create(*this); if (!description.is_error()) { description.value()->set_rw_mode(options); description.value()->set_file_flags(options); @@ -43,23 +43,23 @@ KResult File::close() return KSuccess; } -KResult File::ioctl(FileDescription&, unsigned, Userspace<void*>) +KResult File::ioctl(OpenFileDescription&, unsigned, Userspace<void*>) { return ENOTTY; } -KResultOr<Memory::Region*> File::mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64, int, bool) +KResultOr<Memory::Region*> File::mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64, int, bool) { return ENODEV; } -KResult File::attach(FileDescription&) +KResult File::attach(OpenFileDescription&) { m_attach_count++; return KSuccess; } -void File::detach(FileDescription&) +void File::detach(OpenFileDescription&) { m_attach_count--; } diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 10879d0590..52e495411d 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -43,7 +43,7 @@ public: } }; -// File is the base class for anything that can be referenced by a FileDescription. +// File is the base class for anything that can be referenced by a OpenFileDescription. // // The most important functions in File are: // @@ -77,26 +77,26 @@ public: virtual bool unref() const; virtual ~File(); - virtual KResultOr<NonnullRefPtr<FileDescription>> open(int options); + virtual KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options); virtual KResult close(); - virtual bool can_read(const FileDescription&, size_t) const = 0; - virtual bool can_write(const FileDescription&, size_t) const = 0; + virtual bool can_read(const OpenFileDescription&, size_t) const = 0; + virtual bool can_write(const OpenFileDescription&, size_t) const = 0; - virtual KResult attach(FileDescription&); - virtual void detach(FileDescription&); - virtual void did_seek(FileDescription&, off_t) { } - virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) = 0; - virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0; - virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg); - virtual KResultOr<Memory::Region*> mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared); + virtual KResult attach(OpenFileDescription&); + virtual void detach(OpenFileDescription&); + virtual void did_seek(OpenFileDescription&, off_t) { } + virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) = 0; + virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) = 0; + virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg); + virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared); virtual KResult stat(::stat&) const { return EBADF; } - virtual String absolute_path(const FileDescription&) const = 0; + virtual String absolute_path(const OpenFileDescription&) const = 0; virtual KResult truncate(u64) { return EINVAL; } - virtual KResult chown(FileDescription&, UserID, GroupID) { return EBADF; } - virtual KResult chmod(FileDescription&, mode_t) { return EBADF; } + virtual KResult chown(OpenFileDescription&, UserID, GroupID) { return EBADF; } + virtual KResult chmod(OpenFileDescription&, mode_t) { return EBADF; } virtual StringView class_name() const = 0; diff --git a/Kernel/FileSystem/FileBackedFileSystem.cpp b/Kernel/FileSystem/FileBackedFileSystem.cpp index 97f08716b4..44ee0a70ff 100644 --- a/Kernel/FileSystem/FileBackedFileSystem.cpp +++ b/Kernel/FileSystem/FileBackedFileSystem.cpp @@ -8,7 +8,7 @@ namespace Kernel { -FileBackedFileSystem::FileBackedFileSystem(FileDescription& file_description) +FileBackedFileSystem::FileBackedFileSystem(OpenFileDescription& file_description) : m_file_description(file_description) { } diff --git a/Kernel/FileSystem/FileBackedFileSystem.h b/Kernel/FileSystem/FileBackedFileSystem.h index 623c545485..95cfc42337 100644 --- a/Kernel/FileSystem/FileBackedFileSystem.h +++ b/Kernel/FileSystem/FileBackedFileSystem.h @@ -6,8 +6,8 @@ #pragma once -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileSystem.h> +#include <Kernel/FileSystem/OpenFileDescription.h> namespace Kernel { @@ -16,17 +16,17 @@ public: virtual ~FileBackedFileSystem() override; File& file() { return m_file_description->file(); } - FileDescription& file_description() { return *m_file_description; } + OpenFileDescription& file_description() { return *m_file_description; } const File& file() const { return m_file_description->file(); } - FileDescription& file_description() const { return *m_file_description; } + OpenFileDescription& file_description() const { return *m_file_description; } protected: - explicit FileBackedFileSystem(FileDescription&); + explicit FileBackedFileSystem(OpenFileDescription&); private: virtual bool is_file_backed() const override { return true; } - mutable NonnullRefPtr<FileDescription> m_file_description; + mutable NonnullRefPtr<OpenFileDescription> m_file_description; }; } diff --git a/Kernel/FileSystem/ISO9660FileSystem.cpp b/Kernel/FileSystem/ISO9660FileSystem.cpp index ed72007252..cb5dd95068 100644 --- a/Kernel/FileSystem/ISO9660FileSystem.cpp +++ b/Kernel/FileSystem/ISO9660FileSystem.cpp @@ -171,12 +171,12 @@ private: Vector<DirectoryState> m_directory_stack; }; -KResultOr<NonnullRefPtr<ISO9660FS>> ISO9660FS::try_create(FileDescription& description) +KResultOr<NonnullRefPtr<ISO9660FS>> ISO9660FS::try_create(OpenFileDescription& description) { return adopt_nonnull_ref_or_enomem(new (nothrow) ISO9660FS(description)); } -ISO9660FS::ISO9660FS(FileDescription& description) +ISO9660FS::ISO9660FS(OpenFileDescription& description) : BlockBasedFileSystem(description) { set_block_size(logical_sector_size); @@ -415,7 +415,7 @@ u32 ISO9660FS::calculate_directory_entry_cache_key(ISO::DirectoryRecordHeader co return LittleEndian { record.extent_location.little }; } -KResultOr<size_t> ISO9660Inode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, FileDescription*) const +KResultOr<size_t> ISO9660Inode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const { MutexLocker inode_locker(m_inode_lock); @@ -514,7 +514,7 @@ void ISO9660Inode::flush_metadata() { } -KResultOr<size_t> ISO9660Inode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, FileDescription*) +KResultOr<size_t> ISO9660Inode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { return EROFS; } diff --git a/Kernel/FileSystem/ISO9660FileSystem.h b/Kernel/FileSystem/ISO9660FileSystem.h index fb245aa415..f3d84573b0 100644 --- a/Kernel/FileSystem/ISO9660FileSystem.h +++ b/Kernel/FileSystem/ISO9660FileSystem.h @@ -305,7 +305,7 @@ public: } }; - static KResultOr<NonnullRefPtr<ISO9660FS>> try_create(FileDescription&); + static KResultOr<NonnullRefPtr<ISO9660FS>> try_create(OpenFileDescription&); virtual ~ISO9660FS() override; virtual KResult initialize() override; @@ -320,7 +320,7 @@ public: KResultOr<NonnullRefPtr<DirectoryEntry>> directory_entry_for_record(Badge<ISO9660DirectoryIterator>, ISO::DirectoryRecordHeader const* record); private: - ISO9660FS(FileDescription&); + ISO9660FS(OpenFileDescription&); KResult parse_volume_set(); KResult create_root_inode(); @@ -347,12 +347,12 @@ public: ISO9660FS const& fs() const { return static_cast<ISO9660FS const&>(Inode::fs()); } // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode&, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index 5d5b558a27..bfb7186e29 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -11,9 +11,9 @@ #include <AK/StringView.h> #include <Kernel/API/InodeWatcherEvent.h> #include <Kernel/FileSystem/Custody.h> -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/InodeWatcher.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/KBufferBuilder.h> #include <Kernel/Memory/SharedInodeVMObject.h> @@ -45,7 +45,7 @@ void Inode::sync() } } -KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(FileDescription* description) const +KResultOr<NonnullOwnPtr<KBuffer>> Inode::read_entire(OpenFileDescription* description) const { KBufferBuilder builder; @@ -267,7 +267,7 @@ static inline bool range_overlap(T start1, T len1, T start2, T len2) return ((start1 < start2 + len2) || len2 == 0) && ((start2 < start1 + len1) || len1 == 0); } -static inline KResult normalize_flock(FileDescription const& description, flock& lock) +static inline KResult normalize_flock(OpenFileDescription const& description, flock& lock) { off_t start; switch (lock.l_whence) { @@ -287,7 +287,7 @@ static inline KResult normalize_flock(FileDescription const& description, flock& return KSuccess; } -KResult Inode::can_apply_flock(FileDescription const& description, flock const& new_lock) const +KResult Inode::can_apply_flock(OpenFileDescription const& description, flock const& new_lock) const { VERIFY(new_lock.l_whence == SEEK_SET); @@ -314,7 +314,7 @@ KResult Inode::can_apply_flock(FileDescription const& description, flock const& return KSuccess; } -KResult Inode::apply_flock(Process const& process, FileDescription const& description, Userspace<flock const*> input_lock) +KResult Inode::apply_flock(Process const& process, OpenFileDescription const& description, Userspace<flock const*> input_lock) { flock new_lock = {}; TRY(copy_from_user(&new_lock, input_lock)); @@ -338,7 +338,7 @@ KResult Inode::apply_flock(Process const& process, FileDescription const& descri return KSuccess; } -KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> reference_lock) const +KResult Inode::get_flock(OpenFileDescription const& description, Userspace<flock*> reference_lock) const { flock lookup = {}; TRY(copy_from_user(&lookup, reference_lock)); @@ -360,7 +360,7 @@ KResult Inode::get_flock(FileDescription const& description, Userspace<flock*> r return copy_to_user(reference_lock, &lookup); } -void Inode::remove_flocks_for_description(FileDescription const& description) +void Inode::remove_flocks_for_description(OpenFileDescription const& description) { MutexLocker locker(m_inode_lock); diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 3d963b2059..5c3db8f135 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -46,15 +46,15 @@ public: InodeIdentifier identifier() const { return { fsid(), index() }; } virtual InodeMetadata metadata() const = 0; - KResultOr<NonnullOwnPtr<KBuffer>> read_entire(FileDescription* = nullptr) const; + KResultOr<NonnullOwnPtr<KBuffer>> read_entire(OpenFileDescription* = nullptr) const; - virtual KResult attach(FileDescription&) { return KSuccess; } - virtual void detach(FileDescription&) { } - virtual void did_seek(FileDescription&, off_t) { } - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const = 0; + virtual KResult attach(OpenFileDescription&) { return KSuccess; } + virtual void detach(OpenFileDescription&) { } + virtual void did_seek(OpenFileDescription&, off_t) { } + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const = 0; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const = 0; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) = 0; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, FileDescription*) = 0; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) = 0; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0; virtual KResult add_child(Inode&, const StringView& name, mode_t) = 0; virtual KResult remove_child(const StringView& name) = 0; @@ -70,7 +70,7 @@ public: bool bind_socket(LocalSocket&); bool unbind_socket(); - virtual FileDescription* preopen_fd() { return nullptr; }; + virtual OpenFileDescription* preopen_fd() { return nullptr; }; bool is_metadata_dirty() const { return m_metadata_dirty; } @@ -96,10 +96,10 @@ public: NonnullRefPtr<FIFO> fifo(); - KResult can_apply_flock(FileDescription const&, flock const&) const; - KResult apply_flock(Process const&, FileDescription const&, Userspace<flock const*>); - KResult get_flock(FileDescription const&, Userspace<flock*>) const; - void remove_flocks_for_description(FileDescription const&); + KResult can_apply_flock(OpenFileDescription const&, flock const&) const; + KResult apply_flock(Process const&, OpenFileDescription const&, Userspace<flock const*>); + KResult get_flock(OpenFileDescription const&, Userspace<flock*>) const; + void remove_flocks_for_description(OpenFileDescription const&); protected: Inode(FileSystem&, InodeIndex); @@ -127,7 +127,7 @@ private: short type; off_t start; off_t len; - FileDescription const* owner; + OpenFileDescription const* owner; pid_t pid; }; diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index 47373cebf5..ecbdcaa05a 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -5,9 +5,9 @@ */ #include <AK/StringView.h> -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/Inode.h> #include <Kernel/FileSystem/InodeFile.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/Memory/PrivateInodeVMObject.h> #include <Kernel/Memory/SharedInodeVMObject.h> @@ -26,7 +26,7 @@ InodeFile::~InodeFile() { } -KResultOr<size_t> InodeFile::read(FileDescription& description, u64 offset, UserOrKernelBuffer& buffer, size_t count) +KResultOr<size_t> InodeFile::read(OpenFileDescription& description, u64 offset, UserOrKernelBuffer& buffer, size_t count) { if (Checked<off_t>::addition_would_overflow(offset, count)) return EOVERFLOW; @@ -39,7 +39,7 @@ KResultOr<size_t> InodeFile::read(FileDescription& description, u64 offset, User return nread; } -KResultOr<size_t> InodeFile::write(FileDescription& description, u64 offset, const UserOrKernelBuffer& data, size_t count) +KResultOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset, const UserOrKernelBuffer& data, size_t count) { if (Checked<off_t>::addition_would_overflow(offset, count)) return EOVERFLOW; @@ -55,7 +55,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, u64 offset, con return nwritten; } -KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspace<void*> arg) +KResult InodeFile::ioctl(OpenFileDescription& description, unsigned request, Userspace<void*> arg) { switch (request) { case FIBMAP: { @@ -81,7 +81,7 @@ KResult InodeFile::ioctl(FileDescription& description, unsigned request, Userspa } } -KResultOr<Memory::Region*> InodeFile::mmap(Process& process, FileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) +KResultOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) { // FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec. RefPtr<Memory::InodeVMObject> vmobject; @@ -92,7 +92,7 @@ KResultOr<Memory::Region*> InodeFile::mmap(Process& process, FileDescription& de return process.address_space().allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, description.absolute_path(), prot, shared); } -String InodeFile::absolute_path(const FileDescription& description) const +String InodeFile::absolute_path(const OpenFileDescription& description) const { VERIFY_NOT_REACHED(); VERIFY(description.custody()); @@ -106,14 +106,14 @@ KResult InodeFile::truncate(u64 size) return KSuccess; } -KResult InodeFile::chown(FileDescription& description, UserID uid, GroupID gid) +KResult InodeFile::chown(OpenFileDescription& description, UserID uid, GroupID gid) { VERIFY(description.inode() == m_inode); VERIFY(description.custody()); return VirtualFileSystem::the().chown(*description.custody(), uid, gid); } -KResult InodeFile::chmod(FileDescription& description, mode_t mode) +KResult InodeFile::chmod(OpenFileDescription& description, mode_t mode) { VERIFY(description.inode() == m_inode); VERIFY(description.custody()); diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index cc16047dc4..8e7dd7cd8d 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -27,20 +27,20 @@ public: const Inode& inode() const { return *m_inode; } Inode& inode() { return *m_inode; } - virtual bool can_read(const FileDescription&, size_t) const override { return true; } - virtual bool can_write(const FileDescription&, size_t) const override { return true; } + virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; } + virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; } - virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override; - virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override; - virtual KResult ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override; - virtual KResultOr<Memory::Region*> mmap(Process&, FileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override; + virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; + virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override; + virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override; + virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override; virtual KResult stat(::stat& buffer) const override { return inode().metadata().stat(buffer); } - virtual String absolute_path(const FileDescription&) const override; + virtual String absolute_path(const OpenFileDescription&) const override; virtual KResult truncate(u64) override; - virtual KResult chown(FileDescription&, UserID, GroupID) override; - virtual KResult chmod(FileDescription&, mode_t) override; + virtual KResult chown(OpenFileDescription&, UserID, GroupID) override; + virtual KResult chmod(OpenFileDescription&, mode_t) override; virtual StringView class_name() const override { return "InodeFile"; } diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp index 8edd88092f..33624ad440 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -22,13 +22,13 @@ InodeWatcher::~InodeWatcher() (void)close(); } -bool InodeWatcher::can_read(const FileDescription&, size_t) const +bool InodeWatcher::can_read(const OpenFileDescription&, size_t) const { MutexLocker locker(m_lock); return !m_queue.is_empty(); } -KResultOr<size_t> InodeWatcher::read(FileDescription&, u64, UserOrKernelBuffer& buffer, size_t buffer_size) +KResultOr<size_t> InodeWatcher::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t buffer_size) { MutexLocker locker(m_lock); if (m_queue.is_empty()) @@ -81,7 +81,7 @@ KResult InodeWatcher::close() return KSuccess; } -String InodeWatcher::absolute_path(const FileDescription&) const +String InodeWatcher::absolute_path(const OpenFileDescription&) const { return String::formatted("InodeWatcher:({})", m_wd_to_watches.size()); } diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index 01260b2508..041e3ece77 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -43,14 +43,14 @@ public: static KResultOr<NonnullRefPtr<InodeWatcher>> try_create(); virtual ~InodeWatcher() override; - virtual bool can_read(const FileDescription&, size_t) const override; - virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override; + virtual bool can_read(const OpenFileDescription&, size_t) const override; + virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; // Can't write to an inode watcher. - virtual bool can_write(const FileDescription&, size_t) const override { return true; } - virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EIO; } + virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; } + virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EIO; } virtual KResult close() override; - virtual String absolute_path(const FileDescription&) const override; + virtual String absolute_path(const OpenFileDescription&) const override; virtual StringView class_name() const override { return "InodeWatcher"; }; virtual bool is_inode_watcher() const override { return true; } diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/OpenFileDescription.cpp index bd0bc23f6b..05803ecfc6 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/OpenFileDescription.cpp @@ -10,10 +10,10 @@ #include <Kernel/Devices/BlockDevice.h> #include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/FIFO.h> -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileSystem.h> #include <Kernel/FileSystem/InodeFile.h> #include <Kernel/FileSystem/InodeWatcher.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/Memory/MemoryManager.h> #include <Kernel/Net/Socket.h> #include <Kernel/Process.h> @@ -24,24 +24,24 @@ namespace Kernel { -KResultOr<NonnullRefPtr<FileDescription>> FileDescription::try_create(Custody& custody) +KResultOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(Custody& custody) { auto inode_file = TRY(InodeFile::create(custody.inode())); - auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) FileDescription(move(inode_file)))); + auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(move(inode_file)))); description->m_custody = custody; TRY(description->attach()); return description; } -KResultOr<NonnullRefPtr<FileDescription>> FileDescription::try_create(File& file) +KResultOr<NonnullRefPtr<OpenFileDescription>> OpenFileDescription::try_create(File& file) { - auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) FileDescription(file))); + auto description = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) OpenFileDescription(file))); TRY(description->attach()); return description; } -FileDescription::FileDescription(File& file) +OpenFileDescription::OpenFileDescription(File& file) : m_file(file) { if (file.is_inode()) @@ -50,7 +50,7 @@ FileDescription::FileDescription(File& file) m_is_directory = metadata().is_directory(); } -FileDescription::~FileDescription() +OpenFileDescription::~OpenFileDescription() { m_file->detach(*this); if (is_fifo()) @@ -64,14 +64,14 @@ FileDescription::~FileDescription() m_inode->remove_flocks_for_description(*this); } -KResult FileDescription::attach() +KResult OpenFileDescription::attach() { if (m_inode) TRY(m_inode->attach(*this)); return m_file->attach(*this); } -Thread::FileBlocker::BlockFlags FileDescription::should_unblock(Thread::FileBlocker::BlockFlags block_flags) const +Thread::FileBlocker::BlockFlags OpenFileDescription::should_unblock(Thread::FileBlocker::BlockFlags block_flags) const { using BlockFlags = Thread::FileBlocker::BlockFlags; BlockFlags unblock_flags = BlockFlags::None; @@ -92,7 +92,7 @@ Thread::FileBlocker::BlockFlags FileDescription::should_unblock(Thread::FileBloc return unblock_flags; } -KResult FileDescription::stat(::stat& buffer) +KResult OpenFileDescription::stat(::stat& buffer) { MutexLocker locker(m_lock); // FIXME: This is due to the Device class not overriding File::stat(). @@ -101,7 +101,7 @@ KResult FileDescription::stat(::stat& buffer) return m_file->stat(buffer); } -KResultOr<off_t> FileDescription::seek(off_t offset, int whence) +KResultOr<off_t> OpenFileDescription::seek(off_t offset, int whence) { MutexLocker locker(m_lock); if (!m_file->is_seekable()) @@ -142,21 +142,21 @@ KResultOr<off_t> FileDescription::seek(off_t offset, int whence) return m_current_offset; } -KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, u64 offset, size_t count) +KResultOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, u64 offset, size_t count) { if (Checked<u64>::addition_would_overflow(offset, count)) return EOVERFLOW; return m_file->read(*this, offset, buffer, count); } -KResultOr<size_t> FileDescription::write(u64 offset, UserOrKernelBuffer const& data, size_t data_size) +KResultOr<size_t> OpenFileDescription::write(u64 offset, UserOrKernelBuffer const& data, size_t data_size) { if (Checked<u64>::addition_would_overflow(offset, data_size)) return EOVERFLOW; return m_file->write(*this, offset, data, data_size); } -KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, size_t count) +KResultOr<size_t> OpenFileDescription::read(UserOrKernelBuffer& buffer, size_t count) { MutexLocker locker(m_lock); if (Checked<off_t>::addition_would_overflow(m_current_offset, count)) @@ -168,7 +168,7 @@ KResultOr<size_t> FileDescription::read(UserOrKernelBuffer& buffer, size_t count return nread; } -KResultOr<size_t> FileDescription::write(const UserOrKernelBuffer& data, size_t size) +KResultOr<size_t> OpenFileDescription::write(const UserOrKernelBuffer& data, size_t size) { MutexLocker locker(m_lock); if (Checked<off_t>::addition_would_overflow(m_current_offset, size)) @@ -180,17 +180,17 @@ KResultOr<size_t> FileDescription::write(const UserOrKernelBuffer& data, size_t return nwritten; } -bool FileDescription::can_write() const +bool OpenFileDescription::can_write() const { return m_file->can_write(*this, offset()); } -bool FileDescription::can_read() const +bool OpenFileDescription::can_read() const { return m_file->can_read(*this, offset()); } -KResultOr<NonnullOwnPtr<KBuffer>> FileDescription::read_entire_file() +KResultOr<NonnullOwnPtr<KBuffer>> OpenFileDescription::read_entire_file() { // HACK ALERT: (This entire function) VERIFY(m_file->is_inode()); @@ -198,7 +198,7 @@ KResultOr<NonnullOwnPtr<KBuffer>> FileDescription::read_entire_file() return m_inode->read_entire(this); } -KResultOr<size_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, size_t size) +KResultOr<size_t> OpenFileDescription::get_dir_entries(UserOrKernelBuffer& output_buffer, size_t size) { MutexLocker locker(m_lock, Mutex::Mode::Shared); if (!is_directory()) @@ -261,90 +261,90 @@ KResultOr<size_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_bu return size - remaining; } -bool FileDescription::is_device() const +bool OpenFileDescription::is_device() const { return m_file->is_device(); } -const Device* FileDescription::device() const +const Device* OpenFileDescription::device() const { if (!is_device()) return nullptr; return static_cast<const Device*>(m_file.ptr()); } -Device* FileDescription::device() +Device* OpenFileDescription::device() { if (!is_device()) return nullptr; return static_cast<Device*>(m_file.ptr()); } -bool FileDescription::is_tty() const +bool OpenFileDescription::is_tty() const { return m_file->is_tty(); } -const TTY* FileDescription::tty() const +const TTY* OpenFileDescription::tty() const { if (!is_tty()) return nullptr; return static_cast<const TTY*>(m_file.ptr()); } -TTY* FileDescription::tty() +TTY* OpenFileDescription::tty() { if (!is_tty()) return nullptr; return static_cast<TTY*>(m_file.ptr()); } -bool FileDescription::is_inode_watcher() const +bool OpenFileDescription::is_inode_watcher() const { return m_file->is_inode_watcher(); } -const InodeWatcher* FileDescription::inode_watcher() const +const InodeWatcher* OpenFileDescription::inode_watcher() const { if (!is_inode_watcher()) return nullptr; return static_cast<const InodeWatcher*>(m_file.ptr()); } -InodeWatcher* FileDescription::inode_watcher() +InodeWatcher* OpenFileDescription::inode_watcher() { if (!is_inode_watcher()) return nullptr; return static_cast<InodeWatcher*>(m_file.ptr()); } -bool FileDescription::is_master_pty() const +bool OpenFileDescription::is_master_pty() const { return m_file->is_master_pty(); } -const MasterPTY* FileDescription::master_pty() const +const MasterPTY* OpenFileDescription::master_pty() const { if (!is_master_pty()) return nullptr; return static_cast<const MasterPTY*>(m_file.ptr()); } -MasterPTY* FileDescription::master_pty() +MasterPTY* OpenFileDescription::master_pty() { if (!is_master_pty()) return nullptr; return static_cast<MasterPTY*>(m_file.ptr()); } -KResult FileDescription::close() +KResult OpenFileDescription::close() { if (m_file->attach_count() > 0) return KSuccess; return m_file->close(); } -KResultOr<NonnullOwnPtr<KString>> FileDescription::try_serialize_absolute_path() +KResultOr<NonnullOwnPtr<KString>> OpenFileDescription::try_serialize_absolute_path() { if (m_custody) return m_custody->try_serialize_absolute_path(); @@ -352,64 +352,64 @@ KResultOr<NonnullOwnPtr<KString>> FileDescription::try_serialize_absolute_path() return KString::try_create(m_file->absolute_path(*this)); } -String FileDescription::absolute_path() const +String OpenFileDescription::absolute_path() const { if (m_custody) return m_custody->absolute_path(); return m_file->absolute_path(*this); } -InodeMetadata FileDescription::metadata() const +InodeMetadata OpenFileDescription::metadata() const { if (m_inode) return m_inode->metadata(); return {}; } -KResultOr<Memory::Region*> FileDescription::mmap(Process& process, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) +KResultOr<Memory::Region*> OpenFileDescription::mmap(Process& process, Memory::VirtualRange const& range, u64 offset, int prot, bool shared) { MutexLocker locker(m_lock); return m_file->mmap(process, *this, range, offset, prot, shared); } -KResult FileDescription::truncate(u64 length) +KResult OpenFileDescription::truncate(u64 length) { MutexLocker locker(m_lock); return m_file->truncate(length); } -bool FileDescription::is_fifo() const +bool OpenFileDescription::is_fifo() const { return m_file->is_fifo(); } -FIFO* FileDescription::fifo() +FIFO* OpenFileDescription::fifo() { if (!is_fifo()) return nullptr; return static_cast<FIFO*>(m_file.ptr()); } -bool FileDescription::is_socket() const +bool OpenFileDescription::is_socket() const { return m_file->is_socket(); } -Socket* FileDescription::socket() +Socket* OpenFileDescription::socket() { if (!is_socket()) return nullptr; return static_cast<Socket*>(m_file.ptr()); } -const Socket* FileDescription::socket() const +const Socket* OpenFileDescription::socket() const { if (!is_socket()) return nullptr; return static_cast<const Socket*>(m_file.ptr()); } -void FileDescription::set_file_flags(u32 flags) +void OpenFileDescription::set_file_flags(u32 flags) { MutexLocker locker(m_lock); m_is_blocking = !(flags & O_NONBLOCK); @@ -418,24 +418,24 @@ void FileDescription::set_file_flags(u32 flags) m_file_flags = flags; } -KResult FileDescription::chmod(mode_t mode) +KResult OpenFileDescription::chmod(mode_t mode) { MutexLocker locker(m_lock); return m_file->chmod(*this, mode); } -KResult FileDescription::chown(UserID uid, GroupID gid) +KResult OpenFileDescription::chown(UserID uid, GroupID gid) { MutexLocker locker(m_lock); return m_file->chown(*this, uid, gid); } -FileBlockerSet& FileDescription::blocker_set() +FileBlockerSet& OpenFileDescription::blocker_set() { return m_file->blocker_set(); } -KResult FileDescription::apply_flock(Process const& process, Userspace<flock const*> lock) +KResult OpenFileDescription::apply_flock(Process const& process, Userspace<flock const*> lock) { if (!m_inode) return EBADF; @@ -443,7 +443,7 @@ KResult FileDescription::apply_flock(Process const& process, Userspace<flock con return m_inode->apply_flock(process, *this, lock); } -KResult FileDescription::get_flock(Userspace<flock*> lock) const +KResult OpenFileDescription::get_flock(Userspace<flock*> lock) const { if (!m_inode) return EBADF; diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/OpenFileDescription.h index 45b9db794b..04c3c08e61 100644 --- a/Kernel/FileSystem/FileDescription.h +++ b/Kernel/FileSystem/OpenFileDescription.h @@ -18,17 +18,17 @@ namespace Kernel { -class FileDescriptionData { +class OpenFileDescriptionData { public: - virtual ~FileDescriptionData() = default; + virtual ~OpenFileDescriptionData() = default; }; -class FileDescription : public RefCounted<FileDescription> { - MAKE_SLAB_ALLOCATED(FileDescription) +class OpenFileDescription : public RefCounted<OpenFileDescription> { + MAKE_SLAB_ALLOCATED(OpenFileDescription) public: - static KResultOr<NonnullRefPtr<FileDescription>> try_create(Custody&); - static KResultOr<NonnullRefPtr<FileDescription>> try_create(File&); - ~FileDescription(); + static KResultOr<NonnullRefPtr<OpenFileDescription>> try_create(Custody&); + static KResultOr<NonnullRefPtr<OpenFileDescription>> try_create(File&); + ~OpenFileDescription(); Thread::FileBlocker::BlockFlags should_unblock(Thread::FileBlocker::BlockFlags) const; @@ -116,7 +116,7 @@ public: FIFO::Direction fifo_direction() const { return m_fifo_direction; } void set_fifo_direction(Badge<FIFO>, FIFO::Direction direction) { m_fifo_direction = direction; } - OwnPtr<FileDescriptionData>& data() { return m_data; } + OwnPtr<OpenFileDescriptionData>& data() { return m_data; } void set_original_inode(Badge<VirtualFileSystem>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); } @@ -133,7 +133,7 @@ public: private: friend class VirtualFileSystem; - explicit FileDescription(File&); + explicit OpenFileDescription(File&); KResult attach(); @@ -148,7 +148,7 @@ private: off_t m_current_offset { 0 }; - OwnPtr<FileDescriptionData> m_data; + OwnPtr<OpenFileDescriptionData> m_data; u32 m_file_flags { 0 }; @@ -160,7 +160,7 @@ private: bool m_direct : 1 { false }; FIFO::Direction m_fifo_direction { FIFO::Direction::Neither }; - Mutex m_lock { "FileDescription" }; + Mutex m_lock { "OpenFileDescription" }; }; } diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 4f27c1cf28..8508f90b0b 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -9,12 +9,12 @@ namespace Kernel { -KResultOr<NonnullRefPtr<Plan9FS>> Plan9FS::try_create(FileDescription& file_description) +KResultOr<NonnullRefPtr<Plan9FS>> Plan9FS::try_create(OpenFileDescription& file_description) { return adopt_nonnull_ref_or_enomem(new (nothrow) Plan9FS(file_description)); } -Plan9FS::Plan9FS(FileDescription& file_description) +Plan9FS::Plan9FS(OpenFileDescription& file_description) : FileBackedFileSystem(file_description) , m_completion_blocker(*this) { @@ -720,7 +720,7 @@ KResult Plan9FSInode::ensure_open_for_mode(int mode) } } -KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, FileDescription*) const +KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const { TRY(const_cast<Plan9FSInode&>(*this).ensure_open_for_mode(O_RDONLY)); @@ -752,7 +752,7 @@ KResultOr<size_t> Plan9FSInode::read_bytes(off_t offset, size_t size, UserOrKern return nread; } -KResultOr<size_t> Plan9FSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& data, FileDescription*) +KResultOr<size_t> Plan9FSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& data, OpenFileDescription*) { TRY(ensure_open_for_mode(O_WRONLY)); size = fs().adjust_buffer_size(size); diff --git a/Kernel/FileSystem/Plan9FileSystem.h b/Kernel/FileSystem/Plan9FileSystem.h index 7cb964207b..1dfe4f7e55 100644 --- a/Kernel/FileSystem/Plan9FileSystem.h +++ b/Kernel/FileSystem/Plan9FileSystem.h @@ -20,7 +20,7 @@ class Plan9FS final : public FileBackedFileSystem { public: virtual ~Plan9FS() override; - static KResultOr<NonnullRefPtr<Plan9FS>> try_create(FileDescription&); + static KResultOr<NonnullRefPtr<Plan9FS>> try_create(OpenFileDescription&); virtual KResult initialize() override; @@ -46,7 +46,7 @@ public: class Message; private: - Plan9FS(FileDescription&); + Plan9FS(OpenFileDescription&); class Blocker; @@ -156,8 +156,8 @@ public: // ^Inode virtual InodeMetadata metadata() const override; virtual void flush_metadata() override; - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, FileDescription*) override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& data, OpenFileDescription*) override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index c5401594f5..32e086ecee 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -9,7 +9,7 @@ #include <AK/Singleton.h> #include <Kernel/Debug.h> #include <Kernel/FileSystem/Custody.h> -#include <Kernel/FileSystem/FileDescription.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/FileSystem/ProcFS.h> #include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/Heap/kmalloc.h> @@ -115,7 +115,7 @@ ProcFSGlobalInode::ProcFSGlobalInode(const ProcFS& fs, const ProcFSExposedCompon { } -void ProcFSGlobalInode::did_seek(FileDescription& description, off_t new_offset) +void ProcFSGlobalInode::did_seek(OpenFileDescription& description, off_t new_offset) { if (new_offset != 0) return; @@ -126,12 +126,12 @@ void ProcFSGlobalInode::did_seek(FileDescription& description, off_t new_offset) } } -KResult ProcFSGlobalInode::attach(FileDescription& description) +KResult ProcFSGlobalInode::attach(OpenFileDescription& description) { return m_associated_component->refresh_data(description); } -KResultOr<size_t> ProcFSGlobalInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* fd) const +KResultOr<size_t> ProcFSGlobalInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const { return m_associated_component->read_bytes(offset, count, buffer, fd); } @@ -164,7 +164,7 @@ InodeMetadata ProcFSGlobalInode::metadata() const return metadata; } -KResultOr<size_t> ProcFSGlobalInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, FileDescription* fd) +KResultOr<size_t> ProcFSGlobalInode::write_bytes(off_t offset, size_t count, const UserOrKernelBuffer& buffer, OpenFileDescription* fd) { return m_associated_component->write_bytes(offset, count, buffer, fd); } @@ -236,7 +236,7 @@ ProcFSProcessAssociatedInode::ProcFSProcessAssociatedInode(const ProcFS& fs, Pro { } -KResultOr<size_t> ProcFSProcessAssociatedInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, FileDescription*) +KResultOr<size_t> ProcFSProcessAssociatedInode::write_bytes(off_t, size_t, const UserOrKernelBuffer&, OpenFileDescription*) { VERIFY_NOT_REACHED(); } @@ -251,7 +251,7 @@ ProcFSProcessDirectoryInode::ProcFSProcessDirectoryInode(const ProcFS& procfs, P { } -KResult ProcFSProcessDirectoryInode::attach(FileDescription&) +KResult ProcFSProcessDirectoryInode::attach(OpenFileDescription&) { return KSuccess; } @@ -274,7 +274,7 @@ InodeMetadata ProcFSProcessDirectoryInode::metadata() const return metadata; } -KResultOr<size_t> ProcFSProcessDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const +KResultOr<size_t> ProcFSProcessDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } @@ -295,7 +295,7 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView n if (!process) return ESRCH; if (name == "fd"sv) - return TRY(ProcFSProcessSubDirectoryInode::try_create(procfs(), SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions, associated_pid())); + return TRY(ProcFSProcessSubDirectoryInode::try_create(procfs(), SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions, associated_pid())); if (name == "stacks"sv) return TRY(ProcFSProcessSubDirectoryInode::try_create(procfs(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks, associated_pid())); if (name == "unveil"sv) @@ -303,7 +303,7 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView n if (name == "pledge"sv) return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::Pledge, associated_pid())); if (name == "fds"sv) - return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::FileDescriptions, associated_pid())); + return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::OpenFileDescriptions, associated_pid())); if (name == "exe"sv) return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::BinaryLink, associated_pid())); if (name == "cwd"sv) @@ -326,17 +326,17 @@ ProcFSProcessSubDirectoryInode::ProcFSProcessSubDirectoryInode(const ProcFS& pro { } -KResultOr<size_t> ProcFSProcessSubDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const +KResultOr<size_t> ProcFSProcessSubDirectoryInode::read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } -KResult ProcFSProcessSubDirectoryInode::attach(FileDescription&) +KResult ProcFSProcessSubDirectoryInode::attach(OpenFileDescription&) { return KSuccess; } -void ProcFSProcessSubDirectoryInode::did_seek(FileDescription&, off_t) +void ProcFSProcessSubDirectoryInode::did_seek(OpenFileDescription&, off_t) { VERIFY_NOT_REACHED(); } @@ -366,7 +366,7 @@ KResult ProcFSProcessSubDirectoryInode::traverse_as_directory(Function<bool(File if (!process) return EINVAL; switch (m_sub_directory_type) { - case SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions: + case SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions: return process->traverse_file_descriptions_directory(procfs().fsid(), move(callback)); case SegmentedProcFSIndex::ProcessSubDirectory::Stacks: return process->traverse_stacks_directory(procfs().fsid(), move(callback)); @@ -383,7 +383,7 @@ KResultOr<NonnullRefPtr<Inode>> ProcFSProcessSubDirectoryInode::lookup(StringVie if (!process) return ESRCH; switch (m_sub_directory_type) { - case SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions: + case SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions: return process->lookup_file_descriptions_directory(procfs(), name); case SegmentedProcFSIndex::ProcessSubDirectory::Stacks: return process->lookup_stacks_directory(procfs(), name); @@ -414,7 +414,7 @@ ProcFSProcessPropertyInode::ProcFSProcessPropertyInode(const ProcFS& procfs, Seg ProcFSProcessPropertyInode::ProcFSProcessPropertyInode(const ProcFS& procfs, unsigned file_description_index, ProcessID pid) : ProcFSProcessAssociatedInode(procfs, pid, SegmentedProcFSIndex::build_segmented_index_for_file_description(pid, file_description_index)) - , m_parent_sub_directory_type(SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions) + , m_parent_sub_directory_type(SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) { m_possible_data.property_index = file_description_index; } @@ -426,11 +426,11 @@ ProcFSProcessPropertyInode::ProcFSProcessPropertyInode(const ProcFS& procfs, Thr m_possible_data.property_index = thread_stack_index.value(); } -KResult ProcFSProcessPropertyInode::attach(FileDescription& description) +KResult ProcFSProcessPropertyInode::attach(OpenFileDescription& description) { return refresh_data(description); } -void ProcFSProcessPropertyInode::did_seek(FileDescription& description, off_t offset) +void ProcFSProcessPropertyInode::did_seek(OpenFileDescription& description, off_t offset) { if (offset != 0) return; @@ -439,7 +439,7 @@ void ProcFSProcessPropertyInode::did_seek(FileDescription& description, off_t of static mode_t determine_procfs_process_inode_mode(SegmentedProcFSIndex::ProcessSubDirectory parent_sub_directory_type, SegmentedProcFSIndex::MainProcessProperty main_property) { - if (parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions) + if (parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) return S_IFLNK | 0400; if (parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::Stacks) return S_IFREG | 0400; @@ -472,7 +472,7 @@ KResult ProcFSProcessPropertyInode::traverse_as_directory(Function<bool(FileSyst { VERIFY_NOT_REACHED(); } -KResultOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* description) const +KResultOr<size_t> ProcFSProcessPropertyInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* description) const { dbgln_if(PROCFS_DEBUG, "ProcFS ProcessInformation: read_bytes offset: {} count: {}", offset, count); @@ -526,7 +526,7 @@ static KResult build_from_cached_data(KBufferBuilder& builder, ProcFSInodeData& KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBufferBuilder& builder) const { // FIXME: Verify process is already ref-counted - if (m_parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::FileDescriptions) { + if (m_parent_sub_directory_type == SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) { TRY(process.procfs_get_file_description_link(m_possible_data.property_index, builder)); return KSuccess; } @@ -541,7 +541,7 @@ KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBuffe return process.procfs_get_unveil_stats(builder); case SegmentedProcFSIndex::MainProcessProperty::Pledge: return process.procfs_get_pledge_stats(builder); - case SegmentedProcFSIndex::MainProcessProperty::FileDescriptions: + case SegmentedProcFSIndex::MainProcessProperty::OpenFileDescriptions: return process.procfs_get_fds_stats(builder); case SegmentedProcFSIndex::MainProcessProperty::BinaryLink: return process.procfs_get_binary_link(builder); @@ -556,7 +556,7 @@ KResult ProcFSProcessPropertyInode::try_to_acquire_data(Process& process, KBuffe } } -KResult ProcFSProcessPropertyInode::refresh_data(FileDescription& description) +KResult ProcFSProcessPropertyInode::refresh_data(OpenFileDescription& description) { // For process-specific inodes, hold the process's ptrace lock across refresh // and refuse to load data if the process is not dumpable. diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h index ae77b6c76e..1be5b2f1c6 100644 --- a/Kernel/FileSystem/ProcFS.h +++ b/Kernel/FileSystem/ProcFS.h @@ -54,8 +54,8 @@ protected: ProcFS const& procfs() const { return static_cast<ProcFS const&>(Inode::fs()); } // ^Inode - virtual KResult attach(FileDescription& description) = 0; - virtual void did_seek(FileDescription&, off_t) = 0; + virtual KResult attach(OpenFileDescription& description) = 0; + virtual void did_seek(OpenFileDescription&, off_t) = 0; virtual void flush_metadata() override final; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override final; virtual KResult add_child(Inode&, const StringView& name, mode_t) override final; @@ -77,10 +77,10 @@ protected: ProcFSGlobalInode(const ProcFS&, const ProcFSExposedComponent&); // ^Inode - virtual KResult attach(FileDescription& description) override final; - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override final; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override final; - virtual void did_seek(FileDescription&, off_t) override final; + virtual KResult attach(OpenFileDescription& description) override final; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final; + virtual void did_seek(OpenFileDescription&, off_t) override final; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView) override; @@ -122,7 +122,7 @@ protected: ProcessID associated_pid() const { return m_pid; } // ^Inode - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override final; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final; private: const ProcessID m_pid; @@ -137,11 +137,11 @@ public: private: ProcFSProcessDirectoryInode(const ProcFS&, ProcessID); // ^Inode - virtual KResult attach(FileDescription& description) override; - virtual void did_seek(FileDescription&, off_t) override { } + virtual KResult attach(OpenFileDescription& description) override; + virtual void did_seek(OpenFileDescription&, off_t) override { } virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override final; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; }; @@ -154,11 +154,11 @@ public: private: ProcFSProcessSubDirectoryInode(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID); // ^Inode - virtual KResult attach(FileDescription& description) override; - virtual void did_seek(FileDescription&, off_t) override; + virtual KResult attach(OpenFileDescription& description) override; + virtual void did_seek(OpenFileDescription&, off_t) override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override final; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; const SegmentedProcFSIndex::ProcessSubDirectory m_sub_directory_type; @@ -177,14 +177,14 @@ private: ProcFSProcessPropertyInode(const ProcFS&, ThreadID, ProcessID); ProcFSProcessPropertyInode(const ProcFS&, unsigned, ProcessID); // ^Inode - virtual KResult attach(FileDescription& description) override; - virtual void did_seek(FileDescription&, off_t) override; + virtual KResult attach(OpenFileDescription& description) override; + virtual void did_seek(OpenFileDescription&, off_t) override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override final; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override final; - KResult refresh_data(FileDescription& description); + KResult refresh_data(OpenFileDescription& description); KResult try_to_acquire_data(Process& process, KBufferBuilder& builder) const; const SegmentedProcFSIndex::ProcessSubDirectory m_parent_sub_directory_type; diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp index ded4365ff1..e56744f050 100644 --- a/Kernel/FileSystem/SysFS.cpp +++ b/Kernel/FileSystem/SysFS.cpp @@ -96,7 +96,7 @@ SysFSInode::SysFSInode(SysFS const& fs, SysFSComponent const& component) { } -void SysFSInode::did_seek(FileDescription& description, off_t new_offset) +void SysFSInode::did_seek(OpenFileDescription& description, off_t new_offset) { if (new_offset != 0) return; @@ -107,12 +107,12 @@ void SysFSInode::did_seek(FileDescription& description, off_t new_offset) } } -KResult SysFSInode::attach(FileDescription& description) +KResult SysFSInode::attach(OpenFileDescription& description) { return m_associated_component->refresh_data(description); } -KResultOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* fd) const +KResultOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription* fd) const { return m_associated_component->read_bytes(offset, count, buffer, fd); } @@ -144,7 +144,7 @@ void SysFSInode::flush_metadata() { } -KResultOr<size_t> SysFSInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, FileDescription* fd) +KResultOr<size_t> SysFSInode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& buffer, OpenFileDescription* fd) { return m_associated_component->write_bytes(offset, count, buffer, fd); } diff --git a/Kernel/FileSystem/SysFS.h b/Kernel/FileSystem/SysFS.h index c7fe30c619..437ba4595a 100644 --- a/Kernel/FileSystem/SysFS.h +++ b/Kernel/FileSystem/SysFS.h @@ -83,12 +83,12 @@ public: protected: SysFSInode(SysFS const&, SysFSComponent const&); - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; virtual InodeMetadata metadata() const override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode&, StringView const& name, mode_t) override; virtual KResult remove_child(StringView const& name) override; @@ -96,8 +96,8 @@ protected: virtual KResult chown(UserID, GroupID) override; virtual KResult truncate(u64) override; - virtual KResult attach(FileDescription& description) override final; - virtual void did_seek(FileDescription&, off_t) override final; + virtual KResult attach(OpenFileDescription& description) override final; + virtual void did_seek(OpenFileDescription&, off_t) override final; NonnullRefPtr<SysFSComponent> m_associated_component; }; diff --git a/Kernel/FileSystem/SysFSComponent.h b/Kernel/FileSystem/SysFSComponent.h index c640df9ae5..1525014bf7 100644 --- a/Kernel/FileSystem/SysFSComponent.h +++ b/Kernel/FileSystem/SysFSComponent.h @@ -13,24 +13,24 @@ #include <AK/Types.h> #include <Kernel/API/KResult.h> #include <Kernel/FileSystem/File.h> -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileSystem.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/Forward.h> namespace Kernel { -struct SysFSInodeData : public FileDescriptionData { +struct SysFSInodeData : public OpenFileDescriptionData { OwnPtr<KBuffer> buffer; }; class SysFSComponent : public RefCounted<SysFSComponent> { public: virtual StringView name() const { return m_name->view(); } - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const { VERIFY_NOT_REACHED(); } + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); } virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); }; - virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) { return EROFS; } - virtual KResult refresh_data(FileDescription&) const { return KSuccess; } + virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } + virtual KResult refresh_data(OpenFileDescription&) const { return KSuccess; } virtual KResultOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const&) const; diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index cf013adf03..0a671061bd 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -123,7 +123,7 @@ KResult TmpFSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEnt return KSuccess; } -KResultOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, FileDescription*) const +KResultOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernelBuffer& buffer, OpenFileDescription*) const { MutexLocker locker(m_inode_lock, Mutex::Mode::Shared); VERIFY(!is_directory()); @@ -142,7 +142,7 @@ KResultOr<size_t> TmpFSInode::read_bytes(off_t offset, size_t size, UserOrKernel return size; } -KResultOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& buffer, FileDescription*) +KResultOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserOrKernelBuffer& buffer, OpenFileDescription*) { MutexLocker locker(m_inode_lock); VERIFY(!is_directory()); diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h index bd8bb8bb54..4c4f930bfe 100644 --- a/Kernel/FileSystem/TmpFS.h +++ b/Kernel/FileSystem/TmpFS.h @@ -52,12 +52,12 @@ public: const TmpFS& fs() const { return static_cast<const TmpFS&>(Inode::fs()); } // ^Inode - virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override; virtual void flush_metadata() override; - virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, FileDescription*) override; + virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override; virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual KResult add_child(Inode&, const StringView& name, mode_t) override; virtual KResult remove_child(const StringView& name) override; diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 0135af8c3b..1d1de17092 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -11,8 +11,8 @@ #include <Kernel/Devices/BlockDevice.h> #include <Kernel/FileSystem/Custody.h> #include <Kernel/FileSystem/FileBackedFileSystem.h> -#include <Kernel/FileSystem/FileDescription.h> #include <Kernel/FileSystem/FileSystem.h> +#include <Kernel/FileSystem/OpenFileDescription.h> #include <Kernel/FileSystem/VirtualFileSystem.h> #include <Kernel/KLexicalPath.h> #include <Kernel/KSyms.h> @@ -203,7 +203,7 @@ KResultOr<InodeMetadata> VirtualFileSystem::lookup_metadata(StringView path, Cus return custody->inode().metadata(); } -KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner) +KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner) { if ((options & O_CREAT) && (options & O_DIRECTORY)) return EINVAL; @@ -288,7 +288,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::open(StringView pat TRY(inode.truncate(0)); TRY(inode.set_mtime(kgettimeofday().to_truncated_seconds())); } - auto description = TRY(FileDescription::try_create(custody)); + auto description = TRY(OpenFileDescription::try_create(custody)); description->set_rw_mode(options); description->set_file_flags(options); return description; @@ -319,7 +319,7 @@ KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custod return parent_inode.create_child(basename, mode, dev, current_process.euid(), current_process.egid()).result(); } -KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner) +KResultOr<NonnullRefPtr<OpenFileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner) { auto basename = KLexicalPath::basename(path); auto parent_path = TRY(parent_custody.try_serialize_absolute_path()); @@ -345,7 +345,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView p auto inode = TRY(parent_inode.create_child(basename, mode, 0, uid, gid)); auto custody = TRY(Custody::try_create(&parent_custody, basename, inode, parent_custody.mount_flags())); - auto description = TRY(FileDescription::try_create(move(custody))); + auto description = TRY(OpenFileDescription::try_create(move(custody))); description->set_rw_mode(options); description->set_file_flags(options); return description; diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 262ef63dd9..8c9655ba44 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -48,8 +48,8 @@ public: KResult remount(Custody& mount_point, int new_flags); KResult unmount(Inode& guest_inode); - KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {}); - KResultOr<NonnullRefPtr<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {}); + KResultOr<NonnullRefPtr<OpenFileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {}); + KResultOr<NonnullRefPtr<OpenFileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {}); 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); @@ -77,7 +77,7 @@ public: KResultOr<NonnullRefPtr<Custody>> resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0); private: - friend class FileDescription; + friend class OpenFileDescription; UnveilNode const& find_matching_unveiled_path(StringView path); KResult validate_path_against_process_veil(Custody const& path, int options); |