Chameleon

Chameleon Svn Source Tree

Root/branches/xZen/i386/modules/Disk/GUIDPartition.cpp

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

Archive Download this file

Revision: 1206