mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
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.
54 lines
1.9 KiB
C++
54 lines
1.9 KiB
C++
#ifndef DEVICEWRAPPERFATPARTITION_H
|
|
#define DEVICEWRAPPERFATPARTITION_H
|
|
|
|
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
* Copyright (C) 2022 Raspberry Pi Ltd
|
|
*/
|
|
|
|
#include "devicewrapperpartition.h"
|
|
#include <QObject>
|
|
#include <QDate>
|
|
#include <QTime>
|
|
|
|
enum fatType { FAT12, FAT16, FAT32, EXFAT };
|
|
struct dir_entry;
|
|
|
|
class DeviceWrapperFatPartition : public DeviceWrapperPartition
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
DeviceWrapperFatPartition(DeviceWrapper *dw, quint64 partStart, quint64 partLen, QObject *parent = nullptr);
|
|
|
|
QByteArray readFile(const QString &filename);
|
|
void writeFile(const QString &filename, const QByteArray &contents);
|
|
bool fileExists(const QString &filename);
|
|
|
|
protected:
|
|
enum fatType _type;
|
|
uint32_t _firstFatStartOffset, _fatSize, _bytesPerCluster, _clusterOffset;
|
|
uint32_t _fat16_rootDirSectors, _fat16_firstRootDirSector;
|
|
uint32_t _fat32_firstRootDirCluster, _fat32_currentRootDirCluster;
|
|
uint16_t _bytesPerSector, _fat32_fsinfoSector;
|
|
QList<uint32_t> _fatStartOffset;
|
|
|
|
QList<uint32_t> getClusterChain(uint32_t firstCluster);
|
|
void setFAT16(uint16_t cluster, uint16_t value);
|
|
void setFAT32(uint32_t cluster, uint32_t value);
|
|
void setFAT(uint32_t cluster, uint32_t value);
|
|
uint32_t getFAT(uint32_t cluster);
|
|
void seekCluster(uint32_t cluster);
|
|
uint32_t allocateCluster();
|
|
uint32_t allocateCluster(uint32_t previousCluster);
|
|
bool getDirEntry(const QString &longFilename, struct dir_entry *entry, bool createIfNotExist = false);
|
|
bool dirNameExists(const QByteArray dirname);
|
|
void updateDirEntry(struct dir_entry *dirEntry);
|
|
void writeDirEntryAtCurrentPos(struct dir_entry *dirEntry);
|
|
void openDir();
|
|
bool readDir(struct dir_entry *result);
|
|
void updateFSinfo(int deltaClusters, uint32_t nextFreeClusterHint);
|
|
uint16_t QTimeToFATtime(const QTime &time);
|
|
uint16_t QDateToFATdate(const QDate &date);
|
|
};
|
|
|
|
#endif // DEVICEWRAPPERFATPARTITION_H
|