2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-03 07:25:24 -03:00
|
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
|
|
|
|
#include <Kernel/FileSystem/InodeMetadata.h>
|
2019-04-06 15:29:48 -03:00
|
|
|
#include <Kernel/FileSystem/FIFO.h>
|
2019-04-06 09:29:29 -03:00
|
|
|
#include <Kernel/LinearAddress.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/ByteBuffer.h>
|
2018-11-11 22:28:46 -02:00
|
|
|
#include <AK/CircularQueue.h>
|
2018-11-05 16:01:22 -02:00
|
|
|
#include <AK/Retainable.h>
|
2019-01-31 02:05:57 -02:00
|
|
|
#include <AK/Badge.h>
|
2019-04-06 15:29:48 -03:00
|
|
|
#include <Kernel/Net/Socket.h>
|
2019-04-08 21:37:05 -03:00
|
|
|
#include <Kernel/SharedMemory.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-10-30 18:03:02 -03:00
|
|
|
class TTY;
|
2019-01-15 03:30:19 -02:00
|
|
|
class MasterPTY;
|
2019-01-14 11:21:51 -02:00
|
|
|
class Process;
|
2019-02-16 06:57:42 -02:00
|
|
|
class Region;
|
|
|
|
|
class CharacterDevice;
|
2019-02-14 12:40:04 -02:00
|
|
|
|
2018-11-07 08:37:54 -02:00
|
|
|
class FileDescriptor : public Retainable<FileDescriptor> {
|
2018-10-10 06:53:07 -03:00
|
|
|
public:
|
2019-02-14 12:40:04 -02:00
|
|
|
|
2019-02-25 08:43:52 -03:00
|
|
|
static Retained<FileDescriptor> create(RetainPtr<Socket>&&, SocketRole = SocketRole::None);
|
|
|
|
|
static Retained<FileDescriptor> create(RetainPtr<Inode>&&);
|
|
|
|
|
static Retained<FileDescriptor> create(RetainPtr<Device>&&);
|
2019-04-08 21:37:05 -03:00
|
|
|
static Retained<FileDescriptor> create(RetainPtr<SharedMemory>&&);
|
2019-02-25 08:43:52 -03:00
|
|
|
static Retained<FileDescriptor> create_pipe_writer(FIFO&);
|
|
|
|
|
static Retained<FileDescriptor> create_pipe_reader(FIFO&);
|
2018-11-07 08:37:54 -02:00
|
|
|
~FileDescriptor();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-02-25 08:43:52 -03:00
|
|
|
Retained<FileDescriptor> clone();
|
2018-11-02 16:41:58 -03:00
|
|
|
|
2018-11-01 10:00:28 -03:00
|
|
|
int close();
|
|
|
|
|
|
2019-01-23 03:53:01 -02:00
|
|
|
off_t seek(off_t, int whence);
|
2019-02-25 17:19:57 -03:00
|
|
|
ssize_t read(Process&, byte*, ssize_t);
|
|
|
|
|
ssize_t write(Process&, const byte* data, ssize_t);
|
2019-03-01 20:11:08 -03:00
|
|
|
KResult fstat(stat&);
|
2018-10-14 16:19:27 -03:00
|
|
|
|
2019-03-01 06:39:19 -03:00
|
|
|
KResult fchmod(mode_t);
|
|
|
|
|
|
2019-01-15 21:47:00 -02:00
|
|
|
bool can_read(Process&);
|
2019-01-15 06:17:22 -02:00
|
|
|
bool can_write(Process&);
|
2018-10-25 08:07:59 -03:00
|
|
|
|
2019-02-25 17:19:57 -03:00
|
|
|
ssize_t get_dir_entries(byte* buffer, ssize_t);
|
2018-10-24 07:43:52 -03:00
|
|
|
|
2019-01-15 21:20:38 -02:00
|
|
|
ByteBuffer read_entire_file(Process&);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-03-06 18:30:13 -03:00
|
|
|
KResultOr<String> absolute_path();
|
2018-10-24 09:28:22 -03:00
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
bool is_directory() const;
|
2018-10-26 09:24:11 -03:00
|
|
|
|
2019-02-16 06:57:42 -02:00
|
|
|
bool is_device() const { return m_device.ptr(); }
|
|
|
|
|
Device* device() { return m_device.ptr(); }
|
|
|
|
|
const Device* device() const { return m_device.ptr(); }
|
|
|
|
|
|
|
|
|
|
bool is_block_device() const;
|
|
|
|
|
bool is_character_device() const;
|
|
|
|
|
CharacterDevice* character_device();
|
|
|
|
|
const CharacterDevice* character_device() const;
|
2018-11-16 10:11:21 -02:00
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
bool is_tty() const;
|
2018-10-30 18:03:02 -03:00
|
|
|
const TTY* tty() const;
|
2018-11-02 09:14:25 -03:00
|
|
|
TTY* tty();
|
2019-01-15 03:30:19 -02:00
|
|
|
|
|
|
|
|
bool is_master_pty() const;
|
|
|
|
|
const MasterPTY* master_pty() const;
|
|
|
|
|
MasterPTY* master_pty();
|
2018-10-30 18:03:02 -03:00
|
|
|
|
2019-01-16 09:57:07 -02:00
|
|
|
InodeMetadata metadata() const;
|
|
|
|
|
Inode* inode() { return m_inode.ptr(); }
|
|
|
|
|
const Inode* inode() const { return m_inode.ptr(); }
|
2018-10-27 11:43:03 -03:00
|
|
|
|
2019-02-16 06:57:42 -02:00
|
|
|
bool supports_mmap() const;
|
|
|
|
|
Region* mmap(Process&, LinearAddress, size_t offset, size_t, int prot);
|
2018-10-26 09:24:11 -03:00
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
bool is_blocking() const { return m_is_blocking; }
|
|
|
|
|
void set_blocking(bool b) { m_is_blocking = b; }
|
2018-11-11 12:36:40 -02:00
|
|
|
|
|
|
|
|
dword file_flags() const { return m_file_flags; }
|
2018-11-12 22:36:31 -02:00
|
|
|
void set_file_flags(dword flags) { m_file_flags = flags; }
|
2018-11-11 22:28:46 -02:00
|
|
|
|
2019-02-14 11:17:38 -02:00
|
|
|
bool is_socket() const { return m_socket; }
|
|
|
|
|
Socket* socket() { return m_socket.ptr(); }
|
|
|
|
|
const Socket* socket() const { return m_socket.ptr(); }
|
|
|
|
|
|
2018-11-11 22:28:46 -02:00
|
|
|
bool is_fifo() const { return m_fifo; }
|
|
|
|
|
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
2018-10-18 05:27:07 -03:00
|
|
|
|
2019-04-08 20:10:00 -03:00
|
|
|
bool is_file() const;
|
|
|
|
|
bool is_shared_memory() const { return m_shared_memory; }
|
|
|
|
|
SharedMemory* shared_memory() { return m_shared_memory.ptr(); }
|
|
|
|
|
const SharedMemory* shared_memory() const { return m_shared_memory.ptr(); }
|
|
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
ByteBuffer& generator_cache() { return m_generator_cache; }
|
2018-10-26 19:14:24 -03:00
|
|
|
|
2019-03-06 18:14:31 -03:00
|
|
|
void set_original_inode(Badge<VFS>, Retained<Inode>&& inode) { m_inode = move(inode); }
|
2019-01-31 02:05:57 -02:00
|
|
|
|
2019-03-19 22:38:36 -03:00
|
|
|
SocketRole socket_role() const { return m_socket_role; }
|
2019-02-17 07:00:35 -03:00
|
|
|
void set_socket_role(SocketRole);
|
2019-02-14 14:18:35 -02:00
|
|
|
|
2019-04-08 20:10:00 -03:00
|
|
|
KResult truncate(off_t);
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
2018-11-15 11:43:10 -02:00
|
|
|
friend class VFS;
|
2019-02-14 12:40:04 -02:00
|
|
|
FileDescriptor(RetainPtr<Socket>&&, SocketRole);
|
2019-01-16 09:57:07 -02:00
|
|
|
explicit FileDescriptor(RetainPtr<Inode>&&);
|
2019-02-15 21:47:20 -02:00
|
|
|
explicit FileDescriptor(RetainPtr<Device>&&);
|
2019-04-08 21:37:05 -03:00
|
|
|
explicit FileDescriptor(RetainPtr<SharedMemory>&&);
|
2018-11-11 22:28:46 -02:00
|
|
|
FileDescriptor(FIFO&, FIFO::Direction);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-01-16 09:57:07 -02:00
|
|
|
RetainPtr<Inode> m_inode;
|
2019-02-15 21:47:20 -02:00
|
|
|
RetainPtr<Device> m_device;
|
2018-10-14 16:19:27 -03:00
|
|
|
|
2019-01-23 03:53:01 -02:00
|
|
|
off_t m_current_offset { 0 };
|
2018-10-18 05:27:07 -03:00
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
ByteBuffer m_generator_cache;
|
2018-10-26 19:14:24 -03:00
|
|
|
|
2018-12-02 21:39:25 -02:00
|
|
|
bool m_is_blocking { true };
|
2018-11-11 12:36:40 -02:00
|
|
|
dword m_file_flags { 0 };
|
2018-11-11 22:28:46 -02:00
|
|
|
|
2019-02-14 11:17:38 -02:00
|
|
|
RetainPtr<Socket> m_socket;
|
2019-02-14 12:40:04 -02:00
|
|
|
SocketRole m_socket_role { SocketRole::None };
|
2019-02-14 11:17:38 -02:00
|
|
|
|
2018-11-11 22:28:46 -02:00
|
|
|
RetainPtr<FIFO> m_fifo;
|
|
|
|
|
FIFO::Direction m_fifo_direction { FIFO::Neither };
|
2019-01-30 15:26:19 -02:00
|
|
|
|
2019-04-08 20:10:00 -03:00
|
|
|
RetainPtr<SharedMemory> m_shared_memory;
|
|
|
|
|
|
2019-01-30 15:26:19 -02:00
|
|
|
bool m_closed { false };
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|