2009-05-03 20:53:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
|
|
|
|
#include "partition.h"
|
|
|
|
#include "usbstorage.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/* 'partition table' structure */
|
|
|
|
typedef struct {
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Zero bytes */
|
|
|
|
u8 padding[446];
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Partition table entries */
|
|
|
|
partitionEntry entries[MAX_PARTITIONS];
|
2009-05-03 20:53:31 +02:00
|
|
|
} ATTRIBUTE_PACKED partitionTable;
|
|
|
|
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 Partition_GetEntries(partitionEntry *outbuf, u32 *outval) {
|
|
|
|
static partitionTable table ATTRIBUTE_ALIGN(32);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 cnt, sector_size;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get sector size */
|
|
|
|
ret = USBStorage_GetCapacity(§or_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read partition table */
|
|
|
|
ret = USBStorage_ReadSectors(0, 1, &table);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Swap endianess */
|
|
|
|
for (cnt = 0; cnt < 4; cnt++) {
|
|
|
|
partitionEntry *entry = &table.entries[cnt];
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
entry->sector = swap32(entry->sector);
|
|
|
|
entry->size = swap32(entry->size);
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set partition entries */
|
|
|
|
memcpy(outbuf, table.entries, sizeof(table.entries));
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set sector size */
|
|
|
|
*outval = sector_size;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|