mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
Add classes for mounting FAT16/32 without help from OS
Minimal implementation for reading/writing files in the root directory of a FAT16/FAT32 file system. Can read/write from raw disk devices, and no longer relies on operating system support for mounting the file system. Currently assumes Imager will always be run on 'little endian' architectures such as Intel and ARM (at least under Linux). If there is a use-case for big-endian (anybody still using Sparc?) this may be revisited later.
This commit is contained in:
parent
30225187bd
commit
142ddfc037
10 changed files with 1193 additions and 1 deletions
54
src/devicewrapperpartition.cpp
Normal file
54
src/devicewrapperpartition.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (C) 2022 Raspberry Pi Ltd
|
||||
*/
|
||||
|
||||
#include "devicewrapperpartition.h"
|
||||
#include "devicewrapper.h"
|
||||
|
||||
DeviceWrapperPartition::DeviceWrapperPartition(DeviceWrapper *dw, quint64 partStart, quint64 partLen, QObject *parent)
|
||||
: QObject{parent}, _dw(dw), _partStart(partStart), _partLen(partLen), _offset(partStart)
|
||||
{
|
||||
_partEnd = _partStart + _partLen;
|
||||
}
|
||||
|
||||
DeviceWrapperPartition::~DeviceWrapperPartition()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeviceWrapperPartition::read(char *data, qint64 size)
|
||||
{
|
||||
if (_offset+size > _partEnd)
|
||||
{
|
||||
throw std::runtime_error("Error: trying to read beyond partition");
|
||||
}
|
||||
|
||||
_dw->pread(data, size, _offset);
|
||||
_offset += size;
|
||||
}
|
||||
|
||||
void DeviceWrapperPartition::seek(qint64 pos)
|
||||
{
|
||||
if (pos > _partLen)
|
||||
{
|
||||
throw std::runtime_error("Error: trying to seek beyond partition");
|
||||
}
|
||||
_offset = pos+_partStart;
|
||||
}
|
||||
|
||||
qint64 DeviceWrapperPartition::pos() const
|
||||
{
|
||||
return _offset-_partStart;
|
||||
}
|
||||
|
||||
void DeviceWrapperPartition::write(const char *data, qint64 size)
|
||||
{
|
||||
if (_offset+size > _partEnd)
|
||||
{
|
||||
throw std::runtime_error("Error: trying to write beyond partition");
|
||||
}
|
||||
|
||||
_dw->pwrite(data, size, _offset);
|
||||
_offset += size;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue