diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-06 11:36:24 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-06 11:36:24 +0100 |
commit | 1c8f01773059cd858dba76983a6fb721faa515fd (patch) | |
tree | 62847e0021f2370ecbb4eeac1d73485dfe03bb7d | |
parent | f3f0b08d4318a132f528a03575dada47e8eb08b8 (diff) | |
download | serenity-1c8f01773059cd858dba76983a6fb721faa515fd.zip |
Kernel: Remove unused SynthFS filesystem
This used to be the base class of ProcFS and DevPtsFS but not anymore.
-rw-r--r-- | Kernel/FileSystem/SyntheticFileSystem.cpp | 285 | ||||
-rw-r--r-- | Kernel/FileSystem/SyntheticFileSystem.h | 93 | ||||
-rw-r--r-- | Kernel/Makefile | 1 |
3 files changed, 0 insertions, 379 deletions
diff --git a/Kernel/FileSystem/SyntheticFileSystem.cpp b/Kernel/FileSystem/SyntheticFileSystem.cpp deleted file mode 100644 index 49c61f9e30..0000000000 --- a/Kernel/FileSystem/SyntheticFileSystem.cpp +++ /dev/null @@ -1,285 +0,0 @@ -#include <AK/StdLibExtras.h> -#include <Kernel/FileSystem/FileDescription.h> -#include <Kernel/FileSystem/SyntheticFileSystem.h> -#include <LibC/errno_numbers.h> - -//#define SYNTHFS_DEBUG - -NonnullRefPtr<SynthFS> SynthFS::create() -{ - return adopt(*new SynthFS); -} - -SynthFS::SynthFS() -{ -} - -SynthFS::~SynthFS() -{ -} - -bool SynthFS::initialize() -{ - // Add a File for the root directory. - // FIXME: This needs work. - auto root = adopt(*new SynthFSInode(*this, RootInodeIndex)); - root->m_parent = { fsid(), RootInodeIndex }; - root->m_metadata.mode = 0040555; - root->m_metadata.uid = 0; - root->m_metadata.gid = 0; - root->m_metadata.size = 0; - root->m_metadata.mtime = mepoch; - m_inodes.set(RootInodeIndex, move(root)); - return true; -} - -NonnullRefPtr<SynthFSInode> SynthFS::create_directory(String&& name) -{ - auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); - file->m_name = move(name); - file->m_metadata.size = 0; - file->m_metadata.uid = 0; - file->m_metadata.gid = 0; - file->m_metadata.mode = 0040555; - file->m_metadata.mtime = mepoch; - return file; -} - -NonnullRefPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& generator, mode_t mode) -{ - auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); - file->m_generator = move(generator); - file->m_name = move(name); - file->m_metadata.size = 0; - file->m_metadata.uid = 0; - file->m_metadata.gid = 0; - file->m_metadata.mode = mode; - file->m_metadata.mtime = mepoch; - return file; -} - -NonnullRefPtr<SynthFSInode> SynthFS::create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&& read_callback, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&& write_callback, mode_t mode) -{ - auto file = adopt(*new SynthFSInode(*this, generate_inode_index())); - file->m_generator = move(read_callback); - file->m_write_callback = move(write_callback); - file->m_name = move(name); - file->m_metadata.size = 0; - file->m_metadata.uid = 0; - file->m_metadata.gid = 0; - file->m_metadata.mode = mode; - file->m_metadata.mtime = mepoch; - return file; -} - -InodeIdentifier SynthFS::add_file(RefPtr<SynthFSInode>&& file, InodeIndex parent) -{ - LOCKER(m_lock); - ASSERT(file); - auto it = m_inodes.find(parent); - ASSERT(it != m_inodes.end()); - auto new_inode_id = file->identifier(); - file->m_metadata.inode = new_inode_id; - file->m_parent = { fsid(), parent }; - (*it).value->m_children.append(file.ptr()); - m_inodes.set(new_inode_id.index(), move(file)); - return new_inode_id; -} - -bool SynthFS::remove_file(InodeIndex inode) -{ - LOCKER(m_lock); - auto it = m_inodes.find(inode); - if (it == m_inodes.end()) - return false; - auto& file = *(*it).value; - - auto pit = m_inodes.find(file.m_parent.index()); - if (pit == m_inodes.end()) - return false; - auto& parent = *(*pit).value; - for (ssize_t i = 0; i < parent.m_children.size(); ++i) { - if (parent.m_children[i]->m_metadata.inode.index() != inode) - continue; - parent.m_children.remove(i); - break; - } - - Vector<InodeIndex> indices_to_remove; - indices_to_remove.ensure_capacity(file.m_children.size()); - for (auto& child : file.m_children) - indices_to_remove.unchecked_append(child->m_metadata.inode.index()); - for (auto& index : indices_to_remove) - remove_file(index); - m_inodes.remove(inode); - return true; -} - -const char* SynthFS::class_name() const -{ - return "synthfs"; -} - -InodeIdentifier SynthFS::root_inode() const -{ - return { fsid(), 1 }; -} - -RefPtr<Inode> SynthFS::create_inode(InodeIdentifier parentInode, const String& name, mode_t mode, off_t size, dev_t, int& error) -{ - (void)parentInode; - (void)name; - (void)mode; - (void)size; - (void)error; - kprintf("FIXME: Implement SyntheticFileSystem::create_inode().\n"); - return {}; -} - -RefPtr<Inode> SynthFS::create_directory(InodeIdentifier, const String&, mode_t, int& error) -{ - error = -EROFS; - return nullptr; -} - -auto SynthFS::generate_inode_index() -> InodeIndex -{ - LOCKER(m_lock); - return m_next_inode_index++; -} - -RefPtr<Inode> SynthFS::get_inode(InodeIdentifier inode) const -{ - LOCKER(m_lock); - auto it = m_inodes.find(inode.index()); - if (it == m_inodes.end()) - return {}; - return (*it).value; -} - -SynthFSInode::SynthFSInode(SynthFS& fs, unsigned index) - : Inode(fs, index) -{ - m_metadata.inode = { fs.fsid(), index }; -} - -SynthFSInode::~SynthFSInode() -{ -} - -InodeMetadata SynthFSInode::metadata() const -{ - return m_metadata; -} - -ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDescription* description) const -{ - LOCKER(m_lock); -#ifdef SYNTHFS_DEBUG - kprintf("SynthFS: read_bytes %u\n", index()); -#endif - ASSERT(offset >= 0); - ASSERT(buffer); - - Optional<KBuffer> generated_data; - if (m_generator) { - if (!description) { - generated_data = m_generator(const_cast<SynthFSInode&>(*this)); - } else { - if (!description->generator_cache()) - description->generator_cache() = m_generator(const_cast<SynthFSInode&>(*this)); - generated_data = description->generator_cache(); - } - } - - ASSERT(generated_data.has_value()); - ssize_t nread = min(static_cast<off_t>(generated_data.value().size() - offset), static_cast<off_t>(count)); - memcpy(buffer, generated_data.value().data() + offset, nread); - if (nread == 0 && description && description->generator_cache()) - description->generator_cache().clear(); - return nread; -} - -bool SynthFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> callback) const -{ - LOCKER(m_lock); -#ifdef SYNTHFS_DEBUG - kprintf("SynthFS: traverse_as_directory %u\n", index()); -#endif - - if (!m_metadata.is_directory()) - return false; - - callback({ ".", 1, m_metadata.inode, 2 }); - callback({ "..", 2, m_parent, 2 }); - - for (auto& child : m_children) - callback({ child->m_name.characters(), child->m_name.length(), child->m_metadata.inode, child->m_metadata.is_directory() ? (u8)2 : (u8)1 }); - return true; -} - -InodeIdentifier SynthFSInode::lookup(StringView name) -{ - LOCKER(m_lock); - ASSERT(is_directory()); - if (name == ".") - return identifier(); - if (name == "..") - return m_parent; - for (auto& child : m_children) { - if (child->m_name == name) - return child->identifier(); - } - return {}; -} - -void SynthFSInode::flush_metadata() -{ -} - -ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const u8* buffer, FileDescription*) -{ - LOCKER(m_lock); - if (!m_write_callback) - return -EPERM; - // FIXME: Being able to write into SynthFS at a non-zero offset seems like something we should support.. - ASSERT(offset == 0); - bool success = m_write_callback(*this, ByteBuffer::wrap(buffer, size)); - ASSERT(success); - return 0; -} - -KResult SynthFSInode::add_child(InodeIdentifier child_id, const StringView& name, mode_t) -{ - (void)child_id; - (void)name; - ASSERT_NOT_REACHED(); -} - -KResult SynthFSInode::remove_child(const StringView& name) -{ - (void)name; - ASSERT_NOT_REACHED(); -} - -SynthFSInodeCustomData::~SynthFSInodeCustomData() -{ -} - -size_t SynthFSInode::directory_entry_count() const -{ - LOCKER(m_lock); - ASSERT(is_directory()); - // NOTE: The 2 is for '.' and '..' - return m_children.size() + 2; -} - -KResult SynthFSInode::chmod(mode_t) -{ - return KResult(-EPERM); -} - -KResult SynthFSInode::chown(uid_t, gid_t) -{ - return KResult(-EPERM); -} diff --git a/Kernel/FileSystem/SyntheticFileSystem.h b/Kernel/FileSystem/SyntheticFileSystem.h deleted file mode 100644 index df7cdccd16..0000000000 --- a/Kernel/FileSystem/SyntheticFileSystem.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include <AK/HashMap.h> -#include <Kernel/FileSystem/FileSystem.h> -#include <Kernel/FileSystem/Inode.h> -#include <Kernel/KBuffer.h> -#include <Kernel/UnixTypes.h> - -class SynthFSInode; - -class SynthFS : public FS { -public: - virtual ~SynthFS() override; - static NonnullRefPtr<SynthFS> create(); - - virtual bool initialize() override; - virtual const char* class_name() const override; - virtual InodeIdentifier root_inode() const override; - virtual RefPtr<Inode> create_inode(InodeIdentifier parentInode, const String& name, mode_t, off_t size, dev_t, int& error) override; - virtual RefPtr<Inode> create_directory(InodeIdentifier parentInode, const String& name, mode_t, int& error) override; - virtual RefPtr<Inode> get_inode(InodeIdentifier) const override; - -protected: - typedef unsigned InodeIndex; - - InodeIndex generate_inode_index(); - static constexpr InodeIndex RootInodeIndex = 1; - - SynthFS(); - - NonnullRefPtr<SynthFSInode> create_directory(String&& name); - NonnullRefPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, mode_t = 0100644); - NonnullRefPtr<SynthFSInode> create_generated_file(String&& name, Function<ByteBuffer(SynthFSInode&)>&&, Function<ssize_t(SynthFSInode&, const ByteBuffer&)>&&, mode_t = 0100644); - - InodeIdentifier add_file(RefPtr<SynthFSInode>&&, InodeIndex parent = RootInodeIndex); - bool remove_file(InodeIndex); - -private: - InodeIndex m_next_inode_index { 2 }; - HashMap<InodeIndex, RefPtr<SynthFSInode>> m_inodes; -}; - -struct SynthFSInodeCustomData { - virtual ~SynthFSInodeCustomData(); -}; - -class SynthFSInode final : public Inode { - friend class SynthFS; - friend class DevPtsFS; - -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(off_t, ssize_t, u8* buffer, FileDescription*) const override; - virtual InodeMetadata metadata() const override; - virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override; - virtual InodeIdentifier lookup(StringView name) override; - virtual void flush_metadata() override; - virtual ssize_t write_bytes(off_t, ssize_t, const u8* buffer, FileDescription*) override; - virtual KResult add_child(InodeIdentifier child_id, const StringView& name, mode_t) override; - virtual KResult remove_child(const StringView& name) override; - virtual size_t directory_entry_count() const override; - virtual KResult chmod(mode_t) override; - virtual KResult chown(uid_t, gid_t) override; - - SynthFS& fs(); - const SynthFS& fs() const; - SynthFSInode(SynthFS&, unsigned index); - - String m_name; - InodeIdentifier m_parent; - Function<KBuffer(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() -{ - return static_cast<SynthFS&>(Inode::fs()); -} - -inline const SynthFS& SynthFSInode::fs() const -{ - return static_cast<const SynthFS&>(Inode::fs()); -} diff --git a/Kernel/Makefile b/Kernel/Makefile index 79e9021359..abdcbbaa0a 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -89,7 +89,6 @@ VFS_OBJS = \ FileSystem/Ext2FileSystem.o \ FileSystem/VirtualFileSystem.o \ FileSystem/FileDescription.o \ - FileSystem/SyntheticFileSystem.o \ Devices/SB16.o AK_OBJS = \ |