-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFAT32.cpp
35 lines (31 loc) · 1.14 KB
/
FAT32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "FAT32.h"
#include <iostream>
#include "windows.h"
#include "stdio.h"
using namespace std;
bool FAT32::ReadClusterSize()
{
BYTE sector[512];
DWORD bytesRead;
DWORD bytesToRead = sizeof(sector);
LARGE_INTEGER sectorSizeOffset;
sectorSizeOffset.QuadPart = 0;
if (!SetFilePointerEx(fileHandler, sectorSizeOffset, NULL, FILE_BEGIN)) {
throw std::invalid_argument("Set FilePointer error");
CloseHandle(fileHandler);
return false;
}
if (!ReadFile(fileHandler, sector, bytesToRead, &bytesRead, NULL))
{
throw std::invalid_argument("ReadFile error");
CloseHandle(fileHandler);
return false;
}
BootRecord* pBootRecord = reinterpret_cast<BootRecord*>(sector);
unsigned int bytesPerSector = (pBootRecord->bytesPerSector[1] << 8) | pBootRecord->bytesPerSector[0];
unsigned int sectorsPerCluster = pBootRecord->sectorsPerCluster;
clusterSize = bytesPerSector * sectorsPerCluster;
return true;
}
//èçìåíåíû èìåíà ïîëåé ñòðóêòóðû BootRecord
//èçìåíåíà ëîãèêà ðàñ÷åòà ðàçìåðà êëàñòåðà: ïðîèçâåäåíèå êîë-âà áàéòîâ â ñåêòîðå íà êîë-âî ñåêòîðîâ â îäíîì êëàñòåðå