Chameleon

Chameleon Svn Source Tree

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

Source at commit 1209 created 12 years 9 months ago.
By meklort, Use printf from klibc instead of from console.c
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 printf("Partitions %d at LBA %d\n", mPartitionNumber, 2 + (mPartitionNumber / 4));
47 // TODO: Verify partition is valid + offset.
48 mDisk->Read(2 + (mPartitionNumber / 4), 1, mLBABUffer);
49
50 for(int i = 0; i < 10; i++)
51 {
52 for(int j = 0; j < 15; j++)
53 {
54 printf("%x ", mLBABUffer[i*15+j]);
55 }
56 printf("\n");
57
58 }
59
60 UInt32 offset = (mPartitionNumber % 4) * entrySize;
61 printf("\toffset %d at LBA %d\n", offset);
62
63 mGPTEntry = (GPTEntry*) /*mLBABUffer*/ BIOS_ADDR + offset;
64
65 printf("UUID0 %X%X%X%X\n", mGPTEntry->ent_type[3], mGPTEntry->ent_type[2], mGPTEntry->ent_type[1], mGPTEntry->ent_type[0]);
66 printf("mGPTEntry = %d\n", mGPTEntry);
67
68 mNumSectors = mGPTEntry->ent_lba_end - mGPTEntry->ent_lba_start;
69 printf("mNumSectors = %d\n", mNumSectors);
70
71 printf("LBS Start: %lld\tEnd: %lld\n", mGPTEntry->ent_lba_start, mGPTEntry->ent_lba_end);
72 mBeginSector = mGPTEntry->ent_lba_start;
73 //mUUID = mGPTEntry->ent_uuid;
74 pause();
75 }
76
77}
78
79GUIDPartition::~GUIDPartition()
80{
81
82}
83
84
85bool GUIDPartition::isGPTDisk()
86{
87 static bool status = false;
88
89 if(status) return status;
90
91 if(!mGPTHeader) return false;
92
93 if(mGPTHeader->hdr_sig[0] == 'E' &&
94 mGPTHeader->hdr_sig[1] == 'F' &&
95 mGPTHeader->hdr_sig[2] == 'I' &&
96 mGPTHeader->hdr_sig[3] == ' ' &&
97 mGPTHeader->hdr_sig[4] == 'P' &&
98 mGPTHeader->hdr_sig[5] == 'A' &&
99 mGPTHeader->hdr_sig[6] == 'R' &&
100 mGPTHeader->hdr_sig[7] == 'T') return true;
101
102 return false;
103}
104

Archive Download this file

Revision: 1209