瀏覽代碼

Kernel: Merge unnecessary DiskDevice class into BlockDevice

Andreas Kling 5 年之前
父節點
當前提交
88ea152b24

+ 1 - 2
Kernel/ACPI/ACPIDynamicParser.h

@@ -28,7 +28,6 @@
 
 #include <AK/RefPtr.h>
 #include <Kernel/ACPI/ACPIStaticParser.h>
-#include <Kernel/Devices/DiskDevice.h>
 #include <Kernel/IRQHandler.h>
 #include <Kernel/Lock.h>
 #include <Kernel/VM/PhysicalAddress.h>
@@ -56,4 +55,4 @@ private:
     virtual void handle_irq() override;
 
     OwnPtr<Region> m_acpi_namespace;
-};
+};

+ 2 - 0
Kernel/Devices/BXVGADevice.h

@@ -47,6 +47,8 @@ private:
     virtual bool can_write(const FileDescription&) const override { return true; }
     virtual ssize_t read(FileDescription&, 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);
     u32 find_framebuffer_address();

+ 30 - 0
Kernel/Devices/BlockDevice.cpp

@@ -29,3 +29,33 @@
 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);
+}

+ 8 - 0
Kernel/Devices/BlockDevice.h

@@ -35,6 +35,14 @@ public:
     size_t block_size() const { return m_block_size; }
     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:
     BlockDevice(unsigned major, unsigned minor, size_t block_size = PAGE_SIZE)
         : Device(major, minor)

+ 0 - 56
Kernel/Devices/DiskDevice.cpp

@@ -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);
-}

+ 0 - 52
Kernel/Devices/DiskDevice.h

@@ -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);
-};

+ 3 - 21
Kernel/Devices/DiskPartition.cpp

@@ -28,13 +28,13 @@
 
 // #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));
 }
 
-DiskPartition::DiskPartition(DiskDevice& device, unsigned block_offset, unsigned block_limit)
-    : DiskDevice(100, 0, device.block_size())
+DiskPartition::DiskPartition(BlockDevice& device, unsigned block_offset, unsigned block_limit)
+    : BlockDevice(100, 0, device.block_size())
     , m_device(device)
     , m_block_offset(block_offset)
     , 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)
 {
 #ifdef OFFD_DEBUG

+ 5 - 7
Kernel/Devices/DiskPartition.h

@@ -27,15 +27,13 @@
 #pragma once
 
 #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:
-    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 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 write_blocks(unsigned index, u16 count, const u8*) override;
 
@@ -48,9 +46,9 @@ public:
 private:
     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_limit;
 };

+ 1 - 1
Kernel/Devices/EBRPartitionTable.cpp

@@ -29,7 +29,7 @@
 
 #define EBR_DEBUG
 
-EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<DiskDevice> device)
+EBRPartitionTable::EBRPartitionTable(NonnullRefPtr<BlockDevice> device)
     : m_device(move(device))
 {
 }

+ 2 - 3
Kernel/Devices/EBRPartitionTable.h

@@ -28,7 +28,6 @@
 
 #include <AK/RefPtr.h>
 #include <AK/Vector.h>
-#include <Kernel/Devices/DiskDevice.h>
 #include <Kernel/Devices/DiskPartition.h>
 #include <Kernel/Devices/MBRPartitionTable.h>
 
@@ -44,7 +43,7 @@ struct [[gnu::packed]] EBRPartitionExtension
 class EBRPartitionTable {
 
 public:
-    explicit EBRPartitionTable(NonnullRefPtr<DiskDevice>);
+    explicit EBRPartitionTable(NonnullRefPtr<BlockDevice>);
     ~EBRPartitionTable();
 
     bool initialize();
@@ -52,7 +51,7 @@ public:
 
 private:
     int index_of_ebr_container() const;
-    NonnullRefPtr<DiskDevice> m_device;
+    NonnullRefPtr<BlockDevice> m_device;
 
     const MBRPartitionHeader& header() const;
     const EBRPartitionExtension& ebr_extension() const;

+ 1 - 11
Kernel/Devices/FloppyDiskDevice.cpp

@@ -110,7 +110,7 @@ const char* FloppyDiskDevice::class_name() const
 
 FloppyDiskDevice::FloppyDiskDevice(FloppyDiskDevice::DriveType type)
     : 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)
 {
     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)
 {
     return read_sectors_with_dma(index, count, data);

+ 4 - 5
Kernel/Devices/FloppyDiskDevice.h

@@ -98,7 +98,7 @@
 #pragma once
 
 #include <AK/RefPtr.h>
-#include <Kernel/Devices/DiskDevice.h>
+#include <Kernel/Devices/BlockDevice.h>
 #include <Kernel/IRQHandler.h>
 #include <Kernel/Lock.h>
 #include <Kernel/VM/PhysicalAddress.h>
@@ -120,8 +120,9 @@ struct FloppyControllerCommand {
 // uses the Intel 82077A controller. More about this controller can
 // be found here: http://www.buchty.net/casio/files/82077.pdf
 //
-class FloppyDiskDevice final : public IRQHandler
-    , public DiskDevice {
+class FloppyDiskDevice final
+    : public IRQHandler
+    , public BlockDevice {
     AK_MAKE_ETERNAL
 
     static constexpr u8 SECTORS_PER_CYLINDER = 18;
@@ -160,8 +161,6 @@ public:
     virtual ~FloppyDiskDevice() override;
 
     // ^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 write_blocks(unsigned index, u16 count, const u8*) override;
 

+ 1 - 1
Kernel/Devices/GPTPartitionTable.cpp

@@ -29,7 +29,7 @@
 
 #define GPT_DEBUG
 
-GPTPartitionTable::GPTPartitionTable(DiskDevice& device)
+GPTPartitionTable::GPTPartitionTable(BlockDevice& device)
     : m_device(move(device))
 {
 }

+ 2 - 3
Kernel/Devices/GPTPartitionTable.h

@@ -29,7 +29,6 @@
 #include <AK/RefPtr.h>
 #include <AK/Types.h>
 #include <AK/Vector.h>
-#include <Kernel/Devices/DiskDevice.h>
 #include <Kernel/Devices/DiskPartition.h>
 
 #define GPT_SIGNATURE2 0x54524150
@@ -73,14 +72,14 @@ struct [[gnu::packed]] GPTPartitionHeader
 class GPTPartitionTable {
 
 public:
-    explicit GPTPartitionTable(DiskDevice&);
+    explicit GPTPartitionTable(BlockDevice&);
     ~GPTPartitionTable();
 
     bool initialize();
     RefPtr<DiskPartition> partition(unsigned index);
 
 private:
-    NonnullRefPtr<DiskDevice> m_device;
+    NonnullRefPtr<BlockDevice> m_device;
 
     const GPTPartitionHeader& header() const;
 

+ 1 - 1
Kernel/Devices/MBRPartitionTable.cpp

@@ -29,7 +29,7 @@
 
 #define MBR_DEBUG
 
-MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<DiskDevice> device)
+MBRPartitionTable::MBRPartitionTable(NonnullRefPtr<BlockDevice> device)
     : m_device(move(device))
 {
 }

+ 2 - 3
Kernel/Devices/MBRPartitionTable.h

@@ -28,7 +28,6 @@
 
 #include <AK/RefPtr.h>
 #include <AK/Vector.h>
-#include <Kernel/Devices/DiskDevice.h>
 #include <Kernel/Devices/DiskPartition.h>
 
 #define MBR_SIGNATURE 0xaa55
@@ -62,7 +61,7 @@ class MBRPartitionTable {
     AK_MAKE_ETERNAL
 
 public:
-    explicit MBRPartitionTable(NonnullRefPtr<DiskDevice>);
+    explicit MBRPartitionTable(NonnullRefPtr<BlockDevice>);
     ~MBRPartitionTable();
 
     bool initialize();
@@ -71,7 +70,7 @@ public:
     RefPtr<DiskPartition> partition(unsigned index);
 
 private:
-    NonnullRefPtr<DiskDevice> m_device;
+    NonnullRefPtr<BlockDevice> m_device;
 
     const MBRPartitionHeader& header() const;
 

+ 2 - 0
Kernel/Devices/MBVGADevice.h

@@ -47,6 +47,8 @@ private:
     virtual bool can_write(const FileDescription&) const override { return true; }
     virtual ssize_t read(FileDescription&, 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; }
 

+ 1 - 11
Kernel/Devices/PATADiskDevice.cpp

@@ -33,7 +33,7 @@ NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(PATAChannel& channel, Drive
 }
 
 PATADiskDevice::PATADiskDevice(PATAChannel& channel, DriveType type, int major, int minor)
-    : DiskDevice(major, minor)
+    : BlockDevice(major, minor, 512)
     , m_drive_type(type)
     , m_channel(channel)
 {
@@ -55,11 +55,6 @@ bool PATADiskDevice::read_blocks(unsigned index, u16 count, u8* 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)
 {
     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;
 }
 
-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)
 {
     m_cylinders = cyls;

+ 2 - 4
Kernel/Devices/PATADiskDevice.h

@@ -30,13 +30,13 @@
 //
 #pragma once
 
-#include <Kernel/Devices/DiskDevice.h>
+#include <Kernel/Devices/BlockDevice.h>
 #include <Kernel/IRQHandler.h>
 #include <Kernel/Lock.h>
 
 class PATAChannel;
 
-class PATADiskDevice final : public DiskDevice {
+class PATADiskDevice final : public BlockDevice {
     AK_MAKE_ETERNAL
 public:
     // Type of drive this IDEDiskDevice is on the ATA channel.
@@ -53,8 +53,6 @@ public:
     virtual ~PATADiskDevice() override;
 
     // ^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 write_blocks(unsigned index, u16 count, const u8*) override;
 

+ 12 - 12
Kernel/FileSystem/DiskBackedFileSystem.cpp

@@ -110,8 +110,8 @@ private:
     bool m_dirty { false };
 };
 
-DiskBackedFS::DiskBackedFS(NonnullRefPtr<DiskDevice>&& device)
-    : m_device(move(device))
+DiskBackedFS::DiskBackedFS(BlockDevice& device)
+    : m_device(device)
 {
 }
 
@@ -129,8 +129,8 @@ bool DiskBackedFS::write_block(unsigned index, const u8* data, FileDescription*
 
     if (!allow_cache) {
         flush_specific_block_if_needed(index);
-        DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
-        device().write(base_offset, block_size(), data);
+        u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
+        device().write_raw(base_offset, block_size(), data);
         return true;
     }
 
@@ -163,16 +163,16 @@ bool DiskBackedFS::read_block(unsigned index, u8* buffer, FileDescription* descr
 
     if (!allow_cache) {
         const_cast<DiskBackedFS*>(this)->flush_specific_block_if_needed(index);
-        DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
-        bool success = device().read(base_offset, block_size(), buffer);
+        u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
+        bool success = device().read_raw(base_offset, block_size(), buffer);
         ASSERT(success);
         return true;
     }
 
     auto& entry = cache().get(index);
     if (!entry.has_data) {
-        DiskOffset base_offset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(block_size());
-        bool success = device().read(base_offset, block_size(), entry.data);
+        u32 base_offset = static_cast<u32>(index) * static_cast<u32>(block_size());
+        bool success = device().read_raw(base_offset, block_size(), entry.data);
         entry.has_data = true;
         ASSERT(success);
     }
@@ -204,8 +204,8 @@ void DiskBackedFS::flush_specific_block_if_needed(unsigned index)
         return;
     cache().for_each_entry([&](CacheEntry& entry) {
         if (entry.is_dirty && entry.block_index == index) {
-            DiskOffset base_offset = static_cast<DiskOffset>(entry.block_index) * static_cast<DiskOffset>(block_size());
-            device().write(base_offset, block_size(), entry.data);
+            u32 base_offset = static_cast<u32>(entry.block_index) * static_cast<u32>(block_size());
+            device().write_raw(base_offset, block_size(), entry.data);
             entry.is_dirty = false;
         }
     });
@@ -220,8 +220,8 @@ void DiskBackedFS::flush_writes_impl()
     cache().for_each_entry([&](CacheEntry& entry) {
         if (!entry.is_dirty)
             return;
-        DiskOffset base_offset = static_cast<DiskOffset>(entry.block_index) * static_cast<DiskOffset>(block_size());
-        device().write(base_offset, block_size(), entry.data);
+        u32 base_offset = static_cast<u32>(entry.block_index) * static_cast<u32>(block_size());
+        device().write_raw(base_offset, block_size(), entry.data);
         ++count;
         entry.is_dirty = false;
     });

+ 4 - 4
Kernel/FileSystem/DiskBackedFileSystem.h

@@ -37,15 +37,15 @@ public:
 
     virtual bool is_disk_backed() const override { return true; }
 
-    DiskDevice& device() { return *m_device; }
-    const DiskDevice& device() const { return *m_device; }
+    BlockDevice& device() { return *m_device; }
+    const BlockDevice& device() const { return *m_device; }
 
     virtual void flush_writes() override;
 
     void flush_writes_impl();
 
 protected:
-    explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
+    explicit DiskBackedFS(BlockDevice&);
 
     bool read_block(unsigned index, 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;
     void flush_specific_block_if_needed(unsigned index);
 
-    NonnullRefPtr<DiskDevice> m_device;
+    NonnullRefPtr<BlockDevice> m_device;
     mutable OwnPtr<DiskCache> m_cache;
 };

+ 5 - 5
Kernel/FileSystem/Ext2FileSystem.cpp

@@ -58,13 +58,13 @@ static u8 to_ext2_file_type(mode_t mode)
     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)
-    : DiskBackedFS(move(device))
+Ext2FS::Ext2FS(BlockDevice& device)
+    : DiskBackedFS(device)
 {
 }
 
@@ -90,7 +90,7 @@ const ext2_group_desc& Ext2FS::group_descriptor(GroupIndex group_index) const
 bool Ext2FS::initialize()
 {
     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);
 
     auto& super_block = this->super_block();

+ 2 - 2
Kernel/FileSystem/Ext2FileSystem.h

@@ -89,7 +89,7 @@ class Ext2FS final : public DiskBackedFS {
     friend class Ext2FSInode;
 
 public:
-    static NonnullRefPtr<Ext2FS> create(NonnullRefPtr<DiskDevice>);
+    static NonnullRefPtr<Ext2FS> create(BlockDevice&);
     virtual ~Ext2FS() override;
     virtual bool initialize() override;
 
@@ -106,7 +106,7 @@ private:
     typedef unsigned BlockIndex;
     typedef unsigned GroupIndex;
     typedef unsigned InodeIndex;
-    explicit Ext2FS(NonnullRefPtr<DiskDevice>&&);
+    explicit Ext2FS(BlockDevice&);
 
     const ext2_super_block& super_block() const { return m_super_block; }
     const ext2_group_desc& group_descriptor(GroupIndex) const;

+ 1 - 1
Kernel/FileSystem/FileSystem.h

@@ -35,7 +35,7 @@
 #include <AK/String.h>
 #include <AK/WeakPtr.h>
 #include <AK/kstdio.h>
-#include <Kernel/Devices/DiskDevice.h>
+#include <Kernel/Devices/BlockDevice.h>
 #include <Kernel/FileSystem/InodeIdentifier.h>
 #include <Kernel/FileSystem/InodeMetadata.h>
 #include <Kernel/KResult.h>

+ 0 - 1
Kernel/Makefile

@@ -20,7 +20,6 @@ OBJS = \
     Devices/CharacterDevice.o \
     Devices/DebugLogDevice.o \
     Devices/Device.o \
-    Devices/DiskDevice.o \
     Devices/DiskPartition.o \
     Devices/FloppyDiskDevice.o \
     Devices/FullDevice.o \

+ 5 - 5
Kernel/Process.cpp

@@ -3992,15 +3992,15 @@ int Process::sys$mount(const Syscall::SC_mount_params* user_params)
             return source_or_error.error();
 
         auto* device = source_or_error.value()->device();
-        if (!device || !device->is_disk_device()) {
-            dbg() << "mount: this is not a DiskDevice";
+        if (!device || !device->is_block_device()) {
+            dbg() << "mount: this is not a BlockDevice";
             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") {
         fs = ProcFS::create();
     } else if (fs_type == "devpts" || fs_type == "DevPtsFS") {

+ 1 - 1
Kernel/init.cpp

@@ -229,7 +229,7 @@ void init_stage2()
     }
 
     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"));