Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/modules/Disk/GUIDPartition.cpp

Source at commit 1297 created 12 years 8 months ago.
By meklort, Removed libsaioh from all modules. Removed i386 includes from modules.
1/*
2 * Copyright (c) 2011 Evan Lojewski. All rights reserved.
3 *
4 */
5#include <GUIDPartition.hpp>
6#include <Disk.hpp>
7
8
9GUIDPartition::GUIDPartition(Disk* disk, UInt8 partitionNumber) : Partition(disk, partitionNumber)
10{
11 UInt32 entrySize = 0;
12
13 mDisk = disk;
14 mNumSectors = 0;
15 mBeginSector = 0;
16 mPartitionNumber = partitionNumber;
17 mNumPartitions = 0;
18
19 if(mDisk)
20 {
21 // read in lba1, this contains the partition map if it's GPT
22 mDisk->Read(1, 1, mLBABUffer);
23 mGPTHeader = (GPTHeader*)mLBABUffer;
24 entrySize = mGPTHeader->hdr_entsz;
25
26 }
27 else
28 {
29 mGPTHeader = NULL;
30 }
31
32 if(isGPTDisk())
33 {
34 mNumPartitions = mGPTHeader->hdr_entries;
35 }
36
37 mGPTHeader = NULL;
38
39 if(entrySize && mPartitionNumber >= 0 && mPartitionNumber < mNumPartitions)
40 {
41 mDisk->Read(2 + (mPartitionNumber / 4), 1, mLBABUffer);
42
43 UInt32 offset = (mPartitionNumber % 4) * entrySize;
44
45 mGPTEntry = (GPTEntry*) mLBABUffer + offset;
46
47 // TODO: verify partition type != NULL
48
49 mNumSectors = (mGPTEntry->ent_lba_end - mGPTEntry->ent_lba_start) + 1;
50 mBeginSector = mGPTEntry->ent_lba_start;
51 //mUUID = mGPTEntry->ent_uuid;
52 }
53}
54
55GUIDPartition::~GUIDPartition()
56{
57
58}
59
60
61bool GUIDPartition::isGPTDisk()
62{
63 static bool status = false;
64
65 if(status) return status;
66
67 if(!mGPTHeader) return false;
68
69 if(mGPTHeader->hdr_sig[0] == 'E' &&
70 mGPTHeader->hdr_sig[1] == 'F' &&
71 mGPTHeader->hdr_sig[2] == 'I' &&
72 mGPTHeader->hdr_sig[3] == ' ' &&
73 mGPTHeader->hdr_sig[4] == 'P' &&
74 mGPTHeader->hdr_sig[5] == 'A' &&
75 mGPTHeader->hdr_sig[6] == 'R' &&
76 mGPTHeader->hdr_sig[7] == 'T') return true;
77
78 return false;
79}
80

Archive Download this file

Revision: 1297