ladybird/Kernel/Devices/FileBackedDiskDevice.h
Robin Burchell 0dc9af5f7e Add clang-format file
Also run it across the whole tree to get everything using the One True Style.
We don't yet run this in an automated fashion as it's a little slow, but
there is a snippet to do so in makeall.sh.
2019-05-28 17:31:20 +02:00

32 lines
986 B
C++

#pragma once
#include <AK/AKString.h>
#include <AK/RetainPtr.h>
#include <AK/Types.h>
#include <Kernel/Devices/DiskDevice.h>
#include <stdio.h>
class FileBackedDiskDevice final : public DiskDevice {
public:
static RetainPtr<FileBackedDiskDevice> create(String&& image_path, unsigned block_size);
virtual ~FileBackedDiskDevice() override;
bool is_valid() const { return m_file; }
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;
private:
virtual const char* class_name() const override;
bool read_internal(DiskOffset, unsigned length, byte* out) const;
bool write_internal(DiskOffset, unsigned length, const byte* data);
FileBackedDiskDevice(String&& imagePath, unsigned block_size);
String m_image_path;
FILE* m_file { nullptr };
DiskOffset m_file_length { 0 };
unsigned m_block_size { 0 };
};