Chameleon

Chameleon Svn Source Tree

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

Source at commit 1210 created 12 years 9 months ago.
By meklort, remove debugging from GUIDPartition.cpp
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 UInt32 entrySize = 0;
17
18 mDisk = disk;
19 mNumSectors = 0;
20 mBeginSector = 0;
21 mPartitionNumber = partitionNumber;
22 mNumPartitions = 0;
23
24 if(mDisk)
25 {
26 // read in lba1, this contains the partition map if it's GPT
27 mDisk->Read(1, 1, mLBABUffer);
28 mGPTHeader = (GPTHeader*)mLBABUffer;
29 entrySize = mGPTHeader->hdr_entsz;
30
31 }
32 else
33 {
34 mGPTHeader = NULL;
35 }
36
37 if(isGPTDisk())
38 {
39 mNumPartitions = mGPTHeader->hdr_entries;
40 }
41
42 mGPTHeader = NULL;
43
44 if(entrySize && mPartitionNumber >= 0 && mPartitionNumber < mNumPartitions)
45 {
46 mDisk->Read(2 + (mPartitionNumber / 4), 1, mLBABUffer);
47
48 UInt32 offset = (mPartitionNumber % 4) * entrySize;
49
50 mGPTEntry = (GPTEntry*) /*mLBABUffer*/ BIOS_ADDR + offset;
51
52 mNumSectors = mGPTEntry->ent_lba_end - mGPTEntry->ent_lba_start;
53 mBeginSector = mGPTEntry->ent_lba_start;
54 //mUUID = mGPTEntry->ent_uuid;
55 }
56
57}
58
59GUIDPartition::~GUIDPartition()
60{
61
62}
63
64
65bool GUIDPartition::isGPTDisk()
66{
67 static bool status = false;
68
69 if(status) return status;
70
71 if(!mGPTHeader) return false;
72
73 if(mGPTHeader->hdr_sig[0] == 'E' &&
74 mGPTHeader->hdr_sig[1] == 'F' &&
75 mGPTHeader->hdr_sig[2] == 'I' &&
76 mGPTHeader->hdr_sig[3] == ' ' &&
77 mGPTHeader->hdr_sig[4] == 'P' &&
78 mGPTHeader->hdr_sig[5] == 'A' &&
79 mGPTHeader->hdr_sig[6] == 'R' &&
80 mGPTHeader->hdr_sig[7] == 'T') return true;
81
82 return false;
83}
84

Archive Download this file

Revision: 1210