summaryrefslogtreecommitdiff
path: root/Kernel/Storage/Partition
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/Storage/Partition')
-rw-r--r--Kernel/Storage/Partition/DiskPartition.cpp13
-rw-r--r--Kernel/Storage/Partition/DiskPartition.h3
2 files changed, 10 insertions, 6 deletions
diff --git a/Kernel/Storage/Partition/DiskPartition.cpp b/Kernel/Storage/Partition/DiskPartition.cpp
index 367a3b3a4f..17d474f011 100644
--- a/Kernel/Storage/Partition/DiskPartition.cpp
+++ b/Kernel/Storage/Partition/DiskPartition.cpp
@@ -33,7 +33,10 @@ const DiskPartitionMetadata& DiskPartition::metadata() const
void DiskPartition::start_request(AsyncBlockDeviceRequest& request)
{
- auto sub_request_or_error = m_device->try_make_request<AsyncBlockDeviceRequest>(request.request_type(),
+ auto device = m_device.strong_ref();
+ if (!device)
+ request.complete(AsyncBlockDeviceRequest::RequestResult::Failure);
+ auto sub_request_or_error = device->try_make_request<AsyncBlockDeviceRequest>(request.request_type(),
request.block_index() + m_metadata.start_block(), request.block_count(), request.buffer(), request.buffer_size());
if (sub_request_or_error.is_error())
TODO();
@@ -44,28 +47,28 @@ KResultOr<size_t> DiskPartition::read(OpenFileDescription& fd, u64 offset, UserO
{
unsigned adjust = m_metadata.start_block() * block_size();
dbgln_if(OFFD_DEBUG, "DiskPartition::read offset={}, adjust={}, len={}", fd.offset(), adjust, len);
- return m_device->read(fd, offset + adjust, outbuf, len);
+ return m_device.strong_ref()->read(fd, offset + adjust, outbuf, len);
}
bool DiskPartition::can_read(const OpenFileDescription& fd, size_t offset) const
{
unsigned adjust = m_metadata.start_block() * block_size();
dbgln_if(OFFD_DEBUG, "DiskPartition::can_read offset={}, adjust={}", offset, adjust);
- return m_device->can_read(fd, offset + adjust);
+ return m_device.strong_ref()->can_read(fd, offset + adjust);
}
KResultOr<size_t> DiskPartition::write(OpenFileDescription& fd, u64 offset, const UserOrKernelBuffer& inbuf, size_t len)
{
unsigned adjust = m_metadata.start_block() * block_size();
dbgln_if(OFFD_DEBUG, "DiskPartition::write offset={}, adjust={}, len={}", offset, adjust, len);
- return m_device->write(fd, offset + adjust, inbuf, len);
+ return m_device.strong_ref()->write(fd, offset + adjust, inbuf, len);
}
bool DiskPartition::can_write(const OpenFileDescription& fd, size_t offset) const
{
unsigned adjust = m_metadata.start_block() * block_size();
dbgln_if(OFFD_DEBUG, "DiskPartition::can_write offset={}, adjust={}", offset, adjust);
- return m_device->can_write(fd, offset + adjust);
+ return m_device.strong_ref()->can_write(fd, offset + adjust);
}
StringView DiskPartition::class_name() const
diff --git a/Kernel/Storage/Partition/DiskPartition.h b/Kernel/Storage/Partition/DiskPartition.h
index 0352ee2883..46f99a1fcd 100644
--- a/Kernel/Storage/Partition/DiskPartition.h
+++ b/Kernel/Storage/Partition/DiskPartition.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/RefPtr.h>
+#include <AK/WeakPtr.h>
#include <Kernel/Devices/BlockDevice.h>
#include <Kernel/Storage/Partition/DiskPartitionMetadata.h>
@@ -32,7 +33,7 @@ private:
DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
- NonnullRefPtr<BlockDevice> m_device;
+ WeakPtr<BlockDevice> m_device;
DiskPartitionMetadata m_metadata;
};