diff --git a/Kernel/ACPI/ACPIDynamicParser.h b/Kernel/ACPI/ACPIDynamicParser.h index eb87f18fc8..c7ea5539da 100644 --- a/Kernel/ACPI/ACPIDynamicParser.h +++ b/Kernel/ACPI/ACPIDynamicParser.h @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -56,4 +55,4 @@ private: virtual void handle_irq() override; OwnPtr m_acpi_namespace; -}; \ No newline at end of file +}; diff --git a/Kernel/Devices/BXVGADevice.h b/Kernel/Devices/BXVGADevice.h index 9c0791fc7c..84bbd0dea4 100644 --- a/Kernel/Devices/BXVGADevice.h +++ b/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(); diff --git a/Kernel/Devices/BlockDevice.cpp b/Kernel/Devices/BlockDevice.cpp index cdecc67fec..2ad857240b 100644 --- a/Kernel/Devices/BlockDevice.cpp +++ b/Kernel/Devices/BlockDevice.cpp @@ -29,3 +29,33 @@ BlockDevice::~BlockDevice() { } + +bool BlockDevice::read_block(unsigned index, u8* buffer) const +{ + return const_cast(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(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); +} diff --git a/Kernel/Devices/BlockDevice.h b/Kernel/Devices/BlockDevice.h index fd8c2fb495..6b639cbc63 100644 --- a/Kernel/Devices/BlockDevice.h +++ b/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) diff --git a/Kernel/Devices/DiskDevice.cpp b/Kernel/Devices/DiskDevice.cpp deleted file mode 100644 index 9e57368b1d..0000000000 --- a/Kernel/Devices/DiskDevice.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * 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 - -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(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); -} diff --git a/Kernel/Devices/DiskDevice.h b/Kernel/Devices/DiskDevice.h deleted file mode 100644 index e95365ee09..0000000000 --- a/Kernel/Devices/DiskDevice.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * 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 -#include -#include - -// 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); -}; diff --git a/Kernel/Devices/DiskPartition.cpp b/Kernel/Devices/DiskPartition.cpp index a5e40b076d..a763b062ba 100644 --- a/Kernel/Devices/DiskPartition.cpp +++ b/Kernel/Devices/DiskPartition.cpp @@ -28,13 +28,13 @@ // #define OFFD_DEBUG -NonnullRefPtr DiskPartition::create(DiskDevice& device, unsigned block_offset, unsigned block_limit) +NonnullRefPtr 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 diff --git a/Kernel/Devices/DiskPartition.h b/Kernel/Devices/DiskPartition.h index c2d77aa18a..f7258d07e0 100644 --- a/Kernel/Devices/DiskPartition.h +++ b/Kernel/Devices/DiskPartition.h @@ -27,15 +27,13 @@ #pragma once #include -#include +#include -class DiskPartition final : public DiskDevice { +class DiskPartition final : public BlockDevice { public: - static NonnullRefPtr create(DiskDevice&, unsigned block_offset, unsigned block_limit); + static NonnullRefPtr 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 m_device; + NonnullRefPtr m_device; unsigned m_block_offset; unsigned m_block_limit; }; diff --git a/Kernel/Devices/EBRPartitionTable.cpp b/Kernel/Devices/EBRPartitionTable.cpp index a5fbb04462..23f3bb9b05 100644 --- a/Kernel/Devices/EBRPartitionTable.cpp +++ b/Kernel/Devices/EBRPartitionTable.cpp @@ -29,7 +29,7 @@ #define EBR_DEBUG -EBRPartitionTable::EBRPartitionTable(NonnullRefPtr device) +EBRPartitionTable::EBRPartitionTable(NonnullRefPtr device) : m_device(move(device)) { } diff --git a/Kernel/Devices/EBRPartitionTable.h b/Kernel/Devices/EBRPartitionTable.h index 9245fc7626..564c8c9e9c 100644 --- a/Kernel/Devices/EBRPartitionTable.h +++ b/Kernel/Devices/EBRPartitionTable.h @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -44,7 +43,7 @@ struct [[gnu::packed]] EBRPartitionExtension class EBRPartitionTable { public: - explicit EBRPartitionTable(NonnullRefPtr); + explicit EBRPartitionTable(NonnullRefPtr); ~EBRPartitionTable(); bool initialize(); @@ -52,7 +51,7 @@ public: private: int index_of_ebr_container() const; - NonnullRefPtr m_device; + NonnullRefPtr m_device; const MBRPartitionHeader& header() const; const EBRPartitionExtension& ebr_extension() const; diff --git a/Kernel/Devices/FloppyDiskDevice.cpp b/Kernel/Devices/FloppyDiskDevice.cpp index d0486f925c..3e9e4a3128 100644 --- a/Kernel/Devices/FloppyDiskDevice.cpp +++ b/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(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); diff --git a/Kernel/Devices/FloppyDiskDevice.h b/Kernel/Devices/FloppyDiskDevice.h index 2942f94227..e975fd789f 100644 --- a/Kernel/Devices/FloppyDiskDevice.h +++ b/Kernel/Devices/FloppyDiskDevice.h @@ -98,7 +98,7 @@ #pragma once #include -#include +#include #include #include #include @@ -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; diff --git a/Kernel/Devices/GPTPartitionTable.cpp b/Kernel/Devices/GPTPartitionTable.cpp index 1929a6cff7..925d510052 100644 --- a/Kernel/Devices/GPTPartitionTable.cpp +++ b/Kernel/Devices/GPTPartitionTable.cpp @@ -29,7 +29,7 @@ #define GPT_DEBUG -GPTPartitionTable::GPTPartitionTable(DiskDevice& device) +GPTPartitionTable::GPTPartitionTable(BlockDevice& device) : m_device(move(device)) { } diff --git a/Kernel/Devices/GPTPartitionTable.h b/Kernel/Devices/GPTPartitionTable.h index 9ec4ac3ea5..5a86fc00d5 100644 --- a/Kernel/Devices/GPTPartitionTable.h +++ b/Kernel/Devices/GPTPartitionTable.h @@ -29,7 +29,6 @@ #include #include #include -#include #include #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 partition(unsigned index); private: - NonnullRefPtr m_device; + NonnullRefPtr m_device; const GPTPartitionHeader& header() const; diff --git a/Kernel/Devices/MBRPartitionTable.cpp b/Kernel/Devices/MBRPartitionTable.cpp index 8880533698..4f3b865eba 100644 --- a/Kernel/Devices/MBRPartitionTable.cpp +++ b/Kernel/Devices/MBRPartitionTable.cpp @@ -29,7 +29,7 @@ #define MBR_DEBUG -MBRPartitionTable::MBRPartitionTable(NonnullRefPtr device) +MBRPartitionTable::MBRPartitionTable(NonnullRefPtr device) : m_device(move(device)) { } diff --git a/Kernel/Devices/MBRPartitionTable.h b/Kernel/Devices/MBRPartitionTable.h index 61adddf19c..a4c2419cc7 100644 --- a/Kernel/Devices/MBRPartitionTable.h +++ b/Kernel/Devices/MBRPartitionTable.h @@ -28,7 +28,6 @@ #include #include -#include #include #define MBR_SIGNATURE 0xaa55 @@ -62,7 +61,7 @@ class MBRPartitionTable { AK_MAKE_ETERNAL public: - explicit MBRPartitionTable(NonnullRefPtr); + explicit MBRPartitionTable(NonnullRefPtr); ~MBRPartitionTable(); bool initialize(); @@ -71,7 +70,7 @@ public: RefPtr partition(unsigned index); private: - NonnullRefPtr m_device; + NonnullRefPtr m_device; const MBRPartitionHeader& header() const; diff --git a/Kernel/Devices/MBVGADevice.h b/Kernel/Devices/MBVGADevice.h index 67607e1e7b..a5cec28107 100644 --- a/Kernel/Devices/MBVGADevice.h +++ b/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; } diff --git a/Kernel/Devices/PATADiskDevice.cpp b/Kernel/Devices/PATADiskDevice.cpp index 1ab70af9f1..6182ab6e88 100644 --- a/Kernel/Devices/PATADiskDevice.cpp +++ b/Kernel/Devices/PATADiskDevice.cpp @@ -33,7 +33,7 @@ NonnullRefPtr 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(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; diff --git a/Kernel/Devices/PATADiskDevice.h b/Kernel/Devices/PATADiskDevice.h index 086c6d8467..54cbb6f9c5 100644 --- a/Kernel/Devices/PATADiskDevice.h +++ b/Kernel/Devices/PATADiskDevice.h @@ -30,13 +30,13 @@ // #pragma once -#include +#include #include #include 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; diff --git a/Kernel/FileSystem/DiskBackedFileSystem.cpp b/Kernel/FileSystem/DiskBackedFileSystem.cpp index 65ae4754a8..76b0db0df3 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.cpp +++ b/Kernel/FileSystem/DiskBackedFileSystem.cpp @@ -110,8 +110,8 @@ private: bool m_dirty { false }; }; -DiskBackedFS::DiskBackedFS(NonnullRefPtr&& 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(index) * static_cast(block_size()); - device().write(base_offset, block_size(), data); + u32 base_offset = static_cast(index) * static_cast(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(this)->flush_specific_block_if_needed(index); - DiskOffset base_offset = static_cast(index) * static_cast(block_size()); - bool success = device().read(base_offset, block_size(), buffer); + u32 base_offset = static_cast(index) * static_cast(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(index) * static_cast(block_size()); - bool success = device().read(base_offset, block_size(), entry.data); + u32 base_offset = static_cast(index) * static_cast(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(entry.block_index) * static_cast(block_size()); - device().write(base_offset, block_size(), entry.data); + u32 base_offset = static_cast(entry.block_index) * static_cast(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(entry.block_index) * static_cast(block_size()); - device().write(base_offset, block_size(), entry.data); + u32 base_offset = static_cast(entry.block_index) * static_cast(block_size()); + device().write_raw(base_offset, block_size(), entry.data); ++count; entry.is_dirty = false; }); diff --git a/Kernel/FileSystem/DiskBackedFileSystem.h b/Kernel/FileSystem/DiskBackedFileSystem.h index dd4026ea8d..f60ced8a47 100644 --- a/Kernel/FileSystem/DiskBackedFileSystem.h +++ b/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&&); + 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 m_device; + NonnullRefPtr m_device; mutable OwnPtr m_cache; }; diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 2e07e5c4cb..bd7d52519c 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -58,13 +58,13 @@ static u8 to_ext2_file_type(mode_t mode) return EXT2_FT_UNKNOWN; } -NonnullRefPtr Ext2FS::create(NonnullRefPtr device) +NonnullRefPtr Ext2FS::create(BlockDevice& device) { - return adopt(*new Ext2FS(move(device))); + return adopt(*new Ext2FS(device)); } -Ext2FS::Ext2FS(NonnullRefPtr&& 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(device()).read_blocks(2, 1, (u8*)&m_super_block); + bool success = const_cast(device()).read_blocks(2, 1, (u8*)&m_super_block); ASSERT(success); auto& super_block = this->super_block(); diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index c1c6db1321..7a629ae260 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -89,7 +89,7 @@ class Ext2FS final : public DiskBackedFS { friend class Ext2FSInode; public: - static NonnullRefPtr create(NonnullRefPtr); + static NonnullRefPtr 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&&); + explicit Ext2FS(BlockDevice&); const ext2_super_block& super_block() const { return m_super_block; } const ext2_group_desc& group_descriptor(GroupIndex) const; diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index 30fef306ee..373f73241f 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Makefile b/Kernel/Makefile index 97df4b1024..4e154527b7 100644 --- a/Kernel/Makefile +++ b/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 \ diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 3c3f975cab..47683a4135 100644 --- a/Kernel/Process.cpp +++ b/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(*device); + auto& block_device = static_cast(*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") { diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 0d8a832922..122ec63eba 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -229,7 +229,7 @@ void init_stage2() } auto pata0 = PATAChannel::create(PATAChannel::ChannelType::Primary, force_pio); - NonnullRefPtr root_dev = *pata0->master_device(); + NonnullRefPtr root_dev = *pata0->master_device(); root = root.substring(strlen("/dev/hda"), root.length() - strlen("/dev/hda"));