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-10-10 11:53:07 +02:00
|
|
|
#include <AK/ByteBuffer.h>
|
2018-11-05 19:01:22 +01:00
|
|
|
#include <AK/Retainable.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-07 12:05:51 +01:00
|
|
|
#ifdef SERENITY
|
2018-10-30 22:03:02 +01:00
|
|
|
class TTY;
|
2018-11-07 12:05:51 +01:00
|
|
|
#endif
|
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:
|
2018-11-07 11:37:54 +01:00
|
|
|
static RetainPtr<FileDescriptor> create(RetainPtr<VirtualFileSystem::Node>&&);
|
|
|
|
|
~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();
|
|
|
|
|
|
2018-10-14 22:57:41 +02:00
|
|
|
Unix::off_t seek(Unix::off_t, int whence);
|
2018-10-30 15:33:37 +01:00
|
|
|
Unix::ssize_t read(byte*, Unix::size_t);
|
|
|
|
|
Unix::ssize_t write(const byte* data, Unix::size_t);
|
2018-10-14 22:57:41 +02:00
|
|
|
int stat(Unix::stat*);
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2018-10-25 13:07:59 +02:00
|
|
|
bool hasDataAvailableForRead();
|
|
|
|
|
|
2018-10-24 12:43:52 +02:00
|
|
|
ssize_t get_dir_entries(byte* buffer, Unix::size_t);
|
|
|
|
|
|
2018-10-14 21:19:27 +02:00
|
|
|
ByteBuffer readEntireFile();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-01 14:00:28 +01:00
|
|
|
String absolute_path() const;
|
2018-10-24 14:28:22 +02:00
|
|
|
|
2018-10-26 14:24:11 +02:00
|
|
|
bool isDirectory() const;
|
|
|
|
|
|
2018-11-07 12:05:51 +01:00
|
|
|
#ifdef SERENITY
|
2018-10-30 22:03:02 +01:00
|
|
|
bool isTTY() const;
|
|
|
|
|
const TTY* tty() const;
|
2018-11-02 13:14:25 +01:00
|
|
|
TTY* tty();
|
2018-11-07 12:05:51 +01:00
|
|
|
#endif
|
2018-10-30 22:03:02 +01:00
|
|
|
|
2018-10-27 16:43:03 +02:00
|
|
|
InodeMetadata metadata() const { return m_vnode->metadata(); }
|
|
|
|
|
|
2018-10-26 14:24:11 +02:00
|
|
|
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
|
|
|
|
|
2018-10-22 14:06:22 +02:00
|
|
|
#ifdef SERENITY
|
2018-10-25 13:07:59 +02:00
|
|
|
bool isBlocking() const { return m_isBlocking; }
|
|
|
|
|
void setBlocking(bool b) { m_isBlocking = b; }
|
2018-11-11 15:36:40 +01:00
|
|
|
|
|
|
|
|
dword file_flags() const { return m_file_flags; }
|
|
|
|
|
int set_file_flags(dword flags) { m_file_flags = flags; return 0; }
|
|
|
|
|
|
|
|
|
|
dword fd_flags() const { return m_fd_flags; }
|
|
|
|
|
int set_fd_flags(dword flags) { m_fd_flags = flags; return 0; }
|
2018-10-18 10:27:07 +02:00
|
|
|
#endif
|
|
|
|
|
|
2018-10-27 00:14:24 +02:00
|
|
|
ByteBuffer& generatorCache() { return m_generatorCache; }
|
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
private:
|
|
|
|
|
friend class VirtualFileSystem;
|
2018-11-07 11:37:54 +01:00
|
|
|
explicit FileDescriptor(RetainPtr<VirtualFileSystem::Node>&&);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
|
|
|
|
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
2018-10-14 21:19:27 +02:00
|
|
|
|
2018-10-14 22:57:41 +02:00
|
|
|
Unix::off_t m_currentOffset { 0 };
|
2018-10-18 10:27:07 +02:00
|
|
|
|
2018-10-27 00:14:24 +02:00
|
|
|
ByteBuffer m_generatorCache;
|
|
|
|
|
|
2018-10-22 14:06:22 +02:00
|
|
|
#ifdef SERENITY
|
2018-10-25 13:07:59 +02:00
|
|
|
bool m_isBlocking { true };
|
2018-11-11 15:36:40 +01:00
|
|
|
dword m_fd_flags { 0 };
|
|
|
|
|
dword m_file_flags { 0 };
|
2018-10-18 10:27:07 +02:00
|
|
|
#endif
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|
|