1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 21:25:07 +00:00
serenity/VirtualFileSystem/SyntheticFileSystem.h
Andreas Kling 2716a9e2d7 Greatly improve /proc/PID/stack by tracing the ebp frame chain.
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.)
2018-10-27 00:14:24 +02:00

51 lines
1.8 KiB
C++

#pragma once
#include "FileSystem.h"
#include "UnixTypes.h"
#include <AK/HashMap.h>
class SyntheticFileSystem : public FileSystem {
public:
virtual ~SyntheticFileSystem() override;
static RetainPtr<SyntheticFileSystem> create();
virtual bool initialize() override;
virtual const char* className() const override;
virtual InodeIdentifier rootInode() const override;
virtual bool writeInode(InodeIdentifier, const ByteBuffer&) override;
virtual bool enumerateDirectoryInode(InodeIdentifier, Function<bool(const DirectoryEntry&)>) const override;
virtual InodeMetadata inodeMetadata(InodeIdentifier) const override;
virtual bool setModificationTime(InodeIdentifier, dword timestamp) override;
virtual InodeIdentifier createInode(InodeIdentifier parentInode, const String& name, Unix::mode_t, unsigned size) override;
virtual Unix::ssize_t readInodeBytes(InodeIdentifier, Unix::off_t offset, Unix::size_t count, byte* buffer, FileHandle*) const override;
virtual InodeIdentifier makeDirectory(InodeIdentifier parentInode, const String& name, Unix::mode_t) override;
protected:
typedef unsigned InodeIndex;
InodeIndex generateInodeIndex();
static constexpr InodeIndex RootInodeIndex = 1;
SyntheticFileSystem();
struct File {
String name;
InodeMetadata metadata;
InodeIdentifier parent;
ByteBuffer data;
Function<ByteBuffer()> generator;
Vector<File*> children;
};
OwnPtr<File> createDirectory(String&& name);
OwnPtr<File> createTextFile(String&& name, String&& text);
OwnPtr<File> createGeneratedFile(String&& name, Function<ByteBuffer()>&&);
InodeIdentifier addFile(OwnPtr<File>&&, InodeIndex parent = RootInodeIndex);
bool removeFile(InodeIndex);
private:
InodeIndex m_nextInodeIndex { 2 };
HashMap<InodeIndex, OwnPtr<File>> m_inodes;
};