Index: branches/xZen/i386/modules/Disk/GUIDPartition.cpp =================================================================== --- branches/xZen/i386/modules/Disk/GUIDPartition.cpp (revision 1205) +++ branches/xZen/i386/modules/Disk/GUIDPartition.cpp (revision 1206) @@ -3,7 +3,13 @@ * */ #include +#include +extern "C" +{ +#include "libsaio.h" +#include "stdio.h" +} GUIDPartition::GUIDPartition(Disk* disk, UInt8 partitionNumber) : Partition(disk, partitionNumber) { @@ -33,10 +39,11 @@ 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; Index: branches/xZen/i386/modules/Disk/include/Partition.hpp =================================================================== --- branches/xZen/i386/modules/Disk/include/Partition.hpp (revision 1205) +++ branches/xZen/i386/modules/Disk/include/Partition.hpp (revision 1206) @@ -6,10 +6,11 @@ #define PARTITION_H #include -#include #define INVALID_PARTITION (-1) +class Disk; + class Partition { public: @@ -22,6 +23,9 @@ virtual bool probe(); //virtual uuid_t getUUID(); + + virtual UInt32 getPartitionNumber() { return mPartitionNumber; }; + virtual UInt8 getNumPartitions() { return mNumPartitions; }; protected: Disk *mDisk; @@ -36,4 +40,12 @@ }; +class PartitionList +{ +public: + Partition *entry; + PartitionList *next; +}; + + #endif /* PARTITION_H */ Index: branches/xZen/i386/modules/Disk/include/Disk.hpp =================================================================== --- branches/xZen/i386/modules/Disk/include/Disk.hpp (revision 1205) +++ branches/xZen/i386/modules/Disk/include/Disk.hpp (revision 1206) @@ -6,6 +6,7 @@ #define DISK_H #include +#include class Disk { @@ -21,7 +22,11 @@ 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; Index: branches/xZen/i386/modules/Disk/Main.cpp =================================================================== --- branches/xZen/i386/modules/Disk/Main.cpp (revision 1205) +++ branches/xZen/i386/modules/Disk/Main.cpp (revision 1206) @@ -6,20 +6,28 @@ #include #include #include +#include +#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]); @@ -35,12 +43,56 @@ } } + */ + DetermineDisks(); - printf("This is a simple BootDisk_start test.\n"); - delete disk; halt(); -} \ No newline at end of file +} + +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; + } + + } +} Index: branches/xZen/i386/modules/Disk/Partition.cpp =================================================================== --- branches/xZen/i386/modules/Disk/Partition.cpp (revision 1205) +++ branches/xZen/i386/modules/Disk/Partition.cpp (revision 1206) @@ -3,7 +3,7 @@ * */ #include - +#include Partition::Partition(Disk* disk, UInt8 partitionNumber) { mDisk = disk; Index: branches/xZen/i386/modules/Disk/Disk.cpp =================================================================== --- branches/xZen/i386/modules/Disk/Disk.cpp (revision 1205) +++ branches/xZen/i386/modules/Disk/Disk.cpp (revision 1206) @@ -8,9 +8,36 @@ 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; } \ No newline at end of file Index: branches/xZen/i386/modules/Disk/FDiskPartition.cpp =================================================================== --- branches/xZen/i386/modules/Disk/FDiskPartition.cpp (revision 1205) +++ branches/xZen/i386/modules/Disk/FDiskPartition.cpp (revision 1206) @@ -3,8 +3,8 @@ * */ #include +#include - FDiskPartition::FDiskPartition(Disk* disk, UInt8 partitionNumber) : Partition(disk, partitionNumber) { mDisk = disk;