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-10-30 22:03:02 +01:00
|
|
|
class TTY;
|
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
class FileHandle {
|
|
|
|
public:
|
|
|
|
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
|
|
|
~FileHandle();
|
|
|
|
|
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-10-24 14:28:22 +02:00
|
|
|
String absolutePath() const;
|
|
|
|
|
2018-10-26 14:24:11 +02:00
|
|
|
bool isDirectory() const;
|
|
|
|
|
2018-10-30 22:03:02 +01:00
|
|
|
bool isTTY() const;
|
|
|
|
const TTY* tty() const;
|
|
|
|
|
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-18 10:27:07 +02:00
|
|
|
int fd() const { return m_fd; }
|
|
|
|
void setFD(int fd) { m_fd = fd; }
|
2018-10-25 13:07:59 +02:00
|
|
|
|
|
|
|
bool isBlocking() const { return m_isBlocking; }
|
|
|
|
void setBlocking(bool b) { m_isBlocking = b; }
|
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;
|
|
|
|
|
|
|
|
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-18 10:27:07 +02:00
|
|
|
int m_fd { -1 };
|
2018-10-25 13:07:59 +02:00
|
|
|
bool m_isBlocking { true };
|
2018-10-18 10:27:07 +02:00
|
|
|
#endif
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|