Files
fmviewer3/project/fm_viewer/module/bmff.h
2026-02-21 17:11:31 +09:00

495 lines
25 KiB
C++

/*
bmff : Blackbox Media Works Format Free
jykang 20190923
*/
#ifndef _BMFF_H_
#define _BMFF_H_
#if (SUPPORT_FORMAT_FREE)
#define MH3000 1
#define MODEL_CONFIG MH3000
/*
============================================================
/mnt/app/bmff /dev/mmcblk0 sq1920 0 24 0 noaging noemmc mstar
============================================================
OpenDevice OK.../dev/mmcblk0
mblocks = 31090688(15181MiB) , SD1: 31101840, SD2: 31085775
serial number = 0xdeadface
FAT total sectors = 0
sectors per FAT = 0
================================================================
frontHeight = 1920, rearHeight = 0
frontFileSize = 120Mb, rearFileSize = 0Mb
frontParkFileSize = 0Mb, rearParkFileSize = 0Mb
frontEventFileSize = 120Mb, rearEventFileSize = 0Mb
================================================================
NF_Clusters:3840, NR_Clusters:0, EF_Clusters:3840, ER_Clusters:0, PF_Clusters:0, PR_Clusters=0
OpenDevice OK.../dev/mmcblk0
mblocks = 31090688(15181MiB)
DataSectors = 31080832, DataClusters = 485638, SectorsPerFat = 3840
AvailableDataClusters = 483332, ScrapsClusters = 3332
NormalPercent = 88%, EventPercent = 12%, ManualPercent = 0%, ParkingNormalPercent = 0%, ParkingEventPercent = 0%
TotalNormalFileClusters = 422400, TotalEventFileClusters = 57600, TotalManualFileClusters = 0, TotalParkingNormalFileClusters = 0, T
otalParkingEventFileClusters = 0
NormalFiles = 110, EventFiles = 15, ManualFiles = 0, ParkingNormalFiles = 0, ParkingEventFiles = 0
NormalRecords = 110, EventRecords = 15, ManualRecords = 0, ParkingNormalRecords = 0, ParkingEventRecords = 0
NormalDirectoryClusters = 1, EventDirectoryClusters = 1
RootDirectoryStartCluster = 2, clusters = 1
LogDirectoryStartCluster = 3, clusters = 1
LogFilesStartCluster = 4, clusters = 288
ParkingDirectoryStartCluster = 292, clusters = 0
NormalDirectoryStartCluster = 292, clusters = 1
EventDirectoryStartCluster = 293, clusters = 1
ManualDirectoryStartCluster = 294, clusters = 1
ParkingNormalDirectoryStartCluster = 295, clusters = 0
ParkingEventDirectoryStartCluster = 295, clusters = 0
RootDirectoryStartSector = 9856
LogDirectoryStartSector = 9920
LogFilesStartSector = 9984
ParkingDirectoryStartSector = 28416
NormalDirectoryStartSector = 28416
EventDirectoryStartSector = 28480
ManualDirectoryStartSector = 28544
ParkingNormalDirectoryStartSector = 28608
ParkingEventDirectoryStartSector = 28608
serial number = 0xdeadface
FAT total sectors = 31088640
sectors per FAT = 3840
OpenDevice OK.../dev/mmcblk0
MBR write OK...
Free Clusters = 5346
OpenDevice OK.../dev/mmcblk0
*/
// https://github.com/sryze/wdd/blob/master/src/wdd.c
#include <stdio.h>
#include <fcntl.h>
#ifdef WIN32
#include <QString>
#include <Windows.h>
#include <stdint.h>
#else // WIN32
#include <unistd.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif // WIN32
#include <string>
using std::string;
#define MIN_SECTORS 0xec000 // 8GB == 0x1000000 ???
#define MAX_SECTORS 0x80000000 // 1TB
#define SECTOR_SIZE 512
// #define SECTORS_PER_CLUSTER 128
#define SECTORS_PER_CLUSTER 64
#define CLUSTER_SIZE (SECTORS_PER_CLUSTER * SECTOR_SIZE)
#define FAT_RESERVED_SECTORS (128)
#define FAT_BOOT_SECTOR_COPY_POSITION 6
#define SPF_UNIT 0x80
#define ACTIVE_PARTITION_FLAG 0
#define FILE_SYSTEM_ID 0xc
// #define FIRST_SECTOR (2048)
#define SIGNATURE 0xaa55
#define BM_SERIAL_NUMBER 0xdeadface
#define BM_FACTORY_SERIAL_NUMBER 0xdeadfac2
#define MBR_DISK_SERIAL_NUMBER(mbr) (*((unsigned int *)((char*)(mbr) + 0x1b8)))
#define MBR_SIGNATURE(mbr) (*((unsigned short *)((char*)(mbr) + 0x1fe)))
#define PARTITION_TABLE_PTR(mbr,index) ((char*)(mbr) + 0x1be + (0x10 * (index)))
#define PT_ACTIVE_PARTITION_FLAG(mbr,index) (*PARTITION_TABLE_PTR(mbr,index))
#define PT_FILE_SYSTEM_ID(mbr,index) (*(PARTITION_TABLE_PTR(mbr,index) + 4))
#define PT_FIRST_SECTOR(mbr,index) (*(unsigned int *)(PARTITION_TABLE_PTR(mbr,index) + 8))
#define PT_TOTAL_SECTORS(mbr,index) (*(unsigned int *)(PARTITION_TABLE_PTR(mbr,index) + 12))
#define BS_OEM_ID_POS(bs) ((char*)(bs) + 0x3)
#define BS_OEM_ID_SIZE 8
#define BS_BYTES_PER_SECTOR(bs) (*(unsigned short *)((char*)(bs) + 0xb))
#define BS_SECTORS_PER_CLUSTER(bs) (*(unsigned char *)((char*)(bs) + 0xd))
#define BS_RESERVED_SECTORS(bs) (*(unsigned short *)((char*)(bs) + 0xe))
#define BS_TOTAL_SECTORS(bs) (*(unsigned int *)((char*)(bs) + 0x20))
#define BS_SECTORS_PER_FAT(bs) (*(unsigned int *)((char*)(bs) + 0x24))
#define SIS_SIGNATURE_FIRST(sis) (*(unsigned int *)((char*)(sis) + 0x0))
#define SIS_SIGNATURE_MIDDLE(sis) (*(unsigned int *)((char*)(sis) + 0x1e4))
#define SIS_LAST_FREE_CLUSTER(sis) (*(unsigned int *)((char*)(sis) + 0x1e8))
#define SIS_LAST_ALLOCATED_CLUSTER(sis) (*(unsigned int *)((char*)(sis) + 0x1ec))
#define SIS_SIGNATURE_LAST(sis) (*(unsigned int *)((char*)(sis) + 0x1fc))
#define DIRECTORY_OVERHEAD (0xc0)
#define LOG_DIRECTORY "SYSTEM "
#define NORMAL_DIRECTORY "NORMAL "
#define EVENT_DIRECTORY "EVENT "
#define MANUAL_DIRECTORY "MANUAL "
#define PARKING_DIRECTORY "PARKING "
#define SYSTEM_DIRECTORY "SYSTEM "
#define PARKING_NORMAL_DIRECTORY "NORMAL "
#define PARKING_EVENT_DIRECTORY "EVENT "
#define NORMAL_FRONT_FILE ".NORM_FRON_"
#define NORMAL_REAR_FILE ".NORM_REAR_"
#define EVENT_FRONT_FILE ".EVEN_FRON_"
#define EVENT_REAR_FILE ".EVEN_REAR_"
#define MANUAL_FRONT_FILE ".MANU_FRON_"
#define MANUAL_REAR_FILE ".MANU_REAR_"
#define PARKING_FRONT_FILE ".PARK_FRON_"
#define PARKING_REAR_FILE ".PARK_REAR_"
#define LOG_SYSTEM0_FILE "HISTORY DM0"
#define LOG_SYSTEM1_FILE "HISTORY DM1"
#define LOG_SYSTEM2_FILE "HISTORY DM2"
#define LOG_RECORD0_FILE "RECORD DM0"
#define LOG_RECORD1_FILE "RECORD DM1"
#define PARAM_FILE "PARAM ENC"
#define MiB (1024 * 1024)
#define KiB (1024)
#define FREE_SPACE_CLUSTERS (1600) // 100MiB
#if (MODEL_CONFIG == FRC)
#define FILE_OVERHEAD_MIB (0)
#else
#define FILE_OVERHEAD_MIB (4)
#endif
#define GET_FILE_SIZE_BY_SEC(fs60, sec) ((((fs60 / MiB) - FILE_OVERHEAD_MIB) * (sec) / 60 + FILE_OVERHEAD_MIB) * MiB)
#if (USE_H265 == 0)
#define WQHD30_FILE_SIZE ((105 * 210 / 100) * MiB)
#define WQHD27_FILE_SIZE ((96 * 210 / 100) * MiB)
#define WQHD25_FILE_SIZE ((90 * 210 / 100) * MiB)
#define WQHD22_FILE_SIZE ((79 * 210 / 100) * MiB)
#define WQHD16_FILE_SIZE ((60 * 210 / 100) * MiB)
#define WQHD07_FILE_SIZE ((31 * 210 / 100) * MiB)
#define WQHD06_FILE_SIZE ((30 * 210 / 100) * MiB)
#define SQ1920_30_FILE_SIZE ((105 * 210 / 100) * MiB)
#define SQ1920_27_FILE_SIZE ((96 * 210 / 100) * MiB)
#define SQ1920_25_FILE_SIZE (SQ1600_25_FILE_SIZE)
#define SQ1920_22_FILE_SIZE ((79 * 210 / 100) * MiB)
#define SQ1920_16_FILE_SIZE ((60 * 210 / 100) * MiB)
#define SQ1920_07_FILE_SIZE ((31 * 210 / 100) * MiB)
#define SQ1920_06_FILE_SIZE ((30 * 210 / 100) * MiB)
#define SHD30_FILE_SIZE ((92 * 210 / 100) * MiB)
#define SHD27_FILE_SIZE ((84 * 210 / 100) * MiB)
#define SHD25_FILE_SIZE ((78 * 210 / 100) * MiB)
#define SHD22_FILE_SIZE ((69 * 210 / 100) * MiB)
#define SHD16_FILE_SIZE ((54 * 210 / 100) * MiB)
#define SHD07_FILE_SIZE ((27 * 210 / 100) * MiB)
#define SHD06_FILE_SIZE ((26 * 210 / 100) * MiB)
#define SQ1600_30_FILE_SIZE ((92 * 210 / 100) * MiB)
#define SQ1600_27_FILE_SIZE ((84 * 210 / 100) * MiB)
// #define SQ1600_25_FILE_SIZE ((78 * 210 / 100) * MiB)
#define SQ1600_25_FILE_SIZE (120 * MiB)
#define SQ1600_22_FILE_SIZE ((69 * 210 / 100) * MiB)
#define SQ1600_16_FILE_SIZE ((54 * 210 / 100) * MiB)
#define SQ1600_07_FILE_SIZE ((27 * 210 / 100) * MiB)
#define SQ1600_06_FILE_SIZE ((26 * 210 / 100) * MiB)
// #define FHD30_FILE_SIZE ((69 * 210 / 100) * MiB)
#define FHD30_FILE_SIZE (108 * MiB)
// #define FHD27_FILE_SIZE /*((63 * 210 / 100) * MiB)*/
#define FHD27_FILE_SIZE (96 * MiB)
#define FHD25_FILE_SIZE ((60 * 210 / 100) * MiB)
#define FHD22_FILE_SIZE ((54 * 210 / 100) * MiB)
#define FHD16_FILE_SIZE ((42 * 210 / 100) * MiB)
#define FHD07_FILE_SIZE ((21 * 210 / 100) * MiB)
#define FHD06_FILE_SIZE ((20 * 210 / 100) * MiB)
#define HD30_FILE_SIZE ((36 * 210 / 100) * MiB)
// #define HD27_FILE_SIZE ((32 * 210 / 100) * MiB)
#define HD27_FILE_SIZE (53 * MiB)
#define HD25_FILE_SIZE ((31 * 210 / 100) * MiB)
#define HD22_FILE_SIZE ((27 * 210 / 100) * MiB)
#define HD16_FILE_SIZE ((21 * 210 / 100) * MiB)
#define HD07_FILE_SIZE ((14 * 210 / 100) * MiB)
#define HD06_FILE_SIZE (HD07_FILE_SIZE)
#else
// #define WQHD30_FILE_SIZE ((71 * 210 / 100) * MiB) // 9.3Mbps
#define WQHD30_FILE_SIZE ((68 * 210 / 100) * MiB) // 9.3Mbps
#define WQHD27_FILE_SIZE ((64 * 210 / 100) * MiB) // 8.4Mbps
#define WQHD25_FILE_SIZE ((60 * 210 / 100) * MiB) // 7.8Mbps
#define WQHD22_FILE_SIZE ((53 * 210 / 100) * MiB) // 6.8Mbps
#define WQHD16_FILE_SIZE ((40 * 210 / 100) * MiB) // 5.0Mbps
#define WQHD07_FILE_SIZE ((21 * 210 / 100) * MiB) // 2.2Mbps
#define WQHD06_FILE_SIZE ((20 * 210 / 100) * MiB) // 2.0Mbps
#define SQ1920_30_FILE_SIZE ((68 * 210 / 100) * MiB)
#define SQ1920_27_FILE_SIZE ((64 * 210 / 100) * MiB)
#define SQ1920_25_FILE_SIZE ((60 * 210 / 100) * MiB)
#define SQ1920_22_FILE_SIZE ((53 * 210 / 100) * MiB)
#define SQ1920_16_FILE_SIZE ((40 * 210 / 100) * MiB)
#define SQ1920_07_FILE_SIZE ((21 * 210 / 100) * MiB)
#define SQ1920_06_FILE_SIZE ((20 * 210 / 100) * MiB)
#define SHD30_FILE_SIZE ((62 * 210 / 100) * MiB) // 8.1Mbps
#define SHD27_FILE_SIZE ((56 * 210 / 100) * MiB) // 7.3Mbps
#define SHD25_FILE_SIZE ((52 * 210 / 100) * MiB) // 6.8Mbps
#define SHD22_FILE_SIZE ((47 * 210 / 100) * MiB) // 6.0Mbps
#define SHD16_FILE_SIZE ((36 * 210 / 100) * MiB) // 4.3Mbps
#define SHD07_FILE_SIZE ((19 * 210 / 100) * MiB) // 1.9Mbps
#define SHD06_FILE_SIZE ((18 * 210 / 100) * MiB) // 1.7Mbps
#define SQ1600_30_FILE_SIZE SHD30_FILE_SIZE
#define SQ1600_27_FILE_SIZE SHD27_FILE_SIZE
#define SQ1600_25_FILE_SIZE SHD25_FILE_SIZE
#define SQ1600_22_FILE_SIZE SHD22_FILE_SIZE
#define SQ1600_16_FILE_SIZE SHD16_FILE_SIZE
#define SQ1600_07_FILE_SIZE SHD07_FILE_SIZE
#define SQ1600_06_FILE_SIZE SHD06_FILE_SIZE
#define FHD30_FILE_SIZE ((47 * 210 / 100) * MiB) // 6.0Mbps
#define FHD27_FILE_SIZE ((43 * 210 / 100) * MiB) // 5.4Mbps
#define FHD25_FILE_SIZE ((40 * 210 / 100) * MiB) // 5.0Mbps
#define FHD22_FILE_SIZE ((36 * 210 / 100) * MiB) // 4.4Mbps
#define FHD16_FILE_SIZE ((28 * 210 / 100) * MiB) // 3.2Mbps
#define FHD07_FILE_SIZE ((15 * 210 / 100) * MiB) // 1.4Mbps
#define FHD06_FILE_SIZE ((14 * 210 / 100) * MiB) // 1.2Mbps
#define HD30_FILE_SIZE ((24 * 210 / 100) * MiB) // 2.7Mbps
#define HD27_FILE_SIZE ((22 * 210 / 100) * MiB) // 2.4Mbps
#define HD25_FILE_SIZE ((21 * 210 / 100) * MiB) // 2.2Mbps
#define HD22_FILE_SIZE ((19 * 210 / 100) * MiB) // 2.0Mbps
#define HD16_FILE_SIZE ((15 * 210 / 100) * MiB) // 1.4Mbps
#define HD07_FILE_SIZE ((10 * 210 / 100) * MiB) // 0.62Mbps
#define HD06_FILE_SIZE (HD07_FILE_SIZE) // 0.62Mbps
#endif
// #define WQHD30_FILE_SIZE ((103 * 210 / 100) * MiB) // 9.3Mbps
// #define WQHD27_FILE_SIZE ((93 * 210 / 100) * MiB) // 8.4Mbps
// #define WQHD22_FILE_SIZE ((77 * 210 / 100) * MiB) // 6.8Mbps
// #define WQHD16_FILE_SIZE ((57 * 210 / 100) * MiB) // 5.0Mbps
// #define WQHD07_FILE_SIZE ((28 * 210 / 100) * MiB) // 2.2Mbps
// #define SHD30_FILE_SIZE ((84 * 210 / 100) * MiB) // 8.1Mbps
// #define SHD27_FILE_SIZE ((76 * 210 / 100) * MiB) // 7.3Mbps
// #define SHD22_FILE_SIZE ((63 * 210 / 100) * MiB) // 6.0Mbps
// #define SHD16_FILE_SIZE ((47 * 210 / 100) * MiB) // 4.3Mbps
// #define SHD07_FILE_SIZE ((23 * 210 / 100) * MiB) // 1.9Mbps
// #define FHD30_FILE_SIZE ((60 * 210 / 100) * MiB) // 6.0Mbps
// #define FHD27_FILE_SIZE ((54 * 210 / 100) * MiB) // 5.4Mbps
// #define FHD22_FILE_SIZE ((45 * 210 / 100) * MiB) // 4.4Mbps
// #define FHD16_FILE_SIZE ((34 * 210 / 100) * MiB) // 3.2Mbps
// #define FHD07_FILE_SIZE ((18 * 210 / 100) * MiB) // 1.4Mbps
// #define HD30_FILE_SIZE ((29 * 210 / 100) * MiB) // 2.7Mbps
// #define HD27_FILE_SIZE ((27 * 210 / 100) * MiB) // 2.4Mbps
// #define HD22_FILE_SIZE ((23 * 210 / 100) * MiB) // 2.0Mbps
// #define HD16_FILE_SIZE ((18 * 210 / 100) * MiB) // 1.4Mbps
// #define HD07_FILE_SIZE ((11 * 210 / 100) * MiB) // 0.62Mbps
#define LOG0_FILE_SIZE (4 * MiB)
#define LOG1_FILE_SIZE (4 * MiB)
#define LOG2_FILE_SIZE (1 * MiB)
#define PARAM_FILE_SIZE (128 * SECTOR_SIZE)
int GetPhysicalDrive(WCHAR DL);
class BmFF
{
public:
BmFF();
int Init(const char *device, int normalFrontFileSize, int normalRearFileSize,
int eventFrontFileSize, int eventRearFileSize, int parkFrontFileSize, int parkRearFileSize);
// int Init2(const char *device, int frontHeight, int rearHeight, int frontFps);
int Init2(const char *device, int frontHeight, int rearHeight, int frontFps, int parkFps);
void SetEmmc(void) {mEmmc = true; FIRST_SECTOR = 0;}
void SetMstarPark(void) {mMstarPark = true;}
int MakeDisk(void);
bool VerifyDisk(void);
int InvalidateDisk(void);
void SetStoragePercent(bool park);
char GetFileSystem();
void ZeroBlocks(int startSector, int nSectors);
// bool RenameRecordFile(string srcFileName, string trgFileName);
bool mNoPrintFlag;// = false;
bool IsFactoryAging(void) { return mSerialNumber == BM_FACTORY_SERIAL_NUMBER; }
bool IsRecovered() {return mRecovered;}
public:
//OVERLAPPED mOV;
int FIRST_SECTOR;// = 2048;
bool mMstarPark;// = false;
bool mEmmc;// = false;
unsigned long mBlocks;
unsigned long mPtTotalSectors;
int mSectorsPerFat;
int mDataTotalClusters;
#ifdef WIN32
HANDLE mFd;
QString mDeviceName;
#else // WIN32
int mFd;
string mDeviceName;
#endif // WIN32
char mRdMasterBootRecord[SECTOR_SIZE];
char mRdFat32BootSector[SECTOR_SIZE];
char mRdSystemInformationSector[SECTOR_SIZE];
char mWrMasterBootRecord[SECTOR_SIZE];
char mWrFat32BootSector[SECTOR_SIZE];
char mWrSystemInformationSector[SECTOR_SIZE];
unsigned long mSerialNumber;// = 0;
bool mMakeFactoryAging;// = false;
int mRootDirectoryStartSector;
int mLogDirectoryStartSector;
int mLogFilesStartSector;
int mNormalDirectoryStartSector;
int mEventDirectoryStartSector;
int mManualDirectoryStartSector;
int mParkingDirectoryStartSector;
int mParkingNormalDirectoryStartSector;
int mParkingEventDirectoryStartSector;
int mRootDirectoryStartCluster;// = 2;
int mLogDirectoryStartCluster;
int mLogFilesStartCluster;
int mNormalDirectoryStartCluster;
int mEventDirectoryStartCluster;
int mManualDirectoryStartCluster;
int mParkingDirectoryStartCluster;
int mParkingNormalDirectoryStartCluster;
int mParkingEventDirectoryStartCluster;
int mRootDirectoryClusters;// = 1;
int mLogDirectoryClusters;// = 1;
int mNormalDirectoryClusters;
int mEventDirectoryClusters;
int mManualDirectoryClusters;
int mParkingDirectoryClusters;
int mParkingNormalDirectoryClusters;
int mParkingEventDirectoryClusters;
int mNormalFiles;
int mEventFiles;
int mManualFiles;
int mParkingNormalFiles;
int mParkingEventFiles;
int mNormalRecords;
int mEventRecords;
int mManualRecords;
int mParkingNormalRecords;
int mParkingEventRecords;
int mNormalFrontFileClusters;
int mNormalRearFileClusters;
int mEventFrontFileClusters;
int mEventRearFileClusters;
int mManualFrontFileClusters;
int mManualRearFileClusters;
int mParkingFrontFileClusters;
int mParkingRearFileClusters;
unsigned int mCurrentFatOffset;
unsigned int *mMemFat;
char *mMemRootDirectory;
char *mMemLogDirectory;
char *mMemNormalDirectory;
char *mMemEventDirectory;
char *mMemManualDirectory;
char *mMemParkingDirectory;
char *mMemParkingNormalDirectory;
char *mMemParkingEventDirectory;
unsigned int mFlushStartOffset;
int mNormalPercent;// = 60;
int mEventPercent;// = 15;
int mManualPercent;// = 5;
int mParkingNormalPercent;// = 18;
int mParkingEventPercent;// = 2;
bool mRecoverFlag;// = false;
bool mFormatFlag;// = false;
bool mRecovered;// = false;
protected:
int OpenDevice(bool bWrite);
void CloseDevice(void);
void AllocMem(void);
void FreeMem(void);
int GetBlocks(void);
int GetBlocksFirst(void);
int GetMBR(void);
int GetFATBS(void);
int GetFAT(void);
void CalcFat(void);
void HexDump(char *buff, int size);
int ChkMBR(void);
int ChkPT(void);
int UpdateInfo(void);
int UpdateInfoFirst(void);
void MakeMBR(void);
void MakeFATBS(void);
void MakeSIS(void);
void MakeRootDirectory(void);
void MakeLogDirectory(void);
void MakeParkingDirectory(void);
void MakeRecordDirectory(char *data, int directoryStartCluster,
const char *fileFullNameFront, const char *fileName83Front, const char *fileFullNameRear, const char *fileName83Rear,
int nRecords, int frontFileClusters, int rearFileClusters, int parentStartCluster);
int WriteAll(void);
void MakeMemDirectories(void);
int WriteDirectories(void);
int WriteSectors(char *data, unsigned int startSector, unsigned int sectors);
void AddFatElement(unsigned int *pFatBuff, int size);
void SetFatElement(unsigned int *pFatBuff, unsigned int startCluster, int size);
void SetDirFirstCluster(char *pDirBuff, unsigned int cluster);
void SetDirFirstClusterLong(char *pDirBuff, unsigned int cluster);
void SetDirFileAttribute(char *pDirBuff, unsigned char attribute);
void SetDirFileAttributeLong(char *pDirBuff, unsigned char attribute);
void SetDirFileSize(char *pDirBuff, unsigned int fileSize);
void SetDirFileSizeLong(char *pDirBuff, unsigned int fileSize);
void SetDirFileName(char *pDirBuff, const char *fileName83);
void SetDirFileNameLong(char *pDirBuff, const char *fileName83, const char *fileFullName);
unsigned char FileNameChecksum(const char *fileName83);
void UTF8CharCopy(char *target_u, const char *source_c, int size);
void CharUTF8Copy(char *target_c, const char *source_u, int size);
void GetDirFirstCluster(char *pDirBuff, unsigned int &cluster);
void GetDirFirstClusterLong(char *pDirBuff, unsigned int &cluster);
void GetDirFileAttribute(char *pDirBuff, unsigned char &attribute);
void GetDirFileAttributeLong(char *pDirBuff, unsigned char &attribute);
void GetDirFileSize(char *pDirBuff, unsigned int &fileSize);
void GetDirFileSizeLong(char *pDirBuff, unsigned int &fileSize);
void GetDirFileName(char *pDirBuff, char *fileName83);
void GetDirFileNameLong(char *pDirBuff, char *fileName83, char *fileFullName);
bool VerifyMBR(void);
bool VerifyFATBS(void);
bool VerifyFAT(void);
bool VerifyDirectories(void);
bool VerifyRootDirectory(char *buff);
bool VerifyLogDirectory(char *buff);
bool VerifyParkingDirectory(char *buff);
bool VerifyRecordDirectory(char *buff, int buffSize, char *headNameHidden, char *headNameNormmal, int nRecords, int frontFileClusters, int rearFileClusters);
bool ReadSectors(char *data, unsigned int startSector, unsigned int sectors);
void ForceFlush(void);
//#ifdef WIN32
// QString ReadFileName(int cluster);
// void WriteFileName(QString fname, int cluster);
// bool GetDirStartAndSectors(QString fileName, int &startSector, int &nSectors, int &nFiles);
//#else // WIN32
string ReadFileName(int cluster);
void WriteFileName(string fname, int cluster);
bool GetDirStartAndSectors(string fileName, int &startSector, int &nSectors, int &nFiles);
//#endif // WIN32
int RecoverDirectories(void);
int GetFileSize(int height, int fps);
};
#endif
#endif // #if (SUPPORT_FORMAT_FREE)