summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/FileDescription.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-07 09:36:51 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-07 09:36:51 +0200
commit08cd75ac4baa2814bb6154c3ad127957b3b03b7c (patch)
tree87d8bcc40d4bd536c02cbef49c91e5520a44594a /Kernel/FileSystem/FileDescription.h
parent69a6ce90df7e0f074a714e0938cfd526076e38a3 (diff)
downloadserenity-08cd75ac4baa2814bb6154c3ad127957b3b03b7c.zip
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).
Diffstat (limited to 'Kernel/FileSystem/FileDescription.h')
-rw-r--r--Kernel/FileSystem/FileDescription.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/Kernel/FileSystem/FileDescription.h b/Kernel/FileSystem/FileDescription.h
new file mode 100644
index 0000000000..7c1d1ef4bb
--- /dev/null
+++ b/Kernel/FileSystem/FileDescription.h
@@ -0,0 +1,125 @@
+#pragma once
+
+#include <AK/Badge.h>
+#include <AK/ByteBuffer.h>
+#include <AK/CircularQueue.h>
+#include <AK/Retainable.h>
+#include <Kernel/FileSystem/FIFO.h>
+#include <Kernel/FileSystem/Inode.h>
+#include <Kernel/FileSystem/InodeMetadata.h>
+#include <Kernel/FileSystem/VirtualFileSystem.h>
+#include <Kernel/LinearAddress.h>
+#include <Kernel/Net/Socket.h>
+
+class File;
+class TTY;
+class MasterPTY;
+class Process;
+class Region;
+class CharacterDevice;
+class SharedMemory;
+
+class FileDescription : public Retainable<FileDescription> {
+public:
+ static Retained<FileDescription> create(RetainPtr<Custody>&&);
+ static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
+ ~FileDescription();
+
+ Retained<FileDescription> clone();
+
+ int close();
+
+ off_t seek(off_t, int whence);
+ ssize_t read(byte*, ssize_t);
+ ssize_t write(const byte* data, ssize_t);
+ KResult fstat(stat&);
+
+ KResult fchmod(mode_t);
+
+ bool can_read();
+ bool can_write();
+
+ ssize_t get_dir_entries(byte* buffer, ssize_t);
+
+ ByteBuffer read_entire_file();
+
+ String absolute_path() const;
+
+ bool is_directory() const;
+
+ File& file() { return *m_file; }
+ const File& file() const { return *m_file; }
+
+ bool is_device() const;
+
+ bool is_tty() const;
+ const TTY* tty() const;
+ TTY* tty();
+
+ bool is_master_pty() const;
+ const MasterPTY* master_pty() const;
+ MasterPTY* master_pty();
+
+ InodeMetadata metadata() const;
+ Inode* inode() { return m_inode.ptr(); }
+ const Inode* inode() const { return m_inode.ptr(); }
+
+ Custody* custody() { return m_custody.ptr(); }
+ const Custody* custody() const { return m_custody.ptr(); }
+
+ KResultOr<Region*> mmap(Process&, LinearAddress, size_t offset, size_t, int prot);
+
+ bool is_blocking() const { return m_is_blocking; }
+ void set_blocking(bool b) { m_is_blocking = b; }
+ bool should_append() const { return m_should_append; }
+ void set_should_append(bool s) { m_should_append = s; }
+
+ dword file_flags() const { return m_file_flags; }
+ void set_file_flags(dword);
+
+ bool is_socket() const;
+ Socket* socket();
+ const Socket* socket() const;
+
+ bool is_fifo() const;
+ FIFO* fifo();
+ FIFO::Direction fifo_direction() { return m_fifo_direction; }
+ void set_fifo_direction(Badge<FIFO>, FIFO::Direction direction) { m_fifo_direction = direction; }
+
+ bool is_shared_memory() const;
+ SharedMemory* shared_memory();
+ const SharedMemory* shared_memory() const;
+
+ ByteBuffer& generator_cache() { return m_generator_cache; }
+
+ void set_original_inode(Badge<VFS>, Retained<Inode>&& inode) { m_inode = move(inode); }
+
+ SocketRole socket_role() const { return m_socket_role; }
+ void set_socket_role(SocketRole);
+
+ KResult truncate(off_t);
+
+ off_t offset() const { return m_current_offset; }
+
+ KResult chown(uid_t, gid_t);
+
+private:
+ friend class VFS;
+ FileDescription(RetainPtr<File>&&, SocketRole = SocketRole::None);
+ FileDescription(FIFO&, FIFO::Direction);
+
+ RetainPtr<Custody> m_custody;
+ RetainPtr<Inode> m_inode;
+ RetainPtr<File> m_file;
+
+ off_t m_current_offset { 0 };
+
+ ByteBuffer m_generator_cache;
+
+ dword m_file_flags { 0 };
+
+ bool m_is_blocking { true };
+ bool m_should_append { false };
+ SocketRole m_socket_role { SocketRole::None };
+ FIFO::Direction m_fifo_direction { FIFO::Direction::Neither };
+};