summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-16 00:38:35 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-16 02:40:53 +0200
commitabf0249f352b3c4bc90da9566d010b0c28720b71 (patch)
tree50fcce836c89371b360565c18fa42101e1f34113 /Kernel/FileSystem
parentd1395f2eb942cd4a382f79732e1181e84bc136ce (diff)
downloadserenity-abf0249f352b3c4bc90da9566d010b0c28720b71.zip
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.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r--Kernel/FileSystem/BlockBasedFileSystem.cpp33
1 files changed, 7 insertions, 26 deletions
diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp
index 1e36e0819d..d4ba393c36 100644
--- a/Kernel/FileSystem/BlockBasedFileSystem.cpp
+++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp
@@ -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();