From c7c957966acb3c166288be777025f7cea9633d68 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 14 Oct 2018 23:13:45 +0200 Subject: [PATCH] Implement SyntheticFileSystem::readInodeBytes(). --- VirtualFileSystem/Ext2FileSystem.cpp | 12 ++++++------ VirtualFileSystem/SyntheticFileSystem.cpp | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index c27b84e3db..f09b61e9d0 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -258,7 +258,7 @@ Vector Ext2FileSystem::blockListForInode(const ext2_inode& e2inode) co return list; } -ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer) const +Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer) const { ASSERT(offset >= 0); ASSERT(inode.fileSystemID() == id()); @@ -282,7 +282,7 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset // This avoids wasting an entire block on short links. (Most links are short.) static const unsigned maxInlineSymlinkLength = 60; if (isSymbolicLink(e2inode->i_mode) && e2inode->i_size < maxInlineSymlinkLength) { - ssize_t nread = min(e2inode->i_size - offset, static_cast(count)); + Unix::ssize_t nread = min(e2inode->i_size - offset, static_cast(count)); memcpy(buffer, e2inode->i_block + offset, nread); return nread; } @@ -302,8 +302,8 @@ ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset dword offsetIntoFirstBlock = offset % blockSize(); - ssize_t nread = 0; - size_t remainingCount = min((Unix::off_t)count, e2inode->i_size - offset); + Unix::ssize_t nread = 0; + Unix::size_t remainingCount = min((Unix::off_t)count, e2inode->i_size - offset); byte* out = buffer; #ifdef EXT2_DEBUG @@ -346,7 +346,7 @@ ByteBuffer Ext2FileSystem::readInode(InodeIdentifier inode) const auto contents = ByteBuffer::createUninitialized(e2inode->i_size); - ssize_t nread; + Unix::ssize_t nread; byte buffer[512]; byte* out = contents.pointer(); Unix::off_t offset = 0; @@ -501,7 +501,7 @@ public: private: ByteBuffer& m_buffer; - size_t m_offset { 0 }; + Unix::size_t m_offset { 0 }; }; bool Ext2FileSystem::writeDirectoryInode(unsigned directoryInode, Vector&& entries) diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index 50a8473a90..5479933a42 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -1,4 +1,5 @@ #include "SyntheticFileSystem.h" +#include RetainPtr SyntheticFileSystem::create() { @@ -122,8 +123,19 @@ bool SyntheticFileSystem::writeInode(InodeIdentifier, const ByteBuffer&) return false; } -ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier, Unix::off_t offset, size_t count, byte* buffer) const +ssize_t SyntheticFileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t offset, Unix::size_t count, byte* buffer) const { - printf("FIXME: Implement SyntheticFileSystem::readInodeBytes().\n"); - return 0; + ASSERT(inode.fileSystemID() == id()); +#ifdef SYNTHFS_DEBUG + printf("[synthfs] readInode %u\n", inode.index()); +#endif + ASSERT(inode.index() != 1); + ASSERT(inode.index() <= m_files.size()); + ASSERT(offset >= 0); + ASSERT(buffer); + + auto& file = *m_files[inode.index() - 1]; + Unix::ssize_t nread = min(file.data.size() - offset, static_cast(count)); + memcpy(buffer, file.data.pointer() + offset, nread); + return nread; }