mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
Kernel: Require StorageDevice reference for StorageDevicePartition
Allowing creation of StorageDevicePartition objects for any arbitrary BlockDevice objects means that we could technically create a StorageDevicePartition for another StorageDevicePartition which is obviously not the intention for this code. Instead, require to pass a StorageDevice reference to ensure this cannot happen.
This commit is contained in:
parent
f08f339e9a
commit
c216e7439f
Notes:
sideshowbarker
2024-07-17 01:51:00 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/c216e7439f Pull-request: https://github.com/SerenityOS/serenity/pull/19714 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/Panky-codes
2 changed files with 7 additions and 5 deletions
|
@ -6,12 +6,13 @@
|
|||
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/Devices/Storage/StorageDevice.h>
|
||||
#include <Kernel/Devices/Storage/StorageDevicePartition.h>
|
||||
#include <Kernel/FileSystem/OpenFileDescription.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullLockRefPtr<StorageDevicePartition> StorageDevicePartition::create(BlockDevice& device, MinorNumber minor_number, Partition::DiskPartitionMetadata metadata)
|
||||
NonnullLockRefPtr<StorageDevicePartition> StorageDevicePartition::create(StorageDevice& device, MinorNumber minor_number, Partition::DiskPartitionMetadata metadata)
|
||||
{
|
||||
auto partition_or_error = DeviceManagement::try_create_device<StorageDevicePartition>(device, minor_number, metadata);
|
||||
// FIXME: Find a way to propagate errors
|
||||
|
@ -19,7 +20,7 @@ NonnullLockRefPtr<StorageDevicePartition> StorageDevicePartition::create(BlockDe
|
|||
return partition_or_error.release_value();
|
||||
}
|
||||
|
||||
StorageDevicePartition::StorageDevicePartition(BlockDevice& device, MinorNumber minor_number, Partition::DiskPartitionMetadata metadata)
|
||||
StorageDevicePartition::StorageDevicePartition(StorageDevice& device, MinorNumber minor_number, Partition::DiskPartitionMetadata metadata)
|
||||
: BlockDevice(100, minor_number, device.block_size())
|
||||
, m_device(device)
|
||||
, m_metadata(metadata)
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class StorageDevice;
|
||||
class StorageDevicePartition final : public BlockDevice {
|
||||
friend class DeviceManagement;
|
||||
|
||||
public:
|
||||
static NonnullLockRefPtr<StorageDevicePartition> create(BlockDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
||||
static NonnullLockRefPtr<StorageDevicePartition> create(StorageDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
||||
virtual ~StorageDevicePartition();
|
||||
|
||||
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
||||
|
@ -35,10 +36,10 @@ public:
|
|||
Partition::DiskPartitionMetadata const& metadata() const;
|
||||
|
||||
private:
|
||||
StorageDevicePartition(BlockDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
||||
StorageDevicePartition(StorageDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
||||
virtual StringView class_name() const override;
|
||||
|
||||
LockWeakPtr<BlockDevice> m_device;
|
||||
LockWeakPtr<StorageDevice> m_device;
|
||||
Partition::DiskPartitionMetadata m_metadata;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue