-
Notifications
You must be signed in to change notification settings - Fork 2
/
FAT16.cpp
33 lines (29 loc) · 991 Bytes
/
FAT16.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
#include "FAT16.h"
#include <iostream>
#include "windows.h"
#include "stdio.h"
using namespace std;
bool FAT16::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 sectorSize = (pBootRecord->sectorSize[1] << 8) | pBootRecord->sectorSize[0];
unsigned int countSectors = static_cast<int>(pBootRecord->clasterSize[0]);
clusterSize = sectorSize * countSectors;
return true;
}