2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2020-12-19 12:50:57 +02:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2018-10-16 14:17:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-08 02:17:26 +01:00
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2020-02-22 19:53:03 +02:00
|
|
|
#include <Kernel/Interrupts/IRQHandler.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <Kernel/Lock.h>
|
2020-12-26 16:53:30 +02:00
|
|
|
#include <Kernel/Storage/Partition/DiskPartition.h>
|
2020-12-19 12:50:57 +02:00
|
|
|
#include <Kernel/Storage/StorageController.h>
|
2019-09-04 11:04:50 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
class StorageDevice : public BlockDevice {
|
2020-12-26 16:53:30 +02:00
|
|
|
friend class StorageManagement;
|
2019-05-19 03:46:50 +02:00
|
|
|
AK_MAKE_ETERNAL
|
2019-07-08 06:16:52 +00:00
|
|
|
|
|
|
|
public:
|
2021-03-16 20:23:16 +01:00
|
|
|
virtual u64 max_addressable_block() const { return m_max_addressable_block; }
|
2018-10-16 14:17:43 +02:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
NonnullRefPtr<StorageController> controller() const;
|
2019-07-28 23:44:01 +10:00
|
|
|
|
2019-08-02 23:18:47 +10:00
|
|
|
// ^BlockDevice
|
2021-03-17 13:18:51 +01:00
|
|
|
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2020-04-10 19:44:42 +10:00
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override;
|
2021-03-17 13:18:51 +01:00
|
|
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
2020-04-10 19:44:42 +10:00
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override;
|
2019-08-02 23:18:47 +10:00
|
|
|
|
2020-12-25 19:01:19 +02:00
|
|
|
// ^Device
|
|
|
|
virtual mode_t required_mode() const override { return 0600; }
|
|
|
|
|
2018-10-16 14:17:43 +02:00
|
|
|
protected:
|
2021-03-16 20:23:16 +01:00
|
|
|
StorageDevice(const StorageController&, size_t, u64);
|
|
|
|
StorageDevice(const StorageController&, int, int, size_t, u64);
|
2018-11-10 15:15:31 +01:00
|
|
|
// ^DiskDevice
|
2018-11-15 15:36:35 +01:00
|
|
|
virtual const char* class_name() const override;
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2020-12-19 12:50:57 +02:00
|
|
|
private:
|
|
|
|
NonnullRefPtr<StorageController> m_storage_controller;
|
2020-12-26 16:53:30 +02:00
|
|
|
NonnullRefPtrVector<DiskPartition> m_partitions;
|
2021-03-16 20:23:16 +01:00
|
|
|
u64 m_max_addressable_block;
|
2018-10-16 14:17:43 +02:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|