mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-02 22:55:23 +00:00
This is really a basic support for AHCI hotplug events, so we know how to add a node representing the device in /sys/dev/block and removing it according to the event type (insertion/removal). This change doesn't take into account what happens if the device was mounted or a read/write operation is being handled. For this to work correctly, StorageManagement now uses the Singleton container, as it might be accessed simultaneously from many CPUs for hotplug events. DiskPartition holds a WeakPtr instead of a RefPtr, to allow removal of a StorageDevice object from the heap. StorageDevices are now stored and being referenced to via an IntrusiveList to make it easier to remove them on hotplug event. In future changes, all of the stated above might change, but for now, this commit represents the least amount of changes to make everything to work correctly.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/WeakPtr.h>
|
|
#include <Kernel/Devices/BlockDevice.h>
|
|
#include <Kernel/Storage/Partition/DiskPartitionMetadata.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class DiskPartition final : public BlockDevice {
|
|
public:
|
|
static NonnullRefPtr<DiskPartition> create(BlockDevice&, unsigned, DiskPartitionMetadata);
|
|
virtual ~DiskPartition();
|
|
|
|
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
|
|
|
// ^BlockDevice
|
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
virtual bool can_read(const OpenFileDescription&, size_t) const override;
|
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
|
virtual bool can_write(const OpenFileDescription&, size_t) const override;
|
|
|
|
const DiskPartitionMetadata& metadata() const;
|
|
|
|
private:
|
|
virtual StringView class_name() const override;
|
|
|
|
DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
|
|
|
|
WeakPtr<BlockDevice> m_device;
|
|
DiskPartitionMetadata m_metadata;
|
|
};
|
|
|
|
}
|