mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
Kernel: Merge unnecessary DiskDevice class into BlockDevice
This commit is contained in:
parent
6be880bd10
commit
88ea152b24
Notes:
sideshowbarker
2024-07-19 09:32:16 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/88ea152b242
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <Kernel/ACPI/ACPIStaticParser.h>
|
#include <Kernel/ACPI/ACPIStaticParser.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
|
||||||
#include <Kernel/IRQHandler.h>
|
#include <Kernel/IRQHandler.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
#include <Kernel/VM/PhysicalAddress.h>
|
#include <Kernel/VM/PhysicalAddress.h>
|
||||||
@ -56,4 +55,4 @@ private:
|
|||||||
virtual void handle_irq() override;
|
virtual void handle_irq() override;
|
||||||
|
|
||||||
OwnPtr<Region> m_acpi_namespace;
|
OwnPtr<Region> m_acpi_namespace;
|
||||||
};
|
};
|
||||||
|
@ -47,6 +47,8 @@ private:
|
|||||||
virtual bool can_write(const FileDescription&) const override { return true; }
|
virtual bool can_write(const FileDescription&) const override { return true; }
|
||||||
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return -EINVAL; }
|
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return -EINVAL; }
|
||||||
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return -EINVAL; }
|
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return -EINVAL; }
|
||||||
|
virtual bool read_blocks(unsigned, u16, u8*) override { return false; }
|
||||||
|
virtual bool write_blocks(unsigned, u16, const u8*) override { return false; }
|
||||||
|
|
||||||
void set_register(u16 index, u16 value);
|
void set_register(u16 index, u16 value);
|
||||||
u32 find_framebuffer_address();
|
u32 find_framebuffer_address();
|
||||||
|
@ -29,3 +29,33 @@
|
|||||||
BlockDevice::~BlockDevice()
|
BlockDevice::~BlockDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BlockDevice::read_block(unsigned index, u8* buffer) const
|
||||||
|
{
|
||||||
|
return const_cast<BlockDevice*>(this)->read_blocks(index, 1, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BlockDevice::write_block(unsigned index, const u8* data)
|
||||||
|
{
|
||||||
|
return write_blocks(index, 1, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BlockDevice::read_raw(u32 offset, unsigned length, u8* out) const
|
||||||
|
{
|
||||||
|
ASSERT((offset % block_size()) == 0);
|
||||||
|
ASSERT((length % block_size()) == 0);
|
||||||
|
u32 first_block = offset / block_size();
|
||||||
|
u32 end_block = (offset + length) / block_size();
|
||||||
|
return const_cast<BlockDevice*>(this)->read_blocks(first_block, end_block - first_block, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BlockDevice::write_raw(u32 offset, unsigned length, const u8* in)
|
||||||
|
{
|
||||||
|
ASSERT((offset % block_size()) == 0);
|
||||||
|
ASSERT((length % block_size()) == 0);
|
||||||
|
u32 first_block = offset / block_size();
|
||||||
|
u32 end_block = (offset + length) / block_size();
|
||||||
|
ASSERT(first_block <= 0xffffffff);
|
||||||
|
ASSERT(end_block <= 0xffffffff);
|
||||||
|
return write_blocks(first_block, end_block - first_block, in);
|
||||||
|
}
|
||||||
|
@ -35,6 +35,14 @@ public:
|
|||||||
size_t block_size() const { return m_block_size; }
|
size_t block_size() const { return m_block_size; }
|
||||||
virtual bool is_seekable() const override { return true; }
|
virtual bool is_seekable() const override { return true; }
|
||||||
|
|
||||||
|
bool read_block(unsigned index, u8*) const;
|
||||||
|
bool write_block(unsigned index, const u8*);
|
||||||
|
bool read_raw(u32 offset, unsigned length, u8*) const;
|
||||||
|
bool write_raw(u32 offset, unsigned length, const u8*);
|
||||||
|
|
||||||
|
virtual bool read_blocks(unsigned index, u16 count, u8*) = 0;
|
||||||
|
virtual bool write_blocks(unsigned index, u16 count, const u8*) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BlockDevice(unsigned major, unsigned minor, size_t block_size = PAGE_SIZE)
|
BlockDevice(unsigned major, unsigned minor, size_t block_size = PAGE_SIZE)
|
||||||
: Device(major, minor)
|
: Device(major, minor)
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
|
||||||
|
|
||||||
DiskDevice::DiskDevice(int major, int minor, size_t block_size)
|
|
||||||
: BlockDevice(major, minor, block_size)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DiskDevice::~DiskDevice()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiskDevice::read(DiskOffset offset, unsigned length, u8* out) const
|
|
||||||
{
|
|
||||||
ASSERT((offset % block_size()) == 0);
|
|
||||||
ASSERT((length % block_size()) == 0);
|
|
||||||
u32 first_block = offset / block_size();
|
|
||||||
u32 end_block = (offset + length) / block_size();
|
|
||||||
return const_cast<DiskDevice*>(this)->read_blocks(first_block, end_block - first_block, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiskDevice::write(DiskOffset offset, unsigned length, const u8* in)
|
|
||||||
{
|
|
||||||
ASSERT((offset % block_size()) == 0);
|
|
||||||
ASSERT((length % block_size()) == 0);
|
|
||||||
u32 first_block = offset / block_size();
|
|
||||||
u32 end_block = (offset + length) / block_size();
|
|
||||||
ASSERT(first_block <= 0xffffffff);
|
|
||||||
ASSERT(end_block <= 0xffffffff);
|
|
||||||
return write_blocks(first_block, end_block - first_block, in);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
|
||||||
#include <AK/Types.h>
|
|
||||||
#include <Kernel/Devices/BlockDevice.h>
|
|
||||||
|
|
||||||
// FIXME: Support 64-bit DiskOffset
|
|
||||||
typedef u32 DiskOffset;
|
|
||||||
|
|
||||||
class DiskDevice : public BlockDevice {
|
|
||||||
public:
|
|
||||||
virtual ~DiskDevice() override;
|
|
||||||
|
|
||||||
virtual bool read_block(unsigned index, u8*) const = 0;
|
|
||||||
virtual bool write_block(unsigned index, const u8*) = 0;
|
|
||||||
bool read(DiskOffset, unsigned length, u8*) const;
|
|
||||||
bool write(DiskOffset, unsigned length, const u8*);
|
|
||||||
|
|
||||||
virtual bool read_blocks(unsigned index, u16 count, u8*) = 0;
|
|
||||||
virtual bool write_blocks(unsigned index, u16 count, const u8*) = 0;
|
|
||||||
|
|
||||||
virtual bool is_disk_device() const override { return true; };
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DiskDevice(int major, int minor, size_t block_size = 512);
|
|
||||||
};
|
|
@ -28,13 +28,13 @@
|
|||||||
|
|
||||||
// #define OFFD_DEBUG
|
// #define OFFD_DEBUG
|
||||||
|
|
||||||
NonnullRefPtr<DiskPartition> DiskPartition::create(DiskDevice& device, unsigned block_offset, unsigned block_limit)
|
NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned block_offset, unsigned block_limit)
|
||||||
{
|
{
|
||||||
return adopt(*new DiskPartition(device, block_offset, block_limit));
|
return adopt(*new DiskPartition(device, block_offset, block_limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskPartition::DiskPartition(DiskDevice& device, unsigned block_offset, unsigned block_limit)
|
DiskPartition::DiskPartition(BlockDevice& device, unsigned block_offset, unsigned block_limit)
|
||||||
: DiskDevice(100, 0, device.block_size())
|
: BlockDevice(100, 0, device.block_size())
|
||||||
, m_device(device)
|
, m_device(device)
|
||||||
, m_block_offset(block_offset)
|
, m_block_offset(block_offset)
|
||||||
, m_block_limit(block_limit)
|
, m_block_limit(block_limit)
|
||||||
@ -45,24 +45,6 @@ DiskPartition::~DiskPartition()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DiskPartition::read_block(unsigned index, u8* out) const
|
|
||||||
{
|
|
||||||
#ifdef OFFD_DEBUG
|
|
||||||
kprintf("DiskPartition::read_block %u (really: %u)\n", index, m_block_offset + index);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_device->read_block(m_block_offset + index, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiskPartition::write_block(unsigned index, const u8* data)
|
|
||||||
{
|
|
||||||
#ifdef OFFD_DEBUG
|
|
||||||
kprintf("DiskPartition::write_block %u (really: %u)\n", index, m_block_offset + index);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return m_device->write_block(m_block_offset + index, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiskPartition::read_blocks(unsigned index, u16 count, u8* out)
|
bool DiskPartition::read_blocks(unsigned index, u16 count, u8* out)
|
||||||
{
|
{
|
||||||
#ifdef OFFD_DEBUG
|
#ifdef OFFD_DEBUG
|
||||||
|
@ -27,15 +27,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
#include <Kernel/Devices/BlockDevice.h>
|
||||||
|
|
||||||
class DiskPartition final : public DiskDevice {
|
class DiskPartition final : public BlockDevice {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<DiskPartition> create(DiskDevice&, unsigned block_offset, unsigned block_limit);
|
static NonnullRefPtr<DiskPartition> create(BlockDevice&, unsigned block_offset, unsigned block_limit);
|
||||||
virtual ~DiskPartition();
|
virtual ~DiskPartition();
|
||||||
|
|
||||||
virtual bool read_block(unsigned index, u8* out) const override;
|
|
||||||
virtual bool write_block(unsigned index, const u8*) override;
|
|
||||||
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
||||||
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
||||||
|
|
||||||
@ -48,9 +46,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override;
|
virtual const char* class_name() const override;
|
||||||
|
|
||||||
DiskPartition(DiskDevice&, unsigned block_offset, unsigned block_limit);
|
DiskPartition(BlockDevice&, unsigned block_offset, unsigned block_limit);
|
||||||
|
|
||||||
NonnullRefPtr<DiskDevice> m_device;
|
NonnullRefPtr<BlockDevice> m_device;
|
||||||
unsigned m_block_offset;
|
unsigned m_block_offset;
|
||||||
unsigned m_block_limit;
|
unsigned m_block_limit;
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define EBR_DEBUG
|
#define EBR_DEBUG
|
||||||
|
|
||||||
EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<DiskDevice> device)
|
EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<BlockDevice> device)
|
||||||
: m_device(move(device))
|
: m_device(move(device))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
|
||||||
#include <Kernel/Devices/DiskPartition.h>
|
#include <Kernel/Devices/DiskPartition.h>
|
||||||
#include <Kernel/Devices/MBRPartitionTable.h>
|
#include <Kernel/Devices/MBRPartitionTable.h>
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ struct [[gnu::packed]] EBRPartitionExtension
|
|||||||
class EBRPartitionTable {
|
class EBRPartitionTable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EBRPartitionTable(NonnullRefPtr<DiskDevice>);
|
explicit EBRPartitionTable(NonnullRefPtr<BlockDevice>);
|
||||||
~EBRPartitionTable();
|
~EBRPartitionTable();
|
||||||
|
|
||||||
bool initialize();
|
bool initialize();
|
||||||
@ -52,7 +51,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int index_of_ebr_container() const;
|
int index_of_ebr_container() const;
|
||||||
NonnullRefPtr<DiskDevice> m_device;
|
NonnullRefPtr<BlockDevice> m_device;
|
||||||
|
|
||||||
const MBRPartitionHeader& header() const;
|
const MBRPartitionHeader& header() const;
|
||||||
const EBRPartitionExtension& ebr_extension() const;
|
const EBRPartitionExtension& ebr_extension() const;
|
||||||
|
@ -110,7 +110,7 @@ const char* FloppyDiskDevice::class_name() const
|
|||||||
|
|
||||||
FloppyDiskDevice::FloppyDiskDevice(FloppyDiskDevice::DriveType type)
|
FloppyDiskDevice::FloppyDiskDevice(FloppyDiskDevice::DriveType type)
|
||||||
: IRQHandler(IRQ_FLOPPY_DRIVE)
|
: IRQHandler(IRQ_FLOPPY_DRIVE)
|
||||||
, DiskDevice(89, (type == FloppyDiskDevice::DriveType::Master) ? 0 : 1, BYTES_PER_SECTOR)
|
, BlockDevice(89, (type == FloppyDiskDevice::DriveType::Master) ? 0 : 1, BYTES_PER_SECTOR)
|
||||||
, m_io_base_addr((type == FloppyDiskDevice::DriveType::Master) ? 0x3F0 : 0x370)
|
, m_io_base_addr((type == FloppyDiskDevice::DriveType::Master) ? 0x3F0 : 0x370)
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
@ -120,16 +120,6 @@ FloppyDiskDevice::~FloppyDiskDevice()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloppyDiskDevice::read_block(unsigned index, u8* data) const
|
|
||||||
{
|
|
||||||
return const_cast<FloppyDiskDevice*>(this)->read_blocks(index, 1, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FloppyDiskDevice::write_block(unsigned index, const u8* data)
|
|
||||||
{
|
|
||||||
return write_sectors_with_dma(index, 1, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FloppyDiskDevice::read_blocks(unsigned index, u16 count, u8* data)
|
bool FloppyDiskDevice::read_blocks(unsigned index, u16 count, u8* data)
|
||||||
{
|
{
|
||||||
return read_sectors_with_dma(index, count, data);
|
return read_sectors_with_dma(index, count, data);
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
#include <Kernel/Devices/BlockDevice.h>
|
||||||
#include <Kernel/IRQHandler.h>
|
#include <Kernel/IRQHandler.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
#include <Kernel/VM/PhysicalAddress.h>
|
#include <Kernel/VM/PhysicalAddress.h>
|
||||||
@ -120,8 +120,9 @@ struct FloppyControllerCommand {
|
|||||||
// uses the Intel 82077A controller. More about this controller can
|
// uses the Intel 82077A controller. More about this controller can
|
||||||
// be found here: http://www.buchty.net/casio/files/82077.pdf
|
// be found here: http://www.buchty.net/casio/files/82077.pdf
|
||||||
//
|
//
|
||||||
class FloppyDiskDevice final : public IRQHandler
|
class FloppyDiskDevice final
|
||||||
, public DiskDevice {
|
: public IRQHandler
|
||||||
|
, public BlockDevice {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
|
|
||||||
static constexpr u8 SECTORS_PER_CYLINDER = 18;
|
static constexpr u8 SECTORS_PER_CYLINDER = 18;
|
||||||
@ -160,8 +161,6 @@ public:
|
|||||||
virtual ~FloppyDiskDevice() override;
|
virtual ~FloppyDiskDevice() override;
|
||||||
|
|
||||||
// ^DiskDevice
|
// ^DiskDevice
|
||||||
virtual bool read_block(unsigned index, u8*) const override;
|
|
||||||
virtual bool write_block(unsigned index, const u8*) override;
|
|
||||||
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
||||||
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define GPT_DEBUG
|
#define GPT_DEBUG
|
||||||
|
|
||||||
GPTPartitionTable::GPTPartitionTable(DiskDevice& device)
|
GPTPartitionTable::GPTPartitionTable(BlockDevice& device)
|
||||||
: m_device(move(device))
|
: m_device(move(device))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
|
||||||
#include <Kernel/Devices/DiskPartition.h>
|
#include <Kernel/Devices/DiskPartition.h>
|
||||||
|
|
||||||
#define GPT_SIGNATURE2 0x54524150
|
#define GPT_SIGNATURE2 0x54524150
|
||||||
@ -73,14 +72,14 @@ struct [[gnu::packed]] GPTPartitionHeader
|
|||||||
class GPTPartitionTable {
|
class GPTPartitionTable {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GPTPartitionTable(DiskDevice&);
|
explicit GPTPartitionTable(BlockDevice&);
|
||||||
~GPTPartitionTable();
|
~GPTPartitionTable();
|
||||||
|
|
||||||
bool initialize();
|
bool initialize();
|
||||||
RefPtr<DiskPartition> partition(unsigned index);
|
RefPtr<DiskPartition> partition(unsigned index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<DiskDevice> m_device;
|
NonnullRefPtr<BlockDevice> m_device;
|
||||||
|
|
||||||
const GPTPartitionHeader& header() const;
|
const GPTPartitionHeader& header() const;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#define MBR_DEBUG
|
#define MBR_DEBUG
|
||||||
|
|
||||||
MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<DiskDevice> device)
|
MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<BlockDevice> device)
|
||||||
: m_device(move(device))
|
: m_device(move(device))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
|
||||||
#include <Kernel/Devices/DiskPartition.h>
|
#include <Kernel/Devices/DiskPartition.h>
|
||||||
|
|
||||||
#define MBR_SIGNATURE 0xaa55
|
#define MBR_SIGNATURE 0xaa55
|
||||||
@ -62,7 +61,7 @@ class MBRPartitionTable {
|
|||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MBRPartitionTable(NonnullRefPtr<DiskDevice>);
|
explicit MBRPartitionTable(NonnullRefPtr<BlockDevice>);
|
||||||
~MBRPartitionTable();
|
~MBRPartitionTable();
|
||||||
|
|
||||||
bool initialize();
|
bool initialize();
|
||||||
@ -71,7 +70,7 @@ public:
|
|||||||
RefPtr<DiskPartition> partition(unsigned index);
|
RefPtr<DiskPartition> partition(unsigned index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<DiskDevice> m_device;
|
NonnullRefPtr<BlockDevice> m_device;
|
||||||
|
|
||||||
const MBRPartitionHeader& header() const;
|
const MBRPartitionHeader& header() const;
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ private:
|
|||||||
virtual bool can_write(const FileDescription&) const override { return true; }
|
virtual bool can_write(const FileDescription&) const override { return true; }
|
||||||
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return -EINVAL; }
|
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return -EINVAL; }
|
||||||
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return -EINVAL; }
|
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return -EINVAL; }
|
||||||
|
virtual bool read_blocks(unsigned, u16, u8*) override { return false; }
|
||||||
|
virtual bool write_blocks(unsigned, u16, const u8*) override { return false; }
|
||||||
|
|
||||||
size_t framebuffer_size_in_bytes() const { return m_framebuffer_pitch * m_framebuffer_height; }
|
size_t framebuffer_size_in_bytes() const { return m_framebuffer_pitch * m_framebuffer_height; }
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(PATAChannel& channel, Drive
|
|||||||
}
|
}
|
||||||
|
|
||||||
PATADiskDevice::PATADiskDevice(PATAChannel& channel, DriveType type, int major, int minor)
|
PATADiskDevice::PATADiskDevice(PATAChannel& channel, DriveType type, int major, int minor)
|
||||||
: DiskDevice(major, minor)
|
: BlockDevice(major, minor, 512)
|
||||||
, m_drive_type(type)
|
, m_drive_type(type)
|
||||||
, m_channel(channel)
|
, m_channel(channel)
|
||||||
{
|
{
|
||||||
@ -55,11 +55,6 @@ bool PATADiskDevice::read_blocks(unsigned index, u16 count, u8* out)
|
|||||||
return read_sectors(index, count, out);
|
return read_sectors(index, count, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PATADiskDevice::read_block(unsigned index, u8* out) const
|
|
||||||
{
|
|
||||||
return const_cast<PATADiskDevice*>(this)->read_blocks(index, 1, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PATADiskDevice::write_blocks(unsigned index, u16 count, const u8* data)
|
bool PATADiskDevice::write_blocks(unsigned index, u16 count, const u8* data)
|
||||||
{
|
{
|
||||||
if (m_channel.m_bus_master_base && m_channel.m_dma_enabled.resource())
|
if (m_channel.m_bus_master_base && m_channel.m_dma_enabled.resource())
|
||||||
@ -71,11 +66,6 @@ bool PATADiskDevice::write_blocks(unsigned index, u16 count, const u8* data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PATADiskDevice::write_block(unsigned index, const u8* data)
|
|
||||||
{
|
|
||||||
return write_blocks(index, 1, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PATADiskDevice::set_drive_geometry(u16 cyls, u16 heads, u16 spt)
|
void PATADiskDevice::set_drive_geometry(u16 cyls, u16 heads, u16 spt)
|
||||||
{
|
{
|
||||||
m_cylinders = cyls;
|
m_cylinders = cyls;
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
#include <Kernel/Devices/BlockDevice.h>
|
||||||
#include <Kernel/IRQHandler.h>
|
#include <Kernel/IRQHandler.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
|
|
||||||
class PATAChannel;
|
class PATAChannel;
|
||||||
|
|
||||||
class PATADiskDevice final : public DiskDevice {
|
class PATADiskDevice final : public BlockDevice {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
public:
|
public:
|
||||||
// Type of drive this IDEDiskDevice is on the ATA channel.
|
// Type of drive this IDEDiskDevice is on the ATA channel.
|
||||||
@ -53,8 +53,6 @@ public:
|
|||||||
virtual ~PATADiskDevice() override;
|
virtual ~PATADiskDevice() override;
|
||||||
|
|
||||||
// ^DiskDevice
|
// ^DiskDevice
|
||||||
virtual bool read_block(unsigned index, u8*) const override;
|
|
||||||
virtual bool write_block(unsigned index, const u8*) override;
|
|
||||||
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
|
||||||
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ private:
|
|||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
DiskBackedFS::DiskBackedFS(NonnullRefPtr<DiskDevice>&& device)
|
DiskBackedFS::DiskBackedFS(BlockDevice& device)
|
||||||
: m_device(move(device))
|
: m_device(device)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +129,8 @@ bool DiskBackedFS::write_block(unsigned index, const u8* data, FileDescription*
|
|||||||
|
|
||||||
if (!allow_cache) {
|
if (!allow_cache) {
|
||||||
flush_specific_block_if_needed(index);
|
flush_specific_block_if_needed(index);
|
||||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
|
||||||
device().write(base_offset, block_size(), data);
|
device().write_raw(base_offset, block_size(), data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,16 +163,16 @@ bool DiskBackedFS::read_block(unsigned index, u8* buffer, FileDescription* descr
|
|||||||
|
|
||||||
if (!allow_cache) {
|
if (!allow_cache) {
|
||||||
const_cast<DiskBackedFS*>(this)->flush_specific_block_if_needed(index);
|
const_cast<DiskBackedFS*>(this)->flush_specific_block_if_needed(index);
|
||||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
|
||||||
bool success = device().read(base_offset, block_size(), buffer);
|
bool success = device().read_raw(base_offset, block_size(), buffer);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& entry = cache().get(index);
|
auto& entry = cache().get(index);
|
||||||
if (!entry.has_data) {
|
if (!entry.has_data) {
|
||||||
DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
|
u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
|
||||||
bool success = device().read(base_offset, block_size(), entry.data);
|
bool success = device().read_raw(base_offset, block_size(), entry.data);
|
||||||
entry.has_data = true;
|
entry.has_data = true;
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
}
|
}
|
||||||
@ -204,8 +204,8 @@ void DiskBackedFS::flush_specific_block_if_needed(unsigned index)
|
|||||||
return;
|
return;
|
||||||
cache().for_each_entry([&](CacheEntry& entry) {
|
cache().for_each_entry([&](CacheEntry& entry) {
|
||||||
if (entry.is_dirty && entry.block_index == index) {
|
if (entry.is_dirty && entry.block_index == index) {
|
||||||
DiskOffset base_offset = static_cast<DiskOffset>(entry.block_index) * static_cast<DiskOffset>(block_size());
|
u32 base_offset = static_cast<u32>(entry.block_index) * static_cast<u32>(block_size());
|
||||||
device().write(base_offset, block_size(), entry.data);
|
device().write_raw(base_offset, block_size(), entry.data);
|
||||||
entry.is_dirty = false;
|
entry.is_dirty = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -220,8 +220,8 @@ void DiskBackedFS::flush_writes_impl()
|
|||||||
cache().for_each_entry([&](CacheEntry& entry) {
|
cache().for_each_entry([&](CacheEntry& entry) {
|
||||||
if (!entry.is_dirty)
|
if (!entry.is_dirty)
|
||||||
return;
|
return;
|
||||||
DiskOffset base_offset = static_cast<DiskOffset>(entry.block_index) * static_cast<DiskOffset>(block_size());
|
u32 base_offset = static_cast<u32>(entry.block_index) * static_cast<u32>(block_size());
|
||||||
device().write(base_offset, block_size(), entry.data);
|
device().write_raw(base_offset, block_size(), entry.data);
|
||||||
++count;
|
++count;
|
||||||
entry.is_dirty = false;
|
entry.is_dirty = false;
|
||||||
});
|
});
|
||||||
|
@ -37,15 +37,15 @@ public:
|
|||||||
|
|
||||||
virtual bool is_disk_backed() const override { return true; }
|
virtual bool is_disk_backed() const override { return true; }
|
||||||
|
|
||||||
DiskDevice& device() { return *m_device; }
|
BlockDevice& device() { return *m_device; }
|
||||||
const DiskDevice& device() const { return *m_device; }
|
const BlockDevice& device() const { return *m_device; }
|
||||||
|
|
||||||
virtual void flush_writes() override;
|
virtual void flush_writes() override;
|
||||||
|
|
||||||
void flush_writes_impl();
|
void flush_writes_impl();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
|
explicit DiskBackedFS(BlockDevice&);
|
||||||
|
|
||||||
bool read_block(unsigned index, u8* buffer, FileDescription* = nullptr) const;
|
bool read_block(unsigned index, u8* buffer, FileDescription* = nullptr) const;
|
||||||
bool read_blocks(unsigned index, unsigned count, u8* buffer, FileDescription* = nullptr) const;
|
bool read_blocks(unsigned index, unsigned count, u8* buffer, FileDescription* = nullptr) const;
|
||||||
@ -57,6 +57,6 @@ private:
|
|||||||
DiskCache& cache() const;
|
DiskCache& cache() const;
|
||||||
void flush_specific_block_if_needed(unsigned index);
|
void flush_specific_block_if_needed(unsigned index);
|
||||||
|
|
||||||
NonnullRefPtr<DiskDevice> m_device;
|
NonnullRefPtr<BlockDevice> m_device;
|
||||||
mutable OwnPtr<DiskCache> m_cache;
|
mutable OwnPtr<DiskCache> m_cache;
|
||||||
};
|
};
|
||||||
|
@ -58,13 +58,13 @@ static u8 to_ext2_file_type(mode_t mode)
|
|||||||
return EXT2_FT_UNKNOWN;
|
return EXT2_FT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<Ext2FS> Ext2FS::create(NonnullRefPtr<DiskDevice> device)
|
NonnullRefPtr<Ext2FS> Ext2FS::create(BlockDevice& device)
|
||||||
{
|
{
|
||||||
return adopt(*new Ext2FS(move(device)));
|
return adopt(*new Ext2FS(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ext2FS::Ext2FS(NonnullRefPtr<DiskDevice>&& device)
|
Ext2FS::Ext2FS(BlockDevice& device)
|
||||||
: DiskBackedFS(move(device))
|
: DiskBackedFS(device)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
|
|||||||
bool Ext2FS::initialize()
|
bool Ext2FS::initialize()
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
bool success = const_cast<DiskDevice&>(device()).read_blocks(2, 1, (u8*)&m_super_block);
|
bool success = const_cast<BlockDevice&>(device()).read_blocks(2, 1, (u8*)&m_super_block);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
|
|
||||||
auto& super_block = this->super_block();
|
auto& super_block = this->super_block();
|
||||||
|
@ -89,7 +89,7 @@ class Ext2FS final : public DiskBackedFS {
|
|||||||
friend class Ext2FSInode;
|
friend class Ext2FSInode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<Ext2FS> create(NonnullRefPtr<DiskDevice>);
|
static NonnullRefPtr<Ext2FS> create(BlockDevice&);
|
||||||
virtual ~Ext2FS() override;
|
virtual ~Ext2FS() override;
|
||||||
virtual bool initialize() override;
|
virtual bool initialize() override;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ private:
|
|||||||
typedef unsigned BlockIndex;
|
typedef unsigned BlockIndex;
|
||||||
typedef unsigned GroupIndex;
|
typedef unsigned GroupIndex;
|
||||||
typedef unsigned InodeIndex;
|
typedef unsigned InodeIndex;
|
||||||
explicit Ext2FS(NonnullRefPtr<DiskDevice>&&);
|
explicit Ext2FS(BlockDevice&);
|
||||||
|
|
||||||
const ext2_super_block& super_block() const { return m_super_block; }
|
const ext2_super_block& super_block() const { return m_super_block; }
|
||||||
const ext2_group_desc& group_descriptor(GroupIndex) const;
|
const ext2_group_desc& group_descriptor(GroupIndex) const;
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
#include <Kernel/Devices/DiskDevice.h>
|
#include <Kernel/Devices/BlockDevice.h>
|
||||||
#include <Kernel/FileSystem/InodeIdentifier.h>
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
||||||
#include <Kernel/FileSystem/InodeMetadata.h>
|
#include <Kernel/FileSystem/InodeMetadata.h>
|
||||||
#include <Kernel/KResult.h>
|
#include <Kernel/KResult.h>
|
||||||
|
@ -20,7 +20,6 @@ OBJS = \
|
|||||||
Devices/CharacterDevice.o \
|
Devices/CharacterDevice.o \
|
||||||
Devices/DebugLogDevice.o \
|
Devices/DebugLogDevice.o \
|
||||||
Devices/Device.o \
|
Devices/Device.o \
|
||||||
Devices/DiskDevice.o \
|
|
||||||
Devices/DiskPartition.o \
|
Devices/DiskPartition.o \
|
||||||
Devices/FloppyDiskDevice.o \
|
Devices/FloppyDiskDevice.o \
|
||||||
Devices/FullDevice.o \
|
Devices/FullDevice.o \
|
||||||
|
@ -3992,15 +3992,15 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params)
|
|||||||
return source_or_error.error();
|
return source_or_error.error();
|
||||||
|
|
||||||
auto* device = source_or_error.value()->device();
|
auto* device = source_or_error.value()->device();
|
||||||
if (!device || !device->is_disk_device()) {
|
if (!device || !device->is_block_device()) {
|
||||||
dbg() << "mount: this is not a DiskDevice";
|
dbg() << "mount: this is not a BlockDevice";
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
auto& disk_device = static_cast<DiskDevice&>(*device);
|
auto& block_device = static_cast<BlockDevice&>(*device);
|
||||||
|
|
||||||
dbg() << "mount: attempting to mount " << disk_device.absolute_path() << " on " << target;
|
dbg() << "mount: attempting to mount " << block_device.absolute_path() << " on " << target;
|
||||||
|
|
||||||
fs = Ext2FS::create(disk_device);
|
fs = Ext2FS::create(block_device);
|
||||||
} else if (fs_type == "proc" || fs_type == "ProcFS") {
|
} else if (fs_type == "proc" || fs_type == "ProcFS") {
|
||||||
fs = ProcFS::create();
|
fs = ProcFS::create();
|
||||||
} else if (fs_type == "devpts" || fs_type == "DevPtsFS") {
|
} else if (fs_type == "devpts" || fs_type == "DevPtsFS") {
|
||||||
|
@ -229,7 +229,7 @@ void init_stage2()
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto pata0 = PATAChannel::create(PATAChannel::ChannelType::Primary, force_pio);
|
auto pata0 = PATAChannel::create(PATAChannel::ChannelType::Primary, force_pio);
|
||||||
NonnullRefPtr<DiskDevice> root_dev = *pata0->master_device();
|
NonnullRefPtr<BlockDevice> root_dev = *pata0->master_device();
|
||||||
|
|
||||||
root = root.substring(strlen("/dev/hda"), root.length() - strlen("/dev/hda"));
|
root = root.substring(strlen("/dev/hda"), root.length() - strlen("/dev/hda"));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user