mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:24:58 +00:00
Kernel: Don't explicitly seek before I/O in BlockBasedFileSystem
Use the new FileDescription APIs to avoid doing seek+read or seek+write as two separate operations.
This commit is contained in:
parent
d1395f2eb9
commit
abf0249f35
1 changed files with 7 additions and 26 deletions
|
@ -124,10 +124,7 @@ KResult BlockBasedFileSystem::write_block(BlockIndex index, const UserOrKernelBu
|
|||
if (!allow_cache) {
|
||||
flush_specific_block_if_needed(index);
|
||||
auto base_offset = index.value() * block_size() + offset;
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
if (seek_result.is_error())
|
||||
return seek_result.error();
|
||||
auto nwritten = file_description().write(data, count);
|
||||
auto nwritten = file_description().write(base_offset, data, count);
|
||||
if (nwritten.is_error())
|
||||
return nwritten.error();
|
||||
VERIFY(nwritten.value() == count);
|
||||
|
@ -153,9 +150,7 @@ bool BlockBasedFileSystem::raw_read(BlockIndex index, UserOrKernelBuffer& buffer
|
|||
{
|
||||
Locker locker(m_lock);
|
||||
auto base_offset = index.value() * m_logical_block_size;
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
VERIFY(!seek_result.is_error());
|
||||
auto nread = file_description().read(buffer, m_logical_block_size);
|
||||
auto nread = file_description().read(buffer, base_offset, m_logical_block_size);
|
||||
VERIFY(!nread.is_error());
|
||||
VERIFY(nread.value() == m_logical_block_size);
|
||||
return true;
|
||||
|
@ -165,9 +160,7 @@ bool BlockBasedFileSystem::raw_write(BlockIndex index, const UserOrKernelBuffer&
|
|||
{
|
||||
Locker locker(m_lock);
|
||||
auto base_offset = index.value() * m_logical_block_size;
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
VERIFY(!seek_result.is_error());
|
||||
auto nwritten = file_description().write(buffer, m_logical_block_size);
|
||||
auto nwritten = file_description().write(base_offset, buffer, m_logical_block_size);
|
||||
VERIFY(!nwritten.is_error());
|
||||
VERIFY(nwritten.value() == m_logical_block_size);
|
||||
return true;
|
||||
|
@ -220,10 +213,7 @@ KResult BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* b
|
|||
if (!allow_cache) {
|
||||
const_cast<BlockBasedFileSystem*>(this)->flush_specific_block_if_needed(index);
|
||||
auto base_offset = index.value() * block_size() + offset;
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
if (seek_result.is_error())
|
||||
return seek_result.error();
|
||||
auto nread = file_description().read(*buffer, count);
|
||||
auto nread = file_description().read(*buffer, base_offset, count);
|
||||
if (nread.is_error())
|
||||
return nread.error();
|
||||
VERIFY(nread.value() == count);
|
||||
|
@ -233,11 +223,8 @@ KResult BlockBasedFileSystem::read_block(BlockIndex index, UserOrKernelBuffer* b
|
|||
auto& entry = cache().get(index);
|
||||
if (!entry.has_data) {
|
||||
auto base_offset = index.value() * block_size();
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
if (seek_result.is_error())
|
||||
return seek_result.error();
|
||||
auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry.data);
|
||||
auto nread = file_description().read(entry_data_buffer, block_size());
|
||||
auto nread = file_description().read(entry_data_buffer, base_offset, block_size());
|
||||
if (nread.is_error())
|
||||
return nread.error();
|
||||
VERIFY(nread.value() == block_size());
|
||||
|
@ -276,11 +263,8 @@ void BlockBasedFileSystem::flush_specific_block_if_needed(BlockIndex index)
|
|||
cache().for_each_dirty_entry([&](CacheEntry& entry) {
|
||||
if (entry.block_index != index) {
|
||||
size_t base_offset = entry.block_index.value() * block_size();
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
VERIFY(!seek_result.is_error());
|
||||
// FIXME: Should this error path be surfaced somehow?
|
||||
auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry.data);
|
||||
[[maybe_unused]] auto rc = file_description().write(entry_data_buffer, block_size());
|
||||
[[maybe_unused]] auto rc = file_description().write(base_offset, entry_data_buffer, block_size());
|
||||
cleaned_entries.append(&entry);
|
||||
}
|
||||
});
|
||||
|
@ -298,11 +282,8 @@ void BlockBasedFileSystem::flush_writes_impl()
|
|||
u32 count = 0;
|
||||
cache().for_each_dirty_entry([&](CacheEntry& entry) {
|
||||
auto base_offset = entry.block_index.value() * block_size();
|
||||
auto seek_result = file_description().seek(base_offset, SEEK_SET);
|
||||
VERIFY(!seek_result.is_error());
|
||||
// FIXME: Should this error path be surfaced somehow?
|
||||
auto entry_data_buffer = UserOrKernelBuffer::for_kernel_buffer(entry.data);
|
||||
[[maybe_unused]] auto rc = file_description().write(entry_data_buffer, block_size());
|
||||
[[maybe_unused]] auto rc = file_description().write(base_offset, entry_data_buffer, block_size());
|
||||
++count;
|
||||
});
|
||||
cache().mark_all_clean();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue