Chameleon

Chameleon Commit Details

Date:2011-07-22 07:28:48 (7 years 10 months ago)
Author:Evan Lojewski
Commit:1206
Parents: 1205
Message:Update Disk + Partition classes
Changes:
M/branches/xZen/i386/modules/Disk/include/Partition.hpp
M/branches/xZen/i386/modules/Disk/GUIDPartition.cpp
M/branches/xZen/i386/modules/Disk/include/Disk.hpp
M/branches/xZen/i386/modules/Disk/Main.cpp
M/branches/xZen/i386/modules/Disk/Partition.cpp
M/branches/xZen/i386/modules/Disk/Disk.cpp
M/branches/xZen/i386/modules/Disk/FDiskPartition.cpp

File differences

branches/xZen/i386/modules/Disk/GUIDPartition.cpp
33
44
55
6
67
8
9
10
11
12
713
814
915
......
3339
3440
3541
36
37
42
43
3844
39
45
46
4047
4148
4249
*
*/
#include <GUIDPartition.hpp>
#include <Disk.hpp>
extern "C"
{
#include "libsaio.h"
#include "stdio.h"
}
GUIDPartition::GUIDPartition(Disk* disk, UInt8 partitionNumber) : Partition(disk, partitionNumber)
{
if(mPartitionNumber >= 0 && mPartitionNumber < mNumPartitions)
{
// read in partition entry.
mDisk->Read(2 + mPartitionNumber, 1, mLBABUffer);
// TODO: Verify partition is valid + offset.
mDisk->Read(2 + (mPartitionNumber / 4), 1, mLBABUffer);
mGPTEntry = (gpt_ent*) mLBABUffer;
UInt32 offset = (mPartitionNumber % 4) * mGPTHeader->hdr_entsz;
mGPTEntry = (gpt_ent*) mLBABUffer + offset;
mNumSectors = mGPTEntry->ent_lba_end - mGPTEntry->ent_lba_start;
mBeginSector = mGPTEntry->ent_lba_start;
branches/xZen/i386/modules/Disk/include/Partition.hpp
66
77
88
9
109
1110
1211
12
13
1314
1415
1516
......
2223
2324
2425
26
27
28
2529
2630
2731
......
3640
3741
3842
43
44
45
46
47
48
49
50
3951
#define PARTITION_H
#include <IOKit/IOTypes.h>
#include <Disk.hpp>
#define INVALID_PARTITION (-1)
class Disk;
class Partition
{
public:
virtual bool probe();
//virtual uuid_t getUUID();
virtual UInt32 getPartitionNumber() { return mPartitionNumber; };
virtual UInt8 getNumPartitions() { return mNumPartitions; };
protected:
Disk *mDisk;
};
class PartitionList
{
public:
Partition *entry;
PartitionList *next;
};
#endif /* PARTITION_H */
branches/xZen/i386/modules/Disk/include/Disk.hpp
66
77
88
9
910
1011
1112
......
2122
2223
2324
25
26
27
2428
29
2530
2631
2732
#define DISK_H
#include <IOKit/IOTypes.h>
#include <Partition.hpp>
class Disk
{
virtual bool isValid() { return mName != NULL && mBytesPerSector; };
virtual bool probe() { return isValid(); };
virtual UInt32 bytesPerSector() { return mBytesPerSector; };
virtual void addPartition(Partition* partition);
virtual Partition* getPartition(UInt32 index);
protected:
PartitionList *mPartitions;
const char *mName;
const char *mBusType;
branches/xZen/i386/modules/Disk/Main.cpp
66
77
88
9
910
11
12
1013
1114
1215
1316
1417
1518
19
20
21
22
23
24
25
1626
1727
18
28
29
1930
20
21
22
2331
2432
2533
......
3543
3644
3745
46
47
3848
39
4049
41
4250
4351
4452
4553
46
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <IOKit/IOTypes.h>
#include <BiosDisk.hpp>
#include <GUIDPartition.hpp>
#include <FDiskPartition.hpp>
#define MAXBIOSDEV 32
#define BIOSBUFFER 512 * 8 /* 4Kb */
extern "C"
{
#include "libsaio.h"
void Disk_start();
}
BiosDisk* disks[MAXBIOSDEV];
UInt8 numBiosDisks = 0;
UInt8* diskBuffer = NULL;
void DetermineDisks();
void Disk_start()
{
UInt8* mbr = (UInt8*)malloc(512);
diskBuffer = (UInt8*)malloc(BIOSBUFFER);
/*UInt8* mbr = (UInt8*)malloc(512);
BiosDisk* disk = new BiosDisk("bios:/hd0/");
if(disk->probe())
{
disk->Read(0, 1, mbr);
printf("mbr[0] = 0x%X\n", mbr[0]);
}
}
*/
DetermineDisks();
printf("This is a simple BootDisk_start test.\n");
delete disk;
halt();
}
}
void DetermineDisks()
{
char diskName[] = "bios:/hd%s/";
for(int i = 0; i < MAXBIOSDEV; i++)
{
sprintf(diskName, "bios:/hd%d/", i);
BiosDisk* disk = new BiosDisk(diskName);
if(disk->probe())
{
printf("Disk %s exists\n", diskName);
disks[numBiosDisks++] = disk;
// Check if the disk is GUID
GUIDPartition* partition = new GUIDPartition(disk, 0);
UInt8 partitions = partition->getNumPartitions();
printf("GUID Disk w/ %d disks\n", partitions);
for(UInt8 partno = 0; partno < partitions; partno++)
{
GUIDPartition* partition = new GUIDPartition(disk, partno);
if(partition->probe())
{
printf("Partition %d valid\n", partno);
}
}
// If not, check if the disk is MBR
FDiskPartition* mbrdisk = new FDiskPartition(disk, 0);
partitions = mbrdisk->getNumPartitions();
printf("MBR Disk w/ %d disks\n", partitions);
}
else
{
delete disk;
}
}
}
branches/xZen/i386/modules/Disk/Partition.cpp
33
44
55
6
6
77
88
99
*
*/
#include <Partition.hpp>
#include <Disk.hpp>
Partition::Partition(Disk* disk, UInt8 partitionNumber)
{
mDisk = disk;
branches/xZen/i386/modules/Disk/Disk.cpp
88
99
1010
11
1112
1213
1314
1415
1516
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1643
Disk::Disk()
{
mName = NULL;
mPartitions = NULL;
}
Disk::~Disk()
{
}
Partition* Disk::getPartition(UInt32 index)
{
PartitionList* current = mPartitions;
while(current)
{
if(current->entry->getPartitionNumber() == index)
{
return current->entry;
}
else
{
current = current->next;
}
}
return NULL;
}
void Disk::addPartition(Partition* partition)
{
PartitionList* list = new PartitionList;
list->entry = partition;
list->next = mPartitions;
mPartitions = list;
}
branches/xZen/i386/modules/Disk/FDiskPartition.cpp
33
44
55
6
67
7
88
99
1010
*
*/
#include <FDiskPartition.hpp>
#include <Disk.hpp>
FDiskPartition::FDiskPartition(Disk* disk, UInt8 partitionNumber) : Partition(disk, partitionNumber)
{
mDisk = disk;

Archive Download the corresponding diff file

Revision: 1206