diff options
Diffstat (limited to 'VirtualFileSystem')
-rw-r--r-- | VirtualFileSystem/DiskDevice.cpp | 36 | ||||
-rw-r--r-- | VirtualFileSystem/DiskDevice.h | 4 | ||||
-rw-r--r-- | VirtualFileSystem/Ext2FileSystem.cpp | 4 | ||||
-rw-r--r-- | VirtualFileSystem/FileBackedDiskDevice.cpp | 8 | ||||
-rw-r--r-- | VirtualFileSystem/FileBackedDiskDevice.h | 5 |
5 files changed, 47 insertions, 10 deletions
diff --git a/VirtualFileSystem/DiskDevice.cpp b/VirtualFileSystem/DiskDevice.cpp index 62f7211421..e7f0cce206 100644 --- a/VirtualFileSystem/DiskDevice.cpp +++ b/VirtualFileSystem/DiskDevice.cpp @@ -7,3 +7,39 @@ DiskDevice::DiskDevice() DiskDevice::~DiskDevice() { } + +bool DiskDevice::read(qword offset, unsigned length, byte* out) const +{ + ASSERT((offset % blockSize()) == 0); + ASSERT((length % blockSize()) == 0); + qword firstBlock = offset / blockSize(); + qword endBlock = (offset + length) / blockSize(); + ASSERT(firstBlock <= 0xffffffff); + ASSERT(endBlock <= 0xffffffff); + byte* outptr = out; + unsigned remainingCount = length; + for (unsigned bi = firstBlock; bi < endBlock; ++bi) { + if (!readBlock(bi, outptr)) + return false; + outptr += blockSize(); + } + return true; +} + +bool DiskDevice::write(qword offset, unsigned length, const byte* in) +{ + ASSERT((offset % blockSize()) == 0); + ASSERT((length % blockSize()) == 0); + qword firstBlock = offset / blockSize(); + qword endBlock = (offset + length) / blockSize(); + ASSERT(firstBlock <= 0xffffffff); + ASSERT(endBlock <= 0xffffffff); + const byte* inptr = in; + for (unsigned bi = firstBlock; bi < endBlock; ++bi) { + if (!writeBlock(bi, inptr)) + return false; + inptr += blockSize(); + } + return true; +} + diff --git a/VirtualFileSystem/DiskDevice.h b/VirtualFileSystem/DiskDevice.h index 31d1418687..4ecce51bb1 100644 --- a/VirtualFileSystem/DiskDevice.h +++ b/VirtualFileSystem/DiskDevice.h @@ -11,8 +11,8 @@ public: virtual bool readBlock(unsigned index, byte*) const = 0; virtual bool writeBlock(unsigned index, const byte*) = 0; virtual const char* className() const = 0; - virtual bool read(qword offset, unsigned length, byte*) const = 0; - virtual bool write(qword offset, unsigned length, const byte*) = 0; + bool read(qword offset, unsigned length, byte*) const; + bool write(qword offset, unsigned length, const byte*); protected: DiskDevice(); diff --git a/VirtualFileSystem/Ext2FileSystem.cpp b/VirtualFileSystem/Ext2FileSystem.cpp index 9eb11755b4..1d0159e56a 100644 --- a/VirtualFileSystem/Ext2FileSystem.cpp +++ b/VirtualFileSystem/Ext2FileSystem.cpp @@ -965,8 +965,8 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S // FIXME: Implement writing out indirect blocks! ASSERT(blocks.size() < EXT2_NDIR_BLOCKS); - printf("[XXX] writing %u blocks to i_block array\n", min((unsigned)EXT2_NDIR_BLOCKS, blocks.size())); - for (unsigned i = 0; i < min((unsigned)EXT2_NDIR_BLOCKS, blocks.size()); ++i) { + printf("[XXX] writing %u blocks to i_block array\n", min((size_t)EXT2_NDIR_BLOCKS, blocks.size())); + for (unsigned i = 0; i < min((size_t)EXT2_NDIR_BLOCKS, blocks.size()); ++i) { e2inode->i_block[i] = blocks[i]; } diff --git a/VirtualFileSystem/FileBackedDiskDevice.cpp b/VirtualFileSystem/FileBackedDiskDevice.cpp index d857ff502e..854b932900 100644 --- a/VirtualFileSystem/FileBackedDiskDevice.cpp +++ b/VirtualFileSystem/FileBackedDiskDevice.cpp @@ -35,16 +35,16 @@ unsigned FileBackedDiskDevice::blockSize() const bool FileBackedDiskDevice::readBlock(unsigned index, byte* out) const { qword offset = index * m_blockSize; - return read(offset, blockSize(), out); + return readInternal(offset, blockSize(), out); } bool FileBackedDiskDevice::writeBlock(unsigned index, const byte* data) { qword offset = index * m_blockSize; - return write(offset, blockSize(), data); + return writeInternal(offset, blockSize(), data); } -bool FileBackedDiskDevice::read(qword offset, unsigned length, byte* out) const +bool FileBackedDiskDevice::readInternal(qword offset, unsigned length, byte* out) const { #ifndef IGNORE_FILE_LENGTH if (offset + length >= m_fileLength) @@ -59,7 +59,7 @@ bool FileBackedDiskDevice::read(qword offset, unsigned length, byte* out) const return true; } -bool FileBackedDiskDevice::write(qword offset, unsigned length, const byte* data) +bool FileBackedDiskDevice::writeInternal(qword offset, unsigned length, const byte* data) { #ifndef IGNORE_FILE_LENGTH if (offset + length >= m_fileLength) diff --git a/VirtualFileSystem/FileBackedDiskDevice.h b/VirtualFileSystem/FileBackedDiskDevice.h index 7115ea0be6..10c4af6922 100644 --- a/VirtualFileSystem/FileBackedDiskDevice.h +++ b/VirtualFileSystem/FileBackedDiskDevice.h @@ -16,12 +16,13 @@ public: virtual unsigned blockSize() const override; virtual bool readBlock(unsigned index, byte* out) const override; virtual bool writeBlock(unsigned index, const byte*) override; - virtual bool read(qword offset, unsigned length, byte* out) const override; - virtual bool write(qword offset, unsigned length, const byte* data) override; private: virtual const char* className() const override; + bool readInternal(qword offset, unsigned length, byte* out) const; + bool writeInternal(qword offset, unsigned length, const byte* data); + FileBackedDiskDevice(String&& imagePath, unsigned blockSize); String m_imagePath; |