2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-06-02 18:58:59 +10:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-08 02:17:26 +01:00
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2022-08-19 20:53:40 +02:00
|
|
|
#include <Kernel/Library/LockRefPtr.h>
|
|
|
|
#include <Kernel/Library/LockWeakPtr.h>
|
2022-02-12 14:21:28 -05:00
|
|
|
#include <LibPartition/DiskPartitionMetadata.h>
|
2019-06-02 18:58:59 +10:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-02-08 02:17:26 +01:00
|
|
|
class DiskPartition final : public BlockDevice {
|
2021-09-11 09:19:20 +03:00
|
|
|
friend class DeviceManagement;
|
|
|
|
|
2019-06-02 18:58:59 +10:00
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static NonnullLockRefPtr<DiskPartition> create(BlockDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
2019-06-02 19:38:37 +10:00
|
|
|
virtual ~DiskPartition();
|
2019-06-02 18:58:59 +10:00
|
|
|
|
2020-11-02 11:16:01 -07:00
|
|
|
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
2019-06-02 18:58:59 +10:00
|
|
|
|
2019-08-02 23:18:47 +10:00
|
|
|
// ^BlockDevice
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override;
|
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override;
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override;
|
2019-08-02 23:18:47 +10:00
|
|
|
|
2022-02-12 14:21:28 -05:00
|
|
|
Partition::DiskPartitionMetadata const& metadata() const;
|
2020-12-31 13:17:03 +02:00
|
|
|
|
2019-06-02 18:58:59 +10:00
|
|
|
private:
|
2022-07-23 11:15:35 +03:00
|
|
|
DiskPartition(BlockDevice&, MinorNumber, Partition::DiskPartitionMetadata);
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView class_name() const override;
|
2019-06-02 18:58:59 +10:00
|
|
|
|
2022-08-19 20:53:40 +02:00
|
|
|
LockWeakPtr<BlockDevice> m_device;
|
2022-02-12 14:21:28 -05:00
|
|
|
Partition::DiskPartitionMetadata m_metadata;
|
2019-06-02 18:58:59 +10:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|