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