2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "VirtualFileSystem.h"
|
2018-10-27 11:43:03 -03:00
|
|
|
#include "InodeMetadata.h"
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
|
|
|
|
|
class FileHandle {
|
|
|
|
|
public:
|
|
|
|
|
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
|
|
|
|
~FileHandle();
|
|
|
|
|
|
2018-10-14 17:57:41 -03:00
|
|
|
Unix::off_t seek(Unix::off_t, int whence);
|
|
|
|
|
Unix::ssize_t read(byte* buffer, Unix::size_t count);
|
|
|
|
|
int stat(Unix::stat*);
|
2018-10-14 16:19:27 -03:00
|
|
|
|
2018-10-25 08:07:59 -03:00
|
|
|
bool hasDataAvailableForRead();
|
|
|
|
|
|
2018-10-24 07:43:52 -03:00
|
|
|
ssize_t get_dir_entries(byte* buffer, Unix::size_t);
|
|
|
|
|
|
2018-10-14 16:19:27 -03:00
|
|
|
ByteBuffer readEntireFile();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-10-24 09:28:22 -03:00
|
|
|
String absolutePath() const;
|
|
|
|
|
|
2018-10-26 09:24:11 -03:00
|
|
|
bool isDirectory() const;
|
|
|
|
|
|
2018-10-27 11:43:03 -03:00
|
|
|
InodeMetadata metadata() const { return m_vnode->metadata(); }
|
|
|
|
|
|
2018-10-26 09:24:11 -03:00
|
|
|
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
|
|
|
|
|
2018-10-22 09:06:22 -03:00
|
|
|
#ifdef SERENITY
|
2018-10-18 05:27:07 -03:00
|
|
|
int fd() const { return m_fd; }
|
|
|
|
|
void setFD(int fd) { m_fd = fd; }
|
2018-10-25 08:07:59 -03:00
|
|
|
|
|
|
|
|
bool isBlocking() const { return m_isBlocking; }
|
|
|
|
|
void setBlocking(bool b) { m_isBlocking = b; }
|
2018-10-18 05:27:07 -03:00
|
|
|
#endif
|
|
|
|
|
|
2018-10-26 19:14:24 -03:00
|
|
|
ByteBuffer& generatorCache() { return m_generatorCache; }
|
|
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
|
|
|
|
friend class VirtualFileSystem;
|
|
|
|
|
|
|
|
|
|
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
2018-10-14 16:19:27 -03:00
|
|
|
|
2018-10-14 17:57:41 -03:00
|
|
|
Unix::off_t m_currentOffset { 0 };
|
2018-10-18 05:27:07 -03:00
|
|
|
|
2018-10-26 19:14:24 -03:00
|
|
|
ByteBuffer m_generatorCache;
|
|
|
|
|
|
2018-10-22 09:06:22 -03:00
|
|
|
#ifdef SERENITY
|
2018-10-18 05:27:07 -03:00
|
|
|
int m_fd { -1 };
|
2018-10-25 08:07:59 -03:00
|
|
|
bool m_isBlocking { true };
|
2018-10-18 05:27:07 -03:00
|
|
|
#endif
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|