2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2020-12-19 07:50:57 -03:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2018-10-16 09:17:43 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-08-27 02:08:43 -03:00
|
|
|
#include <AK/IntrusiveList.h>
|
2020-02-07 22:17:26 -03:00
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2020-02-22 14:53:03 -03:00
|
|
|
#include <Kernel/Interrupts/IRQHandler.h>
|
2021-07-18 04:10:27 -03:00
|
|
|
#include <Kernel/Locking/Mutex.h>
|
2020-12-26 11:53:30 -03:00
|
|
|
#include <Kernel/Storage/Partition/DiskPartition.h>
|
2020-12-19 07:50:57 -03:00
|
|
|
#include <Kernel/Storage/StorageController.h>
|
2019-09-04 06:04:50 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2020-12-19 07:50:57 -03:00
|
|
|
class StorageDevice : public BlockDevice {
|
2020-12-26 11:53:30 -03:00
|
|
|
friend class StorageManagement;
|
2019-07-08 03:16:52 -03:00
|
|
|
|
|
|
|
|
public:
|
2021-03-16 16:23:16 -03:00
|
|
|
virtual u64 max_addressable_block() const { return m_max_addressable_block; }
|
2018-10-16 09:17:43 -03:00
|
|
|
|
2020-12-19 07:50:57 -03:00
|
|
|
NonnullRefPtr<StorageController> controller() const;
|
2019-07-28 10:44:01 -03:00
|
|
|
|
2019-08-02 10:18:47 -03:00
|
|
|
// ^BlockDevice
|
2021-09-07 08:39:11 -03:00
|
|
|
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;
|
2019-08-02 10:18:47 -03:00
|
|
|
|
2021-08-14 01:01:19 -03:00
|
|
|
// FIXME: This is being used only during early boot, find a better way to find devices...
|
|
|
|
|
virtual String storage_name() const = 0;
|
2020-12-25 14:01:19 -03:00
|
|
|
|
2021-08-27 02:08:43 -03:00
|
|
|
virtual void prepare_for_unplug() { m_partitions.clear(); }
|
|
|
|
|
|
|
|
|
|
NonnullRefPtrVector<DiskPartition> partitions() const { return m_partitions; }
|
|
|
|
|
|
2018-10-16 09:17:43 -03:00
|
|
|
protected:
|
2021-03-16 16:23:16 -03:00
|
|
|
StorageDevice(const StorageController&, size_t, u64);
|
|
|
|
|
StorageDevice(const StorageController&, int, int, size_t, u64);
|
2018-11-10 12:15:31 -02:00
|
|
|
// ^DiskDevice
|
2021-07-10 20:46:09 -03:00
|
|
|
virtual StringView class_name() const override;
|
2018-11-10 12:15:31 -02:00
|
|
|
|
2020-12-19 07:50:57 -03:00
|
|
|
private:
|
2021-08-27 02:08:43 -03:00
|
|
|
mutable IntrusiveListNode<StorageDevice, RefPtr<StorageDevice>> m_list_node;
|
2020-12-19 07:50:57 -03:00
|
|
|
NonnullRefPtr<StorageController> m_storage_controller;
|
2020-12-26 11:53:30 -03:00
|
|
|
NonnullRefPtrVector<DiskPartition> m_partitions;
|
2021-03-16 16:23:16 -03:00
|
|
|
u64 m_max_addressable_block;
|
2018-10-16 09:17:43 -03:00
|
|
|
};
|
2020-02-15 21:27:42 -03:00
|
|
|
|
|
|
|
|
}
|