1. Reused partition.cpp, partition.h and a small portion of PartInfo.cpp from NghtShd's xbpartitioner codebase.
2. Used typedefs and minor edits to get rid of C++ style code and renamed to .c
partition.h
CODE
typedef int bool;
typedef u_int64_t ULONG;
typedef u_int32_t USHORT;
#define false 0
#define true 1
#define PARTITION_MODE_F_CAPPED 0
#define PARTITION_MODE_F_ALL 1
#define PARTITION_MODE_G_REST 2
#define PARTITION_MODE_FG_EVEN 3
3. Fixed the Makefile.
CODE
OBJS=main.o util.o fatx.o dir.o partition.o
MKFS=mkfs.o util.o fatx.o dir.o partition.o
Headers in xboxdumper.c
CODE
#include "partition.h
Change to writeBRFR
CODE
int writeBRFR(char *szDrive,int partition_mode) {
FILE *fp;
int fd,i;
int error = 0;
FATXPartition* partition = NULL;
u_int64_t start,size,totalsize,totalsectors;
char szBuffer[512];
XboxPartitionTable *BackupPartTbl;
XboxPartitionTable *PartTbl;
XboxPartitionTable DefaultPartTbl =
{
{ '*', '*', '*', '*', 'P', 'A', 'R', 'T', 'I', 'N', 'F', 'O', '*', '*', '*', '*' },
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
{
{ { 'X', 'B', 'O', 'X', ' ', 'S', 'H', 'E', 'L', 'L', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_MUSICPART_LBA_START, XBOX_MUSICPART_LBA_SIZE, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'D', 'A', 'T', 'A', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, PE_PARTFLAGS_IN_USE, XBOX_SYSPART_LBA_START, XBOX_SYSPART_LBA_SIZE, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '1'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART1_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '2'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART2_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'G', 'A', 'M', 'E', ' ', 'S', 'W', 'A', 'P', ' ', '3'}, PE_PARTFLAGS_IN_USE, XBOX_SWAPPART3_LBA_START, XBOX_SWAPPART_LBA_SIZE, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'F', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START, 0, 0 },
{ { 'X', 'B', 'O', 'X', ' ', 'G', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, XBOX_PART6_LBA_START + 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
{ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 0, 0, 0, 0 },
}
};
fp = fopen (szDrive, "r+b");
if(!fp) {
printf("Error opening %s\n",szDrive);
return 0;
}
memset(szBuffer,0,256);
fseeko (fp,0L,SEEK_END);
totalsize = ftello(fp);
totalsectors = totalsize/SECTOR_SIZE;
fseeko(fp,0x600,SEEK_SET);
fread(szBuffer,4,1,fp);
printf("Readed -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);
memset(szBuffer,0,512);
fseeko(fp,0L,SEEK_SET);
for(i = XBOX_SECTOR_CONFIG;i < XBOX_SECTORS_CONFIG;i++)
fwrite(szBuffer,512,1,fp);
fseeko(fp,0x600,SEEK_SET);
sprintf(szBuffer,"BRFR");
fwrite(szBuffer,4,1,fp);
memset(szBuffer,0,256);
fseeko(fp,0x600,SEEK_SET);
fread(szBuffer,4,1,fp);
printf("Written -> %c%c%c%c\n",szBuffer[0],szBuffer[1],szBuffer[2],szBuffer[3]);
PartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));
BackupPartTbl = (XboxPartitionTable*) malloc(sizeof(XboxPartitionTable));
memcpy (BackupPartTbl,&DefaultPartTbl,sizeof(XboxPartitionTable));
part_setup_standard_partitions (PartTbl,BackupPartTbl,totalsectors,partition_mode);
fseeko(fp,0L,SEEK_SET);
fwrite(PartTbl, sizeof(XboxPartitionTable), 1, fp);
fclose(fp);
sprintf(szBuffer,"part50");
start = XBOX_SECTOR_STORE * 512UL;
size = XBOX_SECTORS_STORE * 512ULL;
printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
partition = createPartition(szDrive, start,size, 0);
if(partition == NULL) {
printf("Error creating -> %s\n",szBuffer);
return 0;
}
closePartition(partition);
sprintf(szBuffer,"part51");
start = XBOX_SECTOR_SYSTEM * 512UL;
size = XBOX_SECTORS_SYSTEM * 512UL;
printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
partition = createPartition(szDrive, start,size, 0);
if(partition == NULL) {
printf("Error creating -> %s\n",szBuffer);
return 0;
}
closePartition(partition);
sprintf(szBuffer,"part52");
start = XBOX_SECTOR_CACHE1 * 512UL;
size = XBOX_SECTORS_CACHE1 * 512UL;
printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
partition = createPartition(szDrive, start,size, 0);
if(partition == NULL) {
printf("Error creating -> %s\n",szBuffer);
return 0;
}
closePartition(partition);
sprintf(szBuffer,"part53");
start = XBOX_SECTOR_CACHE2 * 512UL;
size = XBOX_SECTORS_CACHE2 * 512UL;
printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
partition = createPartition(szDrive, start,size, 0);
if(partition == NULL) {
printf("Error creating -> %s\n",szBuffer);
return 0;
}
closePartition(partition);
sprintf(szBuffer,"part54");
start = XBOX_SECTOR_CACHE3 * 512UL;
size = XBOX_SECTORS_CACHE3 * 512UL;
printf("Creating -> %s start %lld size %lld\n",szBuffer, start ,size);
partition = createPartition(szDrive, start,size, 0);
if(partition == NULL) {
printf("Error creating -> %s\n",szBuffer);
return 0;
}
closePartition(partition);
for (i=5;i<14;i++)
{
if (PartTbl->TableEntries.Flags & PE_PARTFLAGS_IN_USE)
{
printf("Creating -> start %lld size %lld\n", PartTbl->TableEntries.LBAStart,PartTbl->TableEntries.LBASize);
partition = createPartition(szDrive, PartTbl->TableEntries.LBAStart,PartTbl->TableEntries.LBASize,0);
closePartition (partition);
}
}
printf("Calling ioctl() to re-read partition table.\n");
sync();
sleep(2);
return 1;
}