mirror of
https://github.com/RGBCube/serenity
synced 2025-10-13 22:12:06 +00:00

I also added a generator cache to FileHandle. This way, multiple reads to a generated file (i.e in a synthfs) can transparently handle multiple calls to read() without the contents changing between calls. The cache is discarded at EOF (or when the FileHandle is destroyed.)
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "VirtualFileSystem.h"
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
class FileHandle {
|
|
public:
|
|
explicit FileHandle(RetainPtr<VirtualFileSystem::Node>&&);
|
|
~FileHandle();
|
|
|
|
Unix::off_t seek(Unix::off_t, int whence);
|
|
Unix::ssize_t read(byte* buffer, Unix::size_t count);
|
|
int stat(Unix::stat*);
|
|
|
|
bool hasDataAvailableForRead();
|
|
|
|
ssize_t get_dir_entries(byte* buffer, Unix::size_t);
|
|
|
|
ByteBuffer readEntireFile();
|
|
|
|
String absolutePath() const;
|
|
|
|
bool isDirectory() const;
|
|
|
|
VirtualFileSystem::Node* vnode() { return m_vnode.ptr(); }
|
|
|
|
#ifdef SERENITY
|
|
int fd() const { return m_fd; }
|
|
void setFD(int fd) { m_fd = fd; }
|
|
|
|
bool isBlocking() const { return m_isBlocking; }
|
|
void setBlocking(bool b) { m_isBlocking = b; }
|
|
#endif
|
|
|
|
ByteBuffer& generatorCache() { return m_generatorCache; }
|
|
|
|
private:
|
|
friend class VirtualFileSystem;
|
|
|
|
RetainPtr<VirtualFileSystem::Node> m_vnode;
|
|
|
|
Unix::off_t m_currentOffset { 0 };
|
|
|
|
ByteBuffer m_generatorCache;
|
|
|
|
#ifdef SERENITY
|
|
int m_fd { -1 };
|
|
bool m_isBlocking { true };
|
|
#endif
|
|
};
|
|
|