Root/
Source at commit 1275 created 12 years 11 months ago. By meklort, Remove unused file. Fixup makefiles some more - boot2 compiles again. | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 2011 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | #include <GUIDPartition.hpp>␊ |
6 | #include <Disk.hpp>␊ |
7 | ␊ |
8 | extern "C"␊ |
9 | {␊ |
10 | #include "libsaio.h"␊ |
11 | #include "stdio.h"␊ |
12 | }␊ |
13 | ␊ |
14 | GUIDPartition::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 + offset;␊ |
51 | ␊ |
52 | // TODO: verify partition type != NULL␊ |
53 | ␊ |
54 | mNumSectors = (mGPTEntry->ent_lba_end - mGPTEntry->ent_lba_start) + 1;␊ |
55 | mBeginSector = mGPTEntry->ent_lba_start;␊ |
56 | //mUUID = mGPTEntry->ent_uuid;␊ |
57 | } ␊ |
58 | }␊ |
59 | ␊ |
60 | GUIDPartition::~GUIDPartition()␊ |
61 | {␊ |
62 | ␊ |
63 | }␊ |
64 | ␊ |
65 | ␊ |
66 | bool GUIDPartition::isGPTDisk()␊ |
67 | {␊ |
68 | static bool status = false;␊ |
69 | ␊ |
70 | if(status) return status;␊ |
71 | ␊ |
72 | if(!mGPTHeader) return false;␊ |
73 | ␊ |
74 | if(mGPTHeader->hdr_sig[0] == 'E' &&␊ |
75 | mGPTHeader->hdr_sig[1] == 'F' &&␊ |
76 | mGPTHeader->hdr_sig[2] == 'I' &&␊ |
77 | mGPTHeader->hdr_sig[3] == ' ' &&␊ |
78 | mGPTHeader->hdr_sig[4] == 'P' &&␊ |
79 | mGPTHeader->hdr_sig[5] == 'A' &&␊ |
80 | mGPTHeader->hdr_sig[6] == 'R' &&␊ |
81 | mGPTHeader->hdr_sig[7] == 'T') return true;␊ |
82 | ␊ |
83 | return false;␊ |
84 | }␊ |
85 |