1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:17:34 +00:00

Kernel: Merge unnecessary DiskDevice class into BlockDevice

This commit is contained in:
Andreas Kling 2020-02-08 02:17:26 +01:00
parent 6be880bd10
commit 88ea152b24
27 changed files with 98 additions and 212 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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>