2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2018-10-16 11:21:49 +02:00
|
|
|
#include "DiskDevice.h"
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/RetainPtr.h>
|
2018-12-04 00:27:16 +01:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2018-10-16 11:21:49 +02:00
|
|
|
class FileBackedDiskDevice final : public DiskDevice {
|
2018-10-10 11:53:07 +02:00
|
|
|
public:
|
2018-12-03 01:38:22 +01:00
|
|
|
static RetainPtr<FileBackedDiskDevice> create(String&& image_path, unsigned block_size);
|
2018-10-16 11:21:49 +02:00
|
|
|
virtual ~FileBackedDiskDevice() override;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-12-03 01:38:22 +01:00
|
|
|
bool is_valid() const { return m_file; }
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-12-03 01:38:22 +01:00
|
|
|
virtual unsigned block_size() const override;
|
|
|
|
|
virtual bool read_block(unsigned index, byte* out) const override;
|
|
|
|
|
virtual bool write_block(unsigned index, const byte*) override;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-11-15 15:36:35 +01:00
|
|
|
virtual const char* class_name() const override;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-12-03 01:38:22 +01:00
|
|
|
bool read_internal(DiskOffset, unsigned length, byte* out) const;
|
|
|
|
|
bool write_internal(DiskOffset, unsigned length, const byte* data);
|
2018-10-16 14:11:58 +02:00
|
|
|
|
2018-12-03 01:38:22 +01:00
|
|
|
FileBackedDiskDevice(String&& imagePath, unsigned block_size);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-12-03 01:38:22 +01:00
|
|
|
String m_image_path;
|
2018-10-10 11:53:07 +02:00
|
|
|
FILE* m_file { nullptr };
|
2018-12-03 01:38:22 +01:00
|
|
|
DiskOffset m_file_length { 0 };
|
|
|
|
|
unsigned m_block_size { 0 };
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|
|