mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
Move readEntireInode() up to FileSystem (from ext2.)
It's just a wrapper around multiple calls to readInodeBytes() now.
This commit is contained in:
parent
0286b5ea48
commit
9528edab92
Notes:
sideshowbarker
2024-07-19 18:48:03 +09:00
Author: https://github.com/awesomekling
Commit: 9528edab92
9 changed files with 39 additions and 52 deletions
|
@ -29,7 +29,7 @@ FileSystem* FileSystem::fromID(dword id)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode, const String& name)
|
||||
InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode, const String& name) const
|
||||
{
|
||||
InodeIdentifier foundInode;
|
||||
enumerateDirectoryInode(inode, [&] (const DirectoryEntry& entry) {
|
||||
|
@ -42,3 +42,35 @@ InodeIdentifier FileSystem::childOfDirectoryInodeWithName(InodeIdentifier inode,
|
|||
return foundInode;
|
||||
}
|
||||
|
||||
ByteBuffer FileSystem::readEntireInode(InodeIdentifier inode) const
|
||||
{
|
||||
ASSERT(inode.fileSystemID() == id());
|
||||
|
||||
auto metadata = inodeMetadata(inode);
|
||||
if (!metadata.isValid()) {
|
||||
printf("[fs] readInode: metadata lookup for inode %u failed\n", inode.index());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto contents = ByteBuffer::createUninitialized(metadata.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("[fs] readInode: ERROR: %d\n", nread);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue