/* Location of partition table in MBR */
#define TABLE_OFFSET 446
#define MBR_MAGIC 0x55aa
#define MBR_MAGIC_OFFSET 510
#define SECTOR_SIZE 512
#define DOSP_TYPE_EXTENDED 5
long long llseek(int fd, long long offset, int whence);
static int readSingleTable(int fd, struct singlePartitionTable * table,
long long partSector) {
unsigned char sector[SECTOR_SIZE];
unsigned short magic;
static int readNextTable(int fd, struct partitionTable * table, int nextNum,
long long partSector, long long sectorOffset) {
struct singlePartitionTable singleTable;
int rc;
int i, thisPart;
int gotExtended = 0;
if ((rc = readSingleTable(fd, &singleTable, partSector + sectorOffset)))
return rc;
if (nextNum >= 4) {
/* This is an extended table */
if (singleTable.parts[2].size || singleTable.parts[3].size)
return BALKAN_ERROR_BADTABLE;
}
for (i = 0; i < 4; i++) {
if (!singleTable.parts[i].size) continue;
if (singleTable.parts[i].type == DOSP_TYPE_EXTENDED &&
nextNum >= 4) continue;
int dospReadTable(int fd, struct partitionTable * table) {
int i, rc;
table->maxNumPartitions = 16;
for (i = 0; i < table->maxNumPartitions; i++)
table->parts[i].type = -1;
table->sectorSize = SECTOR_SIZE;
rc = readNextTable(fd, table, 0, 0, 0);
if (!rc) {
for (i = 0; i < 16; i++) {
if (table->parts[i].type == -1) continue;
switch (table->parts[i].type) {
case 0x01:
case 0x04:
case 0x06:
case 0x0b:
case 0x0c:
case 0x0e:
case 0x0f:
table->parts[i].type = BALKAN_PART_DOS;
break;
case 0x7:
table->parts[i].type = BALKAN_PART_NTFS;
case 0x83:
table->parts[i].type = BALKAN_PART_EXT2;
break;
case 0x82:
table->parts[i].type = BALKAN_PART_SWAP;
break;