Reading Extended partitions



Hi,

I'm trying to read all primary and extended partitions on a system using
just C/C++.
Although I could read the primary partiton, I'm not able to navigate to the
Extended partition using the code below. Could someone tell me what is wrong?

//Header file
struct PartitionTableEntry {
unsigned char bootIndicator;
unsigned char startCHSone;
unsigned char startCHStwo;
unsigned char startCHSthree;
unsigned char partitionTypeDescriptor;
unsigned char endCHSone;
unsigned char endCHStwo;
unsigned char endCHSthree;
unsigned int startSectorLBA;
unsigned int partitionSize;
};

struct MasterBootRecord {
unsigned char codeArea[MBR_CODE_AREA_SIZE];
PartitionTableEntry partitionEntry[MAX_PARTITION_TABLE_ENTRIES];
unsigned short bootRecordSignature;
};

struct ExtendedBootRecord{
unsigned char codeArea[MBR_CODE_AREA_SIZE];
PartitionTableEntry partitionEntry[1];
unsigned short nextPartitionEntry;
unsigned char unusedBytes[32];
unsigned short bootRecordSignature;
};

//CPP file

//Read MBR, and using struct above, get the start sector and seek to that
point.
//MBR is read correctly.

unsigned int startSectorEBR = mbrDisk0.partitionEntry[i].startSectorLBA;
long startByteEBR = startSectorEBR * 512;
long lEBRPos = _lseek(fdDisk0, startByteEBR, SEEK_SET);
nBytesRead = _read(fdDisk0, &ebr, sizeof(ExtendedBootRecord));

But nBytesRead returns -1.

(I'm using this for reference:
http://mirror.href.com/thestarman/asm/mbr/PartTables.htm )
TIA,
SD
.


Loading