Files
ladybird/VirtualFileSystem/FileBackedDiskDevice.h
Andreas Kling 8293a0ff36 Rework DiskDevice's read() and write() to be non-virtual wrappers.
This way subclasses only have to implement readBlock() and writeBlock().
read() and write() require that the offset and length are both divisible
by the blockSize().
2018-10-16 14:13:32 +02:00

34 lines
956 B
C++

#pragma once
#include "DiskDevice.h"
#include <AK/RetainPtr.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <stdio.h>
class FileBackedDiskDevice final : public DiskDevice {
public:
static RetainPtr<FileBackedDiskDevice> create(String&& imagePath, unsigned blockSize);
virtual ~FileBackedDiskDevice() override;
bool isValid() const { return m_file; }
virtual unsigned blockSize() const override;
virtual bool readBlock(unsigned index, byte* out) const override;
virtual bool writeBlock(unsigned index, const byte*) override;
private:
virtual const char* className() const override;
bool readInternal(qword offset, unsigned length, byte* out) const;
bool writeInternal(qword offset, unsigned length, const byte* data);
FileBackedDiskDevice(String&& imagePath, unsigned blockSize);
String m_imagePath;
FILE* m_file { nullptr };
qword m_fileLength { 0 };
unsigned m_blockSize { 0 };
};