diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-16 03:02:37 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-16 03:02:37 +0200 |
commit | 176f683f663eadc49d611ed9156aedd193e3cb31 (patch) | |
tree | 75af46c8e19b2d392e8532977e967130c6eef523 /Kernel/FileSystem/FileSystem.cpp | |
parent | 8aecebe8f3cfcae0cb24301383cc30a7247fb38e (diff) | |
download | serenity-176f683f663eadc49d611ed9156aedd193e3cb31.zip |
Kernel: Move Inode to its own files.
Diffstat (limited to 'Kernel/FileSystem/FileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/FileSystem.cpp | 122 |
1 files changed, 3 insertions, 119 deletions
diff --git a/Kernel/FileSystem/FileSystem.cpp b/Kernel/FileSystem/FileSystem.cpp index 99a591bcda..a8619bd806 100644 --- a/Kernel/FileSystem/FileSystem.cpp +++ b/Kernel/FileSystem/FileSystem.cpp @@ -2,13 +2,13 @@ #include <AK/HashMap.h> #include <AK/StringBuilder.h> #include <LibC/errno_numbers.h> -#include "FileSystem.h" +#include <Kernel/FileSystem/FileSystem.h> +#include <Kernel/FileSystem/Inode.h> #include <Kernel/VM/MemoryManager.h> #include <Kernel/Net/LocalSocket.h> static dword s_lastFileSystemID; static HashMap<dword, FS*>* s_fs_map; -static HashTable<Inode*>* s_inode_set; static HashMap<dword, FS*>& all_fses() { @@ -17,12 +17,6 @@ static HashMap<dword, FS*>& all_fses() return *s_fs_map; } -HashTable<Inode*>& all_inodes() -{ - if (!s_inode_set) - s_inode_set = new HashTable<Inode*>(); - return *s_inode_set; -} FS::FS() : m_fsid(++s_lastFileSystemID) @@ -43,30 +37,6 @@ FS* FS::from_fsid(dword id) return nullptr; } -ByteBuffer Inode::read_entire(FileDescriptor* descriptor) const -{ - size_t initial_size = metadata().size ? metadata().size : 4096; - StringBuilder builder(initial_size); - - ssize_t nread; - byte buffer[4096]; - off_t offset = 0; - for (;;) { - nread = read_bytes(offset, sizeof(buffer), buffer, descriptor); - ASSERT(nread <= (ssize_t)sizeof(buffer)); - if (nread <= 0) - break; - builder.append((const char*)buffer, nread); - offset += nread; - } - if (nread < 0) { - kprintf("Inode::read_entire: ERROR: %d\n", nread); - return nullptr; - } - - return builder.to_byte_buffer(); -} - FS::DirectoryEntry::DirectoryEntry(const char* n, InodeIdentifier i, byte ft) : name_length(strlen(n)) , inode(i) @@ -85,76 +55,9 @@ FS::DirectoryEntry::DirectoryEntry(const char* n, int nl, InodeIdentifier i, byt name[nl] = '\0'; } -Inode::Inode(FS& fs, unsigned index) - : m_fs(fs) - , m_index(index) -{ - all_inodes().set(this); -} - -Inode::~Inode() -{ - all_inodes().remove(this); -} - -void Inode::will_be_destroyed() -{ - if (m_metadata_dirty) - flush_metadata(); -} - -void Inode::inode_contents_changed(off_t offset, ssize_t size, const byte* data) -{ - if (m_vmo) - m_vmo->inode_contents_changed(Badge<Inode>(), offset, size, data); -} - -void Inode::inode_size_changed(size_t old_size, size_t new_size) -{ - if (m_vmo) - m_vmo->inode_size_changed(Badge<Inode>(), old_size, new_size); -} - -int Inode::set_atime(time_t) -{ - return -ENOTIMPL; -} - -int Inode::set_ctime(time_t) -{ - return -ENOTIMPL; -} - -int Inode::set_mtime(time_t) -{ - return -ENOTIMPL; -} - -int Inode::increment_link_count() -{ - return -ENOTIMPL; -} - -int Inode::decrement_link_count() -{ - return -ENOTIMPL; -} - void FS::sync() { - Vector<Retained<Inode>, 32> inodes; - { - InterruptDisabler disabler; - for (auto* inode : all_inodes()) { - if (inode->is_metadata_dirty()) - inodes.append(*inode); - } - } - - for (auto& inode : inodes) { - ASSERT(inode->is_metadata_dirty()); - inode->flush_metadata(); - } + Inode::sync(); Vector<Retained<FS>, 32> fses; { @@ -166,22 +69,3 @@ void FS::sync() for (auto fs : fses) fs->flush_writes(); } - -void Inode::set_vmo(VMObject& vmo) -{ - m_vmo = vmo.make_weak_ptr(); -} - -bool Inode::bind_socket(LocalSocket& socket) -{ - ASSERT(!m_socket); - m_socket = socket; - return true; -} - -bool Inode::unbind_socket() -{ - ASSERT(m_socket); - m_socket = nullptr; - return true; -} |