Move readEntireInode() up to FileSystem (from ext2.)

It's just a wrapper around multiple calls to readInodeBytes() now.
This commit is contained in:
Andreas Kling 2018-10-15 00:16:14 +02:00
parent 0286b5ea48
commit 9528edab92
Notes: sideshowbarker 2024-07-19 18:48:03 +09:00
9 changed files with 39 additions and 52 deletions

View file

@ -336,38 +336,6 @@ Unix::ssize_t Ext2FileSystem::readInodeBytes(InodeIdentifier inode, Unix::off_t
return nread;
}
ByteBuffer Ext2FileSystem::readInode(InodeIdentifier inode) const
{
ASSERT(inode.fileSystemID() == id());
auto e2inode = lookupExt2Inode(inode.index());
if (!e2inode) {
printf("[ext2fs] readInode: metadata lookup for inode %u failed\n", inode.index());
return nullptr;
}
auto contents = ByteBuffer::createUninitialized(e2inode->i_size);
Unix::ssize_t nread;
byte buffer[512];
byte* out = contents.pointer();
Unix::off_t offset = 0;
for (;;) {
nread = readInodeBytes(inode, offset, sizeof(buffer), buffer);
if (nread <= 0)
break;
memcpy(out, buffer, nread);
out += nread;
offset += nread;
}
if (nread < 0) {
printf("[ext2fs] readInode: ERROR: %d\n", nread);
return nullptr;
}
return contents;
}
bool Ext2FileSystem::writeInode(InodeIdentifier inode, const ByteBuffer& data)
{
ASSERT(inode.fileSystemID() == id());
@ -412,7 +380,7 @@ bool Ext2FileSystem::enumerateDirectoryInode(InodeIdentifier inode, std::functio
printf("[ext2fs] Enumerating directory contents of inode %u:\n", inode.index());
#endif
auto buffer = readInode(inode);
auto buffer = readEntireInode(inode);
ASSERT(buffer);
auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer.pointer());