mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
Get rid of FS::read_inode_bytes() and use Inode::read_bytes() everywhere.
This commit is contained in:
parent
951ed6692b
commit
8a71303827
Notes:
sideshowbarker
2024-07-19 16:07:37 +09:00
Author: https://github.com/awesomekling
Commit: 8a71303827
8 changed files with 11 additions and 127 deletions
|
@ -404,82 +404,6 @@ ssize_t Ext2FSInode::read_bytes(Unix::off_t offset, size_t count, byte* buffer,
|
|||
return nread;
|
||||
}
|
||||
|
||||
ssize_t Ext2FS::read_inode_bytes(InodeIdentifier inode, Unix::off_t offset, size_t count, byte* buffer, FileDescriptor*) const
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
||||
auto e2inode = lookup_ext2_inode(inode.index());
|
||||
if (!e2inode) {
|
||||
kprintf("ext2fs: readInodeBytes: metadata lookup for inode %u failed\n", inode.index());
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// FIXME: We can't fail here while the directory traversal depends on this function. :]
|
||||
if (isDirectory(e2inode->i_mode))
|
||||
return -EISDIR;
|
||||
#endif
|
||||
|
||||
if (e2inode->i_size == 0)
|
||||
return 0;
|
||||
|
||||
// Symbolic links shorter than 60 characters are store inline inside the i_block array.
|
||||
// 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((Unix::off_t)e2inode->i_size - offset, static_cast<Unix::off_t>(count));
|
||||
memcpy(buffer, e2inode->i_block + offset, nread);
|
||||
return nread;
|
||||
}
|
||||
|
||||
// FIXME: It's grossly inefficient to fetch the blocklist on every call to readInodeBytes().
|
||||
// It needs to be cached!
|
||||
auto list = block_list_for_inode(*e2inode);
|
||||
if (list.is_empty()) {
|
||||
kprintf("ext2fs: readInodeBytes: empty block list for inode %u\n", inode.index());
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dword firstBlockLogicalIndex = offset / blockSize();
|
||||
dword lastBlockLogicalIndex = (offset + count) / blockSize();
|
||||
if (lastBlockLogicalIndex >= list.size())
|
||||
lastBlockLogicalIndex = list.size() - 1;
|
||||
|
||||
dword offsetIntoFirstBlock = offset % blockSize();
|
||||
|
||||
ssize_t nread = 0;
|
||||
size_t remainingCount = min((Unix::off_t)count, (Unix::off_t)e2inode->i_size - offset);
|
||||
byte* out = buffer;
|
||||
|
||||
#ifdef EXT2_DEBUG
|
||||
kprintf("ok let's do it, read(%llu, %u) -> blocks %u thru %u, oifb: %u\n", offset, count, firstBlockLogicalIndex, lastBlockLogicalIndex, offsetIntoFirstBlock);
|
||||
#endif
|
||||
|
||||
for (dword bi = firstBlockLogicalIndex; bi <= lastBlockLogicalIndex; ++bi) {
|
||||
auto block = readBlock(list[bi]);
|
||||
if (!block) {
|
||||
kprintf("ext2fs: readInodeBytes: readBlock(%u) failed (lbi: %u)\n", list[bi], bi);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dword offsetIntoBlock;
|
||||
|
||||
if (bi == firstBlockLogicalIndex)
|
||||
offsetIntoBlock = offsetIntoFirstBlock;
|
||||
else
|
||||
offsetIntoBlock = 0;
|
||||
|
||||
size_t numBytesToCopy = min(blockSize() - offsetIntoBlock, remainingCount);
|
||||
memcpy(out, block.pointer() + offsetIntoBlock, numBytesToCopy);
|
||||
remainingCount -= numBytesToCopy;
|
||||
nread += numBytesToCopy;
|
||||
out += numBytesToCopy;
|
||||
}
|
||||
|
||||
return nread;
|
||||
}
|
||||
|
||||
bool Ext2FS::write_inode(InodeIdentifier inode, const ByteBuffer& data)
|
||||
{
|
||||
ASSERT(inode.fsid() == id());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue