mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
BlockDevice -> DiskDevice.
BlockDevice was the wrong name for this abstraction, since a block device is a type of file in a unix system, and we should use that name for that concept in the fs implementation.
This commit is contained in:
parent
72bb80a9ae
commit
9cd0a34b5c
Notes:
sideshowbarker
2024-07-19 18:47:37 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9cd0a34b5cf
12 changed files with 62 additions and 64 deletions
|
@ -1,9 +0,0 @@
|
|||
#include "BlockDevice.h"
|
||||
|
||||
BlockDevice::BlockDevice()
|
||||
{
|
||||
}
|
||||
|
||||
BlockDevice::~BlockDevice()
|
||||
{
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
#include "DeviceBackedFileSystem.h"
|
||||
#include "DiskBackedFileSystem.h"
|
||||
|
||||
//#define DBFS_DEBUG
|
||||
|
||||
DeviceBackedFileSystem::DeviceBackedFileSystem(RetainPtr<BlockDevice>&& device)
|
||||
DiskBackedFileSystem::DiskBackedFileSystem(RetainPtr<DiskDevice>&& device)
|
||||
: m_device(std::move(device))
|
||||
{
|
||||
ASSERT(m_device);
|
||||
}
|
||||
|
||||
DeviceBackedFileSystem::~DeviceBackedFileSystem()
|
||||
DiskBackedFileSystem::~DiskBackedFileSystem()
|
||||
{
|
||||
}
|
||||
|
||||
bool DeviceBackedFileSystem::writeBlock(unsigned index, const ByteBuffer& data)
|
||||
bool DiskBackedFileSystem::writeBlock(unsigned index, const ByteBuffer& data)
|
||||
{
|
||||
ASSERT(data.size() == blockSize());
|
||||
#ifdef DBFS_DEBUG
|
||||
printf("DeviceBackedFileSystem::writeBlock %u\n", index);
|
||||
printf("DiskBackedFileSystem::writeBlock %u\n", index);
|
||||
#endif
|
||||
qword baseOffset = static_cast<qword>(index) * static_cast<qword>(blockSize());
|
||||
return device().write(baseOffset, blockSize(), data.pointer());
|
||||
}
|
||||
|
||||
bool DeviceBackedFileSystem::writeBlocks(unsigned index, unsigned count, const ByteBuffer& data)
|
||||
bool DiskBackedFileSystem::writeBlocks(unsigned index, unsigned count, const ByteBuffer& data)
|
||||
{
|
||||
#ifdef DBFS_DEBUG
|
||||
printf("DeviceBackedFileSystem::writeBlocks %u x%u\n", index, count);
|
||||
printf("DiskBackedFileSystem::writeBlocks %u x%u\n", index, count);
|
||||
#endif
|
||||
qword baseOffset = static_cast<qword>(index) * static_cast<qword>(blockSize());
|
||||
return device().write(baseOffset, count * blockSize(), data.pointer());
|
||||
}
|
||||
|
||||
ByteBuffer DeviceBackedFileSystem::readBlock(unsigned index) const
|
||||
ByteBuffer DiskBackedFileSystem::readBlock(unsigned index) const
|
||||
{
|
||||
#ifdef DBFS_DEBUG
|
||||
printf("DeviceBackedFileSystem::readBlock %u\n", index);
|
||||
printf("DiskBackedFileSystem::readBlock %u\n", index);
|
||||
#endif
|
||||
auto buffer = ByteBuffer::createUninitialized(blockSize());
|
||||
qword baseOffset = static_cast<qword>(index) * static_cast<qword>(blockSize());
|
||||
|
@ -44,7 +44,7 @@ ByteBuffer DeviceBackedFileSystem::readBlock(unsigned index) const
|
|||
return buffer;
|
||||
}
|
||||
|
||||
ByteBuffer DeviceBackedFileSystem::readBlocks(unsigned index, unsigned count) const
|
||||
ByteBuffer DiskBackedFileSystem::readBlocks(unsigned index, unsigned count) const
|
||||
{
|
||||
if (!count)
|
||||
return nullptr;
|
||||
|
@ -64,7 +64,7 @@ ByteBuffer DeviceBackedFileSystem::readBlocks(unsigned index, unsigned count) co
|
|||
return blocks;
|
||||
}
|
||||
|
||||
void DeviceBackedFileSystem::setBlockSize(unsigned blockSize)
|
||||
void DiskBackedFileSystem::setBlockSize(unsigned blockSize)
|
||||
{
|
||||
if (blockSize == m_blockSize)
|
||||
return;
|
||||
|
@ -72,7 +72,7 @@ void DeviceBackedFileSystem::setBlockSize(unsigned blockSize)
|
|||
invalidateCaches();
|
||||
}
|
||||
|
||||
void DeviceBackedFileSystem::invalidateCaches()
|
||||
void DiskBackedFileSystem::invalidateCaches()
|
||||
{
|
||||
// FIXME: Implement block cache.
|
||||
}
|
|
@ -3,17 +3,17 @@
|
|||
#include "FileSystem.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
|
||||
class DeviceBackedFileSystem : public FileSystem {
|
||||
class DiskBackedFileSystem : public FileSystem {
|
||||
public:
|
||||
virtual ~DeviceBackedFileSystem() override;
|
||||
virtual ~DiskBackedFileSystem() override;
|
||||
|
||||
BlockDevice& device() { return *m_device; }
|
||||
const BlockDevice& device() const { return *m_device; }
|
||||
DiskDevice& device() { return *m_device; }
|
||||
const DiskDevice& device() const { return *m_device; }
|
||||
|
||||
unsigned blockSize() const { return m_blockSize; }
|
||||
|
||||
protected:
|
||||
explicit DeviceBackedFileSystem(RetainPtr<BlockDevice>&&);
|
||||
explicit DiskBackedFileSystem(RetainPtr<DiskDevice>&&);
|
||||
|
||||
void setBlockSize(unsigned);
|
||||
void invalidateCaches();
|
||||
|
@ -26,5 +26,5 @@ protected:
|
|||
|
||||
private:
|
||||
unsigned m_blockSize { 0 };
|
||||
RetainPtr<BlockDevice> m_device;
|
||||
RetainPtr<DiskDevice> m_device;
|
||||
};
|
9
VirtualFileSystem/DiskDevice.cpp
Normal file
9
VirtualFileSystem/DiskDevice.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "DiskDevice.h"
|
||||
|
||||
DiskDevice::DiskDevice()
|
||||
{
|
||||
}
|
||||
|
||||
DiskDevice::~DiskDevice()
|
||||
{
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
#include <AK/Retainable.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
class BlockDevice : public Retainable<BlockDevice> {
|
||||
class DiskDevice : public Retainable<DiskDevice> {
|
||||
public:
|
||||
virtual ~BlockDevice();
|
||||
virtual ~DiskDevice();
|
||||
|
||||
virtual unsigned blockSize() const = 0;
|
||||
virtual bool readBlock(unsigned index, byte*) const = 0;
|
||||
|
@ -15,6 +15,6 @@ public:
|
|||
virtual bool write(qword offset, unsigned length, const byte*) = 0;
|
||||
|
||||
protected:
|
||||
BlockDevice();
|
||||
DiskDevice();
|
||||
};
|
||||
|
|
@ -10,13 +10,13 @@
|
|||
|
||||
//#define EXT2_DEBUG
|
||||
|
||||
RetainPtr<Ext2FileSystem> Ext2FileSystem::create(RetainPtr<BlockDevice> device)
|
||||
RetainPtr<Ext2FileSystem> Ext2FileSystem::create(RetainPtr<DiskDevice>&& device)
|
||||
{
|
||||
return adopt(*new Ext2FileSystem(std::move(device)));
|
||||
}
|
||||
|
||||
Ext2FileSystem::Ext2FileSystem(RetainPtr<BlockDevice> device)
|
||||
: DeviceBackedFileSystem(std::move(device))
|
||||
Ext2FileSystem::Ext2FileSystem(RetainPtr<DiskDevice>&& device)
|
||||
: DiskBackedFileSystem(std::move(device))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "DeviceBackedFileSystem.h"
|
||||
#include "DiskBackedFileSystem.h"
|
||||
#include "UnixTypes.h"
|
||||
#include <AK/Buffer.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
|
@ -9,9 +9,9 @@ struct ext2_group_desc;
|
|||
struct ext2_inode;
|
||||
struct ext2_super_block;
|
||||
|
||||
class Ext2FileSystem final : public DeviceBackedFileSystem {
|
||||
class Ext2FileSystem final : public DiskBackedFileSystem {
|
||||
public:
|
||||
static RetainPtr<Ext2FileSystem> create(RetainPtr<BlockDevice>);
|
||||
static RetainPtr<Ext2FileSystem> create(RetainPtr<DiskDevice>&&);
|
||||
virtual ~Ext2FileSystem() override;
|
||||
|
||||
private:
|
||||
|
@ -19,7 +19,7 @@ private:
|
|||
typedef unsigned GroupIndex;
|
||||
typedef unsigned InodeIndex;
|
||||
|
||||
explicit Ext2FileSystem(RetainPtr<BlockDevice>);
|
||||
explicit Ext2FileSystem(RetainPtr<DiskDevice>&&);
|
||||
|
||||
const ext2_super_block& superBlock() const;
|
||||
const ext2_group_desc& blockGroupDescriptor(unsigned groupIndex) const;
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include "FileBackedBlockDevice.h"
|
||||
#include "FileBackedDiskDevice.h"
|
||||
#include <cstring>
|
||||
#include <sys/stat.h>
|
||||
|
||||
//#define FBBD_DEBUG
|
||||
#define IGNORE_FILE_LENGTH // Useful for e.g /dev/hda2
|
||||
|
||||
RetainPtr<FileBackedBlockDevice> FileBackedBlockDevice::create(String&& imagePath, unsigned blockSize)
|
||||
RetainPtr<FileBackedDiskDevice> FileBackedDiskDevice::create(String&& imagePath, unsigned blockSize)
|
||||
{
|
||||
return adopt(*new FileBackedBlockDevice(std::move(imagePath), blockSize));
|
||||
return adopt(*new FileBackedDiskDevice(std::move(imagePath), blockSize));
|
||||
}
|
||||
|
||||
FileBackedBlockDevice::FileBackedBlockDevice(String&& imagePath, unsigned blockSize)
|
||||
FileBackedDiskDevice::FileBackedDiskDevice(String&& imagePath, unsigned blockSize)
|
||||
: m_imagePath(std::move(imagePath))
|
||||
, m_blockSize(blockSize)
|
||||
{
|
||||
|
@ -23,35 +23,35 @@ FileBackedBlockDevice::FileBackedBlockDevice(String&& imagePath, unsigned blockS
|
|||
m_file = fopen(m_imagePath.characters(), "r+");
|
||||
}
|
||||
|
||||
FileBackedBlockDevice::~FileBackedBlockDevice()
|
||||
FileBackedDiskDevice::~FileBackedDiskDevice()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned FileBackedBlockDevice::blockSize() const
|
||||
unsigned FileBackedDiskDevice::blockSize() const
|
||||
{
|
||||
return m_blockSize;
|
||||
}
|
||||
|
||||
bool FileBackedBlockDevice::readBlock(unsigned index, byte* out) const
|
||||
bool FileBackedDiskDevice::readBlock(unsigned index, byte* out) const
|
||||
{
|
||||
qword offset = index * m_blockSize;
|
||||
return read(offset, blockSize(), out);
|
||||
}
|
||||
|
||||
bool FileBackedBlockDevice::writeBlock(unsigned index, const byte* data)
|
||||
bool FileBackedDiskDevice::writeBlock(unsigned index, const byte* data)
|
||||
{
|
||||
qword offset = index * m_blockSize;
|
||||
return write(offset, blockSize(), data);
|
||||
}
|
||||
|
||||
bool FileBackedBlockDevice::read(qword offset, unsigned length, byte* out) const
|
||||
bool FileBackedDiskDevice::read(qword offset, unsigned length, byte* out) const
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
return false;
|
||||
#endif
|
||||
#ifdef FBBD_DEBUG
|
||||
printf("[FileBackedBlockDevice] Read device @ offset %llx, length %u\n", offset, length);
|
||||
printf("[FileBackedDiskDevice] Read device @ offset %llx, length %u\n", offset, length);
|
||||
#endif
|
||||
fseeko(m_file, offset, SEEK_SET);
|
||||
unsigned nread = fread(out, sizeof(byte), length, m_file);
|
||||
|
@ -59,14 +59,14 @@ bool FileBackedBlockDevice::read(qword offset, unsigned length, byte* out) const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileBackedBlockDevice::write(qword offset, unsigned length, const byte* data)
|
||||
bool FileBackedDiskDevice::write(qword offset, unsigned length, const byte* data)
|
||||
{
|
||||
#ifndef IGNORE_FILE_LENGTH
|
||||
if (offset + length >= m_fileLength)
|
||||
return false;
|
||||
#endif
|
||||
#ifdef FBBD_DEBUG
|
||||
printf("[FileBackedBlockDevice] Write device @ offset %llx, length %u\n", offset, length);
|
||||
printf("[FileBackedDiskDevice] Write device @ offset %llx, length %u\n", offset, length);
|
||||
#endif
|
||||
fseeko(m_file, offset, SEEK_SET);
|
||||
// size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
||||
|
@ -75,8 +75,8 @@ bool FileBackedBlockDevice::write(qword offset, unsigned length, const byte* dat
|
|||
return true;
|
||||
}
|
||||
|
||||
const char* FileBackedBlockDevice::className() const
|
||||
const char* FileBackedDiskDevice::className() const
|
||||
{
|
||||
return "FileBackedBlockDevice";
|
||||
return "FileBackedDiskDevice";
|
||||
}
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "BlockDevice.h"
|
||||
#include "DiskDevice.h"
|
||||
#include <AK/RetainPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class FileBackedBlockDevice final : public BlockDevice {
|
||||
class FileBackedDiskDevice final : public DiskDevice {
|
||||
public:
|
||||
static RetainPtr<FileBackedBlockDevice> create(String&& imagePath, unsigned blockSize);
|
||||
virtual ~FileBackedBlockDevice() override;
|
||||
static RetainPtr<FileBackedDiskDevice> create(String&& imagePath, unsigned blockSize);
|
||||
virtual ~FileBackedDiskDevice() override;
|
||||
|
||||
bool isValid() const { return m_file; }
|
||||
|
||||
|
@ -22,7 +22,7 @@ public:
|
|||
private:
|
||||
virtual const char* className() const override;
|
||||
|
||||
FileBackedBlockDevice(String&& imagePath, unsigned blockSize);
|
||||
FileBackedDiskDevice(String&& imagePath, unsigned blockSize);
|
||||
|
||||
String m_imagePath;
|
||||
FILE* m_file { nullptr };
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "BlockDevice.h"
|
||||
#include "DiskDevice.h"
|
||||
#include "InodeIdentifier.h"
|
||||
#include "InodeMetadata.h"
|
||||
#include "Limits.h"
|
||||
|
|
|
@ -9,13 +9,13 @@ AK_OBJS = \
|
|||
../AK/kmalloc.o
|
||||
|
||||
VFS_OBJS = \
|
||||
BlockDevice.o \
|
||||
FileBackedBlockDevice.o \
|
||||
DiskDevice.o \
|
||||
FileBackedDiskDevice.o \
|
||||
FileSystem.o \
|
||||
Ext2FileSystem.o \
|
||||
VirtualFileSystem.o \
|
||||
FileHandle.o \
|
||||
DeviceBackedFileSystem.o \
|
||||
DiskBackedFileSystem.o \
|
||||
SyntheticFileSystem.o \
|
||||
InodeIdentifier.o \
|
||||
CharacterDevice.o \
|
||||
|
@ -29,8 +29,6 @@ OBJS = $(AK_OBJS) $(VFS_OBJS)
|
|||
|
||||
CXXFLAGS = -std=c++17 -O0 -W -Wall -Wextra -Wconversion -I. -I.. -ggdb3 -Wno-class-memaccess
|
||||
|
||||
#test.o: BlockDevice.h FileBackedBlockDevice.h FileSystem.h Ext2FileSystem.h VirtualFileSystem.h FileHandle.h
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
.cpp.o:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "Ext2FileSystem.h"
|
||||
#include "FileBackedBlockDevice.h"
|
||||
#include "FileBackedDiskDevice.h"
|
||||
#include "VirtualFileSystem.h"
|
||||
#include "FileHandle.h"
|
||||
#include "SyntheticFileSystem.h"
|
||||
|
@ -217,7 +217,7 @@ int main(int c, char** v)
|
|||
|
||||
RetainPtr<FileSystem> makeFileSystem(const char* imagePath)
|
||||
{
|
||||
auto fsImage = FileBackedBlockDevice::create(imagePath, 512);
|
||||
auto fsImage = FileBackedDiskDevice::create(imagePath, 512);
|
||||
if (!fsImage->isValid()) {
|
||||
fprintf(stderr, "Failed to open fs image file '%s'\n", imagePath);
|
||||
exit(1);
|
||||
|
|
Loading…
Reference in a new issue