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:
Floris Bos 2022-11-14 20:18:36 +01:00
parent 30225187bd
commit 142ddfc037
10 changed files with 1193 additions and 1 deletions

50
src/devicewrapper.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef DEVICEWRAPPER_H
#define DEVICEWRAPPER_H
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright (C) 2022 Raspberry Pi Ltd
*/
#include <QObject>
#include <QMap>
#include <QFile>
class DeviceWrapperBlockCacheEntry;
class DeviceWrapperFatPartition;
#ifdef Q_OS_WIN
#include "windows/winfile.h"
typedef WinFile DeviceWrapperFile;
#elif defined(Q_OS_DARWIN)
#include "mac/macfile.h"
typedef MacFile DeviceWrapperFile;
#else
typedef QFile DeviceWrapperFile;
#endif
class DeviceWrapper : public QObject
{
Q_OBJECT
public:
explicit DeviceWrapper(DeviceWrapperFile *file, QObject *parent = nullptr);
virtual ~DeviceWrapper();
void sync();
void pwrite(const char *buf, quint64 size, quint64 offset);
void pread(char *buf, quint64 size, quint64 offset);
DeviceWrapperFatPartition *fatPartition(int nr);
protected:
bool _dirty;
QMap<quint64,DeviceWrapperBlockCacheEntry *> _blockcache;
DeviceWrapperFile *_file;
void _readIntoBlockCacheIfNeeded(quint64 offset, quint64 size);
void _seekToBlock(quint64 blockNr);
signals:
};
#endif // DEVICEWRAPPER_H