2010-09-17 17:15:21 +02:00
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "usbloader/usbstorage2.h"
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "wbfs.h"
|
|
|
|
#include "usbloader/wbfs/wbfs_base.h"
|
|
|
|
#include "usbloader/wbfs/wbfs_wbfs.h"
|
|
|
|
#include "usbloader/wbfs/wbfs_fat.h"
|
|
|
|
#include "usbloader/wbfs/wbfs_ntfs.h"
|
2010-12-09 21:57:35 +01:00
|
|
|
#include "usbloader/wbfs/wbfs_ext.h"
|
2010-09-17 17:15:21 +02:00
|
|
|
|
|
|
|
#include "usbloader/partition_usbloader.h"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "usbloader/GameList.h"
|
2010-10-27 21:50:48 +02:00
|
|
|
#include "menu/menus.h"
|
2010-09-17 17:15:21 +02:00
|
|
|
#include "gecko.h"
|
|
|
|
|
|
|
|
Wbfs *current = NULL;
|
2010-09-30 06:24:17 +02:00
|
|
|
//#define DEBUG_WBFS
|
2010-09-17 17:15:21 +02:00
|
|
|
|
|
|
|
/* WBFS device */
|
|
|
|
s32 wbfsDev = WBFS_MIN_DEVICE;
|
|
|
|
|
|
|
|
// partition
|
|
|
|
char wbfs_fs_drive[16];
|
2010-09-24 02:48:03 +02:00
|
|
|
int wbfs_part_fs = PART_FS_WBFS;
|
2010-09-17 17:15:21 +02:00
|
|
|
u32 wbfs_part_idx = 0;
|
|
|
|
u32 wbfs_part_lba = 0;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
wbfs_disc_t* WBFS_OpenDisc(u8 *discid)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->OpenDisc(discid);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void WBFS_CloseDisc(wbfs_disc_t *disc)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
current->CloseDisc(disc);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
wbfs_t *GetHddInfo(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-17 17:15:21 +02:00
|
|
|
return current->GetHddInfo();
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_Init(u32 device)
|
2010-09-18 13:46:25 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return Wbfs::Init(device);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_Open(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
WBFS_Close();
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
current = new Wbfs_Wbfs(WBFS_DEVICE_USB, 0, 0); // Fix me!
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_part_fs = wbfs_part_idx = wbfs_part_lba = 0;
|
|
|
|
wbfs_part_idx = 1;
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return current->Open();
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_OpenPart(u32 part_fs, u32 part_idx, u32 part_lba, u32 part_size, char *partition)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
// close
|
|
|
|
WBFS_Close();
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (part_fs == PART_FS_FAT)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
current = new Wbfs_Fat(wbfsDev, part_lba, part_size);
|
|
|
|
strcpy(wbfs_fs_drive, "USB:");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (part_fs == PART_FS_NTFS)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
current = new Wbfs_Ntfs(wbfsDev, part_lba, part_size);
|
|
|
|
strcpy(wbfs_fs_drive, "NTFS:");
|
2010-12-09 21:57:35 +01:00
|
|
|
}
|
|
|
|
else if (part_fs == PART_FS_EXT)
|
|
|
|
{
|
|
|
|
current = new Wbfs_Ext(wbfsDev, part_lba, part_size);
|
|
|
|
strcpy(wbfs_fs_drive, "EXT:");
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
current = new Wbfs_Wbfs(wbfsDev, part_lba, part_size);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (current->Open())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
delete current;
|
|
|
|
current = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// success
|
|
|
|
wbfs_part_fs = part_fs;
|
|
|
|
wbfs_part_idx = part_idx;
|
|
|
|
wbfs_part_lba = part_lba;
|
|
|
|
|
|
|
|
const char *fs = "WBFS";
|
2010-09-24 02:48:03 +02:00
|
|
|
if (wbfs_part_fs == PART_FS_FAT) fs = "FAT";
|
|
|
|
if (wbfs_part_fs == PART_FS_NTFS) fs = "NTFS";
|
2010-12-09 21:57:35 +01:00
|
|
|
if (wbfs_part_fs == PART_FS_EXT) fs = "EXT";
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(partition, "%s%d", fs, wbfs_part_idx);
|
2010-09-19 01:16:05 +02:00
|
|
|
return 0;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_OpenNamed(char *partition)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 i;
|
2010-09-24 02:48:03 +02:00
|
|
|
u32 part_fs = PART_FS_WBFS;
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 part_idx = 0;
|
|
|
|
u32 part_lba = 0;
|
|
|
|
s32 ret = 0;
|
|
|
|
PartList plist;
|
|
|
|
|
|
|
|
// close
|
|
|
|
WBFS_Close();
|
|
|
|
|
|
|
|
// parse partition option
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strncasecmp(partition, "WBFS", 4) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
i = atoi(partition + 4);
|
|
|
|
if (i < 1 || i > 4) goto err;
|
|
|
|
part_fs = PART_FS_WBFS;
|
2010-09-19 01:16:05 +02:00
|
|
|
part_idx = i;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (strncasecmp(partition, "FAT", 3) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (wbfsDev != WBFS_DEVICE_USB) goto err;
|
|
|
|
i = atoi(partition + 3);
|
|
|
|
if (i < 1 || i > 9) goto err;
|
|
|
|
part_fs = PART_FS_FAT;
|
2010-09-19 01:16:05 +02:00
|
|
|
part_idx = i;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (strncasecmp(partition, "NTFS", 4) == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
i = atoi(partition + 4);
|
|
|
|
if (i < 1 || i > 9) goto err;
|
|
|
|
part_fs = PART_FS_NTFS;
|
2010-09-19 01:16:05 +02:00
|
|
|
part_idx = i;
|
|
|
|
}
|
2010-12-09 21:57:35 +01:00
|
|
|
else if (strncasecmp(partition, "EXT", 3) == 0)
|
|
|
|
{
|
|
|
|
i = atoi(partition + 3);
|
|
|
|
if (i < 1 || i > 9) goto err;
|
|
|
|
part_fs = PART_FS_EXT;
|
|
|
|
part_idx = i;
|
|
|
|
}
|
2010-09-19 01:16:05 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get partition entries
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = Partition_GetList(wbfsDev, &plist);
|
|
|
|
if (ret || plist.num == 0) return -1;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (part_fs == PART_FS_WBFS)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (part_idx > plist.wbfs_n) goto err;
|
|
|
|
for (i = 0; i < plist.num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (plist.pinfo[i].wbfs_i == part_idx) break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (part_fs == PART_FS_FAT)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (part_idx > plist.fat_n) goto err;
|
|
|
|
for (i = 0; i < plist.num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (plist.pinfo[i].fat_i == part_idx) break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (part_fs == PART_FS_NTFS)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (part_idx > plist.ntfs_n) goto err;
|
|
|
|
for (i = 0; i < plist.num; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (plist.pinfo[i].ntfs_i == part_idx) break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2010-12-09 21:57:35 +01:00
|
|
|
else if (part_fs == PART_FS_EXT)
|
|
|
|
{
|
|
|
|
if (part_idx > plist.ext_n) goto err;
|
|
|
|
for (i = 0; i < plist.num; i++)
|
|
|
|
{
|
|
|
|
if (plist.pinfo[i].ext_i == part_idx) break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (i >= plist.num) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
// set partition lba sector
|
|
|
|
part_lba = plist.pentry[i].sector;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (WBFS_OpenPart(part_fs, part_idx, part_lba, plist.pentry[i].size, partition))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
// success
|
|
|
|
return 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
err: return -1;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_OpenLBA(u32 lba, u32 size)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
Wbfs *part = new Wbfs_Wbfs(wbfsDev, lba, size);
|
|
|
|
if (part->Open() != 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
delete part;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WBFS_Close();
|
|
|
|
current = part;
|
|
|
|
return 0;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool WBFS_Close(void)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (current != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
current->Close();
|
|
|
|
delete current;
|
|
|
|
current = NULL;
|
|
|
|
}
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_part_fs = 0;
|
|
|
|
wbfs_part_idx = 0;
|
|
|
|
wbfs_part_lba = 0;
|
|
|
|
wbfs_fs_drive[0] = '\0';
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
gameList.clear();
|
2010-09-17 17:15:21 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WBFS_Mounted()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return (current != NULL && current->Mounted());
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_Format(u32 lba, u32 size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
return current->Format();
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_GetCount(u32 *count)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->GetCount(count);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->GetHeaders(outbuf, cnt, len);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_CheckGame(u8 *discid)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->CheckGame(discid);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_AddGame(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
s32 retval = current->AddGame();
|
2010-09-24 02:48:03 +02:00
|
|
|
if (retval == 0) gameList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return retval;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_RemoveGame(u8 *discid)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 retval = current->RemoveGame(discid);
|
|
|
|
if (retval == 0) gameList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return retval;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_GameSize(u8 *discid, f32 *size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->GameSize(discid, size);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_DiskSpace(f32 *used, f32 *free)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->DiskSpace(used, free);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_RenameGame(u8 *discid, const void *newname)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 retval = current->RenameGame(discid, newname);
|
|
|
|
if (retval == 0) gameList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return retval;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 WBFS_ReIDGame(u8 *discid, const void *newID)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 retval = current->ReIDGame(discid, newID);
|
|
|
|
if (retval == 0) gameList.clear();
|
2010-09-18 13:46:25 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return retval;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
f32 WBFS_EstimeGameSize(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
return current->EstimateGameSize();
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int WBFS_GetFragList(u8 *id)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
return current->GetFragList(id);
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool WBFS_ShowFreeSpace(void)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
return current->ShowFreeSpace();
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-10-27 21:50:48 +02:00
|
|
|
int MountWBFS(bool ShowGUI)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-10-27 21:50:48 +02:00
|
|
|
if(ShowGUI)
|
|
|
|
return DiscWait(tr( "Waiting for USB Device" ), 0, 0, 0, 1);
|
|
|
|
|
2010-09-17 17:15:21 +02:00
|
|
|
int ret = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
time_t currTime = time(0);
|
2010-09-17 17:15:21 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
while (time(0) - currTime < 30)
|
2010-09-17 17:15:21 +02:00
|
|
|
{
|
2010-09-24 01:47:51 +02:00
|
|
|
|
2010-09-17 17:15:21 +02:00
|
|
|
USBDevice_deInit();
|
|
|
|
USBStorage2_Deinit();
|
|
|
|
USBDevice_Init();
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = WBFS_Init(WBFS_DEVICE_USB);
|
|
|
|
printf("%i...", int(time(0) - currTime));
|
|
|
|
if (ret < 0)
|
|
|
|
sleep(1);
|
|
|
|
else break;
|
2010-09-17 17:15:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
printf("\n");
|
2010-09-17 17:15:21 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|