2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "VirtualFileSystem.h"
|
2018-10-27 16:43:03 +02:00
|
|
|
#include "InodeMetadata.h"
|
2018-11-12 01:28:46 +01:00
|
|
|
#include "FIFO.h"
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/ByteBuffer.h>
|
2018-11-12 01:28:46 +01:00
|
|
|
#include <AK/CircularQueue.h>
|
2018-11-05 19:01:22 +01:00
|
|
|
#include <AK/Retainable.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-10-30 22:03:02 +01:00
|
|
|
class TTY;
|
2019-01-15 06:30:19 +01:00
|
|
|
class MasterPTY;
|
2019-01-14 14:21:51 +01:00
|
|
|
class Process;
|
2018-10-30 22:03:02 +01:00
|
|
|
|
2018-11-07 11:37:54 +01:00
|
|
|
class FileDescriptor : public Retainable<FileDescriptor> {
|
2018-10-10 11:53:07 +02:00
|
|
|
public:
|
2019-01-16 12:57:07 +01:00
|
|
|
static RetainPtr<FileDescriptor> create(RetainPtr<Inode>&&);
|
|
|
|
static RetainPtr<FileDescriptor> create(RetainPtr<CharacterDevice>&&);
|
2018-11-12 01:28:46 +01:00
|
|
|
static RetainPtr<FileDescriptor> create_pipe_writer(FIFO&);
|
|
|
|
static RetainPtr<FileDescriptor> create_pipe_reader(FIFO&);
|
2018-11-07 11:37:54 +01:00
|
|
|
~FileDescriptor();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-07 11:37:54 +01:00
|
|
|
RetainPtr<FileDescriptor> clone();
|
2018-11-02 20:41:58 +01:00
|
|
|
|
2018-11-01 14:00:28 +01:00
|
|
|
int close();
|
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
off_t seek(off_t, int whence);
|
2019-01-16 00:20:38 +01:00
|
|
|
ssize_t read(Process&, byte*, size_t);
|
|
|
|
ssize_t write(Process&, const byte* data, size_t);
|
2019-01-23 06:53:01 +01:00
|
|
|
int fstat(stat*);
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2019-01-16 00:47:00 +01:00
|
|
|
bool can_read(Process&);
|
2019-01-15 09:17:22 +01:00
|
|
|
bool can_write(Process&);
|
2018-10-25 13:07:59 +02:00
|
|
|
|
2018-12-02 23:34:50 +01:00
|
|
|
ssize_t get_dir_entries(byte* buffer, size_t);
|
2018-10-24 12:43:52 +02:00
|
|
|
|
2019-01-16 00:20:38 +01:00
|
|
|
ByteBuffer read_entire_file(Process&);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-13 23:44:54 +01:00
|
|
|
String absolute_path();
|
2018-10-24 14:28:22 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool is_directory() const;
|
2018-10-26 14:24:11 +02:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
bool is_character_device() const { return m_device.ptr(); }
|
|
|
|
CharacterDevice* character_device() { return m_device.ptr(); }
|
|
|
|
const CharacterDevice* character_device() const { return m_device.ptr(); }
|
2018-11-16 13:11:21 +01:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool is_tty() const;
|
2018-10-30 22:03:02 +01:00
|
|
|
const TTY* tty() const;
|
2018-11-02 13:14:25 +01:00
|
|
|
TTY* tty();
|
2019-01-15 06:30:19 +01:00
|
|
|
|
|
|
|
bool is_master_pty() const;
|
|
|
|
const MasterPTY* master_pty() const;
|
|
|
|
MasterPTY* master_pty();
|
2018-10-30 22:03:02 +01:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
InodeMetadata metadata() const;
|
|
|
|
Inode* inode() { return m_inode.ptr(); }
|
|
|
|
const Inode* inode() const { return m_inode.ptr(); }
|
2018-10-27 16:43:03 +02:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
bool supports_mmap() const { return m_inode && !m_device; }
|
2018-10-26 14:24:11 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool is_blocking() const { return m_is_blocking; }
|
|
|
|
void set_blocking(bool b) { m_is_blocking = b; }
|
2018-11-11 15:36:40 +01:00
|
|
|
|
|
|
|
dword file_flags() const { return m_file_flags; }
|
2018-11-13 01:36:31 +01:00
|
|
|
void set_file_flags(dword flags) { m_file_flags = flags; }
|
2018-11-12 01:28:46 +01:00
|
|
|
|
|
|
|
bool is_fifo() const { return m_fifo; }
|
|
|
|
FIFO::Direction fifo_direction() { return m_fifo_direction; }
|
2018-10-18 10:27:07 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
ByteBuffer& generator_cache() { return m_generator_cache; }
|
2018-10-27 00:14:24 +02:00
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
private:
|
2018-11-15 14:43:10 +01:00
|
|
|
friend class VFS;
|
2019-01-16 12:57:07 +01:00
|
|
|
explicit FileDescriptor(RetainPtr<Inode>&&);
|
|
|
|
explicit FileDescriptor(RetainPtr<CharacterDevice>&&);
|
2018-11-12 01:28:46 +01:00
|
|
|
FileDescriptor(FIFO&, FIFO::Direction);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
RetainPtr<Inode> m_inode;
|
|
|
|
RetainPtr<CharacterDevice> m_device;
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
off_t m_current_offset { 0 };
|
2018-10-18 10:27:07 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
ByteBuffer m_generator_cache;
|
2018-10-27 00:14:24 +02:00
|
|
|
|
2018-12-03 00:39:25 +01:00
|
|
|
bool m_is_blocking { true };
|
2018-11-11 15:36:40 +01:00
|
|
|
dword m_file_flags { 0 };
|
2018-11-12 01:28:46 +01:00
|
|
|
|
|
|
|
RetainPtr<FIFO> m_fifo;
|
|
|
|
FIFO::Direction m_fifo_direction { FIFO::Neither };
|
2019-01-30 18:26:19 +01:00
|
|
|
|
|
|
|
bool m_closed { false };
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|