2023-01-03 21:18:18 -05:00
|
|
|
#include "ApaReader.h"
|
2023-01-06 13:47:25 -05:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
2023-01-03 21:18:18 -05:00
|
|
|
#include "HddDefs.h"
|
|
|
|
|
|
|
|
using namespace Hdd;
|
|
|
|
|
|
|
|
CApaReader::CApaReader(Framework::CStream& stream)
|
2023-01-06 12:26:39 -05:00
|
|
|
: m_stream(stream)
|
2023-01-03 21:18:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-29 13:59:26 -05:00
|
|
|
std::vector<APA_HEADER> CApaReader::GetPartitions()
|
|
|
|
{
|
|
|
|
std::vector<APA_HEADER> result;
|
|
|
|
uint32_t lba = 0;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
APA_HEADER header;
|
|
|
|
m_stream.Seek(lba * g_sectorSize, Framework::STREAM_SEEK_SET);
|
|
|
|
m_stream.Read(&header, sizeof(APA_HEADER));
|
|
|
|
assert(header.magic == APA_HEADER_MAGIC);
|
|
|
|
result.push_back(header);
|
|
|
|
lba = header.next;
|
|
|
|
if(lba == 0) break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-01-04 19:36:29 -05:00
|
|
|
bool CApaReader::TryFindPartition(const char* partitionId, APA_HEADER& partitionHeader)
|
2023-01-03 21:18:18 -05:00
|
|
|
{
|
|
|
|
uint32_t lba = 0;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
APA_HEADER header;
|
|
|
|
m_stream.Seek(lba * g_sectorSize, Framework::STREAM_SEEK_SET);
|
|
|
|
m_stream.Read(&header, sizeof(APA_HEADER));
|
|
|
|
assert(header.magic == APA_HEADER_MAGIC);
|
|
|
|
if(!strcmp(header.id, partitionId))
|
|
|
|
{
|
2023-01-04 19:36:29 -05:00
|
|
|
partitionHeader = header;
|
|
|
|
return true;
|
2023-01-03 21:18:18 -05:00
|
|
|
}
|
|
|
|
lba = header.next;
|
|
|
|
if(lba == 0) break;
|
|
|
|
}
|
2023-01-04 19:36:29 -05:00
|
|
|
return false;
|
2023-01-03 21:18:18 -05:00
|
|
|
}
|