Add mechanism to expose kernel variables to userspace via ProcFS.

Only booleans are supported at first. More types can be added easily.
Use this to add /proc/sys/wm_flash_flush which when enabled flashes pending
screen flush rects in yellow before they happen.
This commit is contained in:
Andreas Kling
2019-01-18 15:01:40 +01:00
parent 9454c5dd52
commit f7cc454162
8 changed files with 121 additions and 29 deletions

View File

@@ -28,7 +28,8 @@ protected:
RetainPtr<SynthFSInode> create_directory(String&& name);
RetainPtr<SynthFSInode> create_text_file(String&& name, ByteBuffer&&, Unix::mode_t = 0010644);
RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer()>&&, Unix::mode_t = 0100644);
RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Unix::mode_t = 0100644);
RetainPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, Unix::mode_t = 0100644);
InodeIdentifier add_file(RetainPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex);
bool remove_file(InodeIndex);
@@ -38,11 +39,19 @@ private:
HashMap<InodeIndex, RetainPtr<SynthFSInode>> m_inodes;
};
struct SynthFSInodeCustomData {
virtual ~SynthFSInodeCustomData();
};
class SynthFSInode final : public Inode {
friend class SynthFS;
public:
virtual ~SynthFSInode() override;
void set_custom_data(OwnPtr<SynthFSInodeCustomData>&& custom_data) { m_custom_data = move(custom_data); }
SynthFSInodeCustomData* custom_data() { return m_custom_data.ptr(); }
const SynthFSInodeCustomData* custom_data() const { return m_custom_data.ptr(); }
private:
// ^Inode
virtual ssize_t read_bytes(Unix::off_t, size_t, byte* buffer, FileDescriptor*) override;
@@ -62,9 +71,11 @@ private:
String m_name;
InodeIdentifier m_parent;
ByteBuffer m_data;
Function<ByteBuffer()> m_generator;
Function<ByteBuffer(SynthFSInode&)> m_generator;
Function<ssize_t(SynthFSInode&, const ByteBuffer&)> m_write_callback;
Vector<SynthFSInode*> m_children;
InodeMetadata m_metadata;
OwnPtr<SynthFSInodeCustomData> m_custom_data;
};
inline SynthFS& SynthFSInode::fs()