2009-05-03 20:53:31 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "sdhc.h"
|
|
|
|
#include "usbstorage.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "wdvd.h"
|
2009-07-30 07:41:12 +02:00
|
|
|
#include "wbfs.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "wbfs_fat.h"
|
|
|
|
#include "fatmounter.h"
|
2009-11-15 22:30:44 +01:00
|
|
|
#include "partition_usbloader.h"
|
2009-12-10 21:27:36 +01:00
|
|
|
#include "settings/cfg.h"
|
2009-07-30 07:41:12 +02:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
#include "libwbfs/libwbfs.h"
|
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
#define MAX_NB_SECTORS 32
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
/* WBFS device */
|
|
|
|
s32 wbfsDev = WBFS_MIN_DEVICE;
|
|
|
|
|
|
|
|
// partition
|
|
|
|
int wbfs_part_fat = 0;
|
|
|
|
u32 wbfs_part_idx = 0;
|
|
|
|
u32 wbfs_part_lba = 0;
|
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
/* WBFS HDD */
|
2009-11-15 20:52:58 +01:00
|
|
|
wbfs_t *hdd = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
/* WBFS callbacks */
|
|
|
|
static rw_sector_callback_t readCallback = NULL;
|
2009-06-14 01:39:42 +02:00
|
|
|
static rw_sector_callback_t writeCallback = NULL;
|
2009-07-05 22:22:29 +02:00
|
|
|
static s32 done = -1, total = -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
/* Variables */
|
2009-05-13 22:55:33 +02:00
|
|
|
|
2009-05-03 20:53:31 +02:00
|
|
|
static u32 nb_sectors, sector_size;
|
2009-11-15 20:52:58 +01:00
|
|
|
|
|
|
|
void WBFS_Spinner(s32 x, s32 max) {
|
2009-07-30 07:41:12 +02:00
|
|
|
done = x;
|
|
|
|
total = max;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
wbfs_disc_t* WBFS_OpenDisc(u8 *discid)
|
|
|
|
{
|
|
|
|
if (wbfs_part_fat) return WBFS_FAT_OpenDisc(discid);
|
|
|
|
|
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Open disc */
|
|
|
|
return wbfs_open_disc(hdd, discid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WBFS_CloseDisc(wbfs_disc_t *disc)
|
|
|
|
{
|
|
|
|
if (wbfs_part_fat) {
|
|
|
|
WBFS_FAT_CloseDisc(disc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No device open */
|
|
|
|
if (!hdd || !disc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Close disc */
|
|
|
|
wbfs_close_disc(disc);
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void GetProgressValue(s32 * d, s32 * m) {
|
|
|
|
*d = done;
|
|
|
|
*m = total;
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
wbfs_t *GetHddInfo(void) {
|
|
|
|
return hdd;
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __WBFS_ReadDVD(void *fp, u32 lba, u32 len, void *iobuf) {
|
|
|
|
void *buffer = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u64 offset;
|
|
|
|
u32 mod, size;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Calculate offset */
|
|
|
|
offset = ((u64)lba) << 2;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Calcualte sizes */
|
|
|
|
mod = len % 32;
|
|
|
|
size = len - mod;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read aligned data */
|
|
|
|
if (size) {
|
|
|
|
ret = WDVD_UnencryptedRead(iobuf, size, offset);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read non-aligned data */
|
|
|
|
if (mod) {
|
|
|
|
/* Allocate memory */
|
|
|
|
buffer = memalign(32, 0x20);
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read data */
|
|
|
|
ret = WDVD_UnencryptedRead(buffer, 0x20, offset + size);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Copy data */
|
|
|
|
memcpy(iobuf + size, buffer, mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success */
|
|
|
|
ret = 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
out:
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Free memory */
|
|
|
|
if (buffer)
|
|
|
|
free(buffer);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __WBFS_ReadUSB(void *fp, u32 lba, u32 count, void *iobuf) {
|
|
|
|
u32 cnt = 0;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Do reads */
|
|
|
|
while (cnt < count) {
|
|
|
|
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
|
|
|
|
u32 sectors = (count - cnt);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read sectors is too big */
|
|
|
|
if (sectors > MAX_NB_SECTORS)
|
|
|
|
sectors = MAX_NB_SECTORS;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* USB read */
|
|
|
|
ret = USBStorage_ReadSectors(lba + cnt, sectors, ptr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Increment counter */
|
|
|
|
cnt += sectors;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __WBFS_WriteUSB(void *fp, u32 lba, u32 count, void *iobuf) {
|
|
|
|
u32 cnt = 0;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Do writes */
|
|
|
|
while (cnt < count) {
|
|
|
|
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
|
|
|
|
u32 sectors = (count - cnt);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Write sectors is too big */
|
|
|
|
if (sectors > MAX_NB_SECTORS)
|
|
|
|
sectors = MAX_NB_SECTORS;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* USB write */
|
|
|
|
ret = USBStorage_WriteSectors(lba + cnt, sectors, ptr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Increment counter */
|
|
|
|
cnt += sectors;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __WBFS_ReadSDHC(void *fp, u32 lba, u32 count, void *iobuf) {
|
|
|
|
u32 cnt = 0;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Do reads */
|
|
|
|
while (cnt < count) {
|
|
|
|
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
|
|
|
|
u32 sectors = (count - cnt);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Read sectors is too big */
|
|
|
|
if (sectors > MAX_NB_SECTORS)
|
|
|
|
sectors = MAX_NB_SECTORS;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* SDHC read */
|
|
|
|
ret = SDHC_ReadSectors(lba + cnt, sectors, ptr);
|
|
|
|
if (!ret)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Increment counter */
|
|
|
|
cnt += sectors;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 __WBFS_WriteSDHC(void *fp, u32 lba, u32 count, void *iobuf) {
|
|
|
|
u32 cnt = 0;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Do writes */
|
|
|
|
while (cnt < count) {
|
|
|
|
void *ptr = ((u8 *)iobuf) + (cnt * sector_size);
|
|
|
|
u32 sectors = (count - cnt);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Write sectors is too big */
|
|
|
|
if (sectors > MAX_NB_SECTORS)
|
|
|
|
sectors = MAX_NB_SECTORS;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* SDHC write */
|
|
|
|
ret = SDHC_WriteSectors(lba + cnt, sectors, ptr);
|
|
|
|
if (!ret)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Increment counter */
|
|
|
|
cnt += sectors;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_Init(u32 device) {
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
switch (device) {
|
|
|
|
case WBFS_DEVICE_USB:
|
|
|
|
/* Initialize USB storage */
|
|
|
|
ret = USBStorage_Init();
|
|
|
|
if (ret >= 0) {
|
|
|
|
/* Setup callbacks */
|
|
|
|
readCallback = __WBFS_ReadUSB;
|
|
|
|
writeCallback = __WBFS_WriteUSB;
|
|
|
|
/* Device info */
|
|
|
|
/* Get USB capacity */
|
|
|
|
nb_sectors = USBStorage_GetCapacity(§or_size);
|
|
|
|
if (!nb_sectors)
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
return ret;
|
|
|
|
break;
|
|
|
|
case WBFS_DEVICE_SDHC:
|
|
|
|
/* Initialize SDHC */
|
|
|
|
ret = SDHC_Init();
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
/* Setup callbacks */
|
|
|
|
readCallback = __WBFS_ReadSDHC;
|
|
|
|
writeCallback = __WBFS_WriteSDHC;
|
|
|
|
|
|
|
|
/* Device info */
|
|
|
|
nb_sectors = 0;
|
|
|
|
sector_size = SDHC_SECTOR_SIZE;
|
|
|
|
} else
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_Open(void) {
|
|
|
|
/* Close hard disk */
|
|
|
|
if (hdd)
|
|
|
|
wbfs_close(hdd);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Open hard disk */
|
2009-11-15 20:52:58 +01:00
|
|
|
wbfs_part_fat = wbfs_part_idx = wbfs_part_lba = 0;
|
2009-07-30 07:41:12 +02:00
|
|
|
hdd = wbfs_open_hd(readCallback, writeCallback, NULL, sector_size, nb_sectors, 0);
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-10-13 23:19:23 +02:00
|
|
|
// Save the new sector size, so it will be used in read and write calls
|
2009-10-16 06:18:00 +02:00
|
|
|
sector_size = 1 << hdd->head->hd_sec_sz_s;
|
2009-10-13 23:19:23 +02:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
wbfs_part_idx = 1;
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
s32 WBFS_OpenPart(u32 part_fat, u32 part_idx, u32 part_lba, u32 part_size, char *partition)
|
|
|
|
{
|
|
|
|
// close
|
|
|
|
WBFS_Close();
|
|
|
|
|
|
|
|
if (part_fat) {
|
|
|
|
if (wbfsDev != WBFS_DEVICE_USB) return -1;
|
|
|
|
if (part_lba == fat_usb_sec) {
|
|
|
|
strcpy(wbfs_fat_drive, "USB:");
|
|
|
|
} else {
|
|
|
|
if (WBFSDevice_Init(part_lba)) return -1;
|
|
|
|
strcpy(wbfs_fat_drive, "WBFS:");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (WBFS_OpenLBA(part_lba, part_size)) return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
// success
|
|
|
|
wbfs_part_fat = part_fat;
|
|
|
|
wbfs_part_idx = part_idx;
|
|
|
|
wbfs_part_lba = part_lba;
|
2009-11-22 15:09:08 +01:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
sprintf(partition, "%s%d", wbfs_part_fat ? "FAT" : "WBFS", wbfs_part_idx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 WBFS_OpenNamed(char *partition)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u32 part_idx = 0;
|
|
|
|
u32 part_fat = 0;
|
|
|
|
u32 part_lba = 0;
|
|
|
|
s32 ret = 0;
|
|
|
|
PartList plist;
|
|
|
|
|
|
|
|
// close
|
|
|
|
WBFS_Close();
|
|
|
|
|
|
|
|
// parse partition option
|
|
|
|
if (strncasecmp(partition, "WBFS", 4) == 0) {
|
|
|
|
i = atoi(partition+4);
|
|
|
|
if (i < 1 || i > 4) goto err;
|
|
|
|
part_idx = i;
|
|
|
|
} else if (strncasecmp(partition, "FAT", 3) == 0) {
|
|
|
|
if (wbfsDev != WBFS_DEVICE_USB) goto err;
|
|
|
|
i = atoi(partition+3);
|
|
|
|
if (i < 1 || i > 9) goto err;
|
|
|
|
part_idx = i;
|
|
|
|
part_fat = 1;
|
|
|
|
} else {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get partition entries
|
2009-12-04 16:05:20 +01:00
|
|
|
ret = Partition_GetList(wbfsDev, &plist);
|
2009-11-15 20:52:58 +01:00
|
|
|
if (ret || plist.num == 0) return -1;
|
|
|
|
|
|
|
|
if (part_fat) {
|
|
|
|
if (part_idx > plist.fat_n) goto err;
|
|
|
|
for (i=0; i<plist.num; i++) {
|
|
|
|
if (plist.pinfo[i].fat_i == part_idx) break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (part_idx > plist.wbfs_n) goto err;
|
|
|
|
for (i=0; i<plist.num; i++) {
|
|
|
|
if (plist.pinfo[i].wbfs_i == part_idx) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= plist.num) goto err;
|
|
|
|
// set partition lba sector
|
|
|
|
part_lba = plist.pentry[i].sector;
|
|
|
|
|
|
|
|
if (WBFS_OpenPart(part_fat, part_idx, part_lba, plist.pentry[i].size, partition)) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
// success
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 WBFS_OpenLBA(u32 lba, u32 size)
|
|
|
|
{
|
|
|
|
wbfs_t *part = NULL;
|
|
|
|
|
|
|
|
/* Open partition */
|
|
|
|
part = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 0);
|
|
|
|
if (!part) return -1;
|
|
|
|
|
|
|
|
/* Close current hard disk */
|
|
|
|
if (hdd) wbfs_close(hdd);
|
|
|
|
hdd = part;
|
2009-07-30 07:41:12 +02:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WBFS_Close(void)
|
2009-05-03 20:53:31 +02:00
|
|
|
{
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Close hard disk */
|
2009-11-15 20:52:58 +01:00
|
|
|
if (hdd) {
|
2009-07-30 07:41:12 +02:00
|
|
|
wbfs_close(hdd);
|
2009-11-15 20:52:58 +01:00
|
|
|
hdd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WBFSDevice_deInit();
|
|
|
|
wbfs_part_fat = 0;
|
|
|
|
wbfs_part_idx = 0;
|
|
|
|
wbfs_part_lba = 0;
|
|
|
|
wbfs_fat_drive[0] = '\0';
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
bool WBFS_Mounted()
|
|
|
|
{
|
|
|
|
return (hdd != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WBFS_Selected()
|
|
|
|
{
|
|
|
|
if (wbfs_part_fat && wbfs_part_lba && *wbfs_fat_drive) return true;
|
|
|
|
return WBFS_Mounted();
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_Format(u32 lba, u32 size) {
|
|
|
|
wbfs_t *partition = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Reset partition */
|
|
|
|
partition = wbfs_open_partition(readCallback, writeCallback, NULL, sector_size, size, lba, 1);
|
|
|
|
if (!partition)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Free memory */
|
|
|
|
wbfs_close(partition);
|
|
|
|
|
|
|
|
return 0;
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_GetCount(u32 *count) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) return WBFS_FAT_GetCount(count);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get list length */
|
|
|
|
*count = wbfs_count_discs(hdd);
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_GetHeaders(void *outbuf, u32 cnt, u32 len) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) return WBFS_FAT_GetHeaders(outbuf, cnt, len);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 idx, size;
|
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
for (idx = 0; idx < cnt; idx++) {
|
|
|
|
u8 *ptr = ((u8 *)outbuf) + (idx * len);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get header */
|
|
|
|
ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_CheckGame(u8 *discid) {
|
|
|
|
wbfs_disc_t *disc = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Try to open game disc */
|
2009-11-15 20:52:58 +01:00
|
|
|
disc = WBFS_OpenDisc(discid);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (disc) {
|
|
|
|
/* Close disc */
|
2009-11-15 20:52:58 +01:00
|
|
|
WBFS_CloseDisc(disc);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 1;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_AddGame(void) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) return WBFS_FAT_AddGame();
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Add game to device */
|
2009-12-10 21:27:36 +01:00
|
|
|
partition_selector_t part_sel;
|
|
|
|
int copy_1_1 = 0;
|
|
|
|
|
|
|
|
if (Settings.fullcopy) {
|
|
|
|
part_sel = ALL_PARTITIONS;
|
|
|
|
copy_1_1 = 1;
|
|
|
|
} else {
|
|
|
|
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wbfs_add_disc(hdd, __WBFS_ReadDVD, NULL, WBFS_Spinner, part_sel, copy_1_1);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_RemoveGame(u8 *discid) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) return WBFS_FAT_RemoveGame(discid);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Remove game from USB device */
|
|
|
|
ret = wbfs_rm_disc(hdd, discid);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_GameSize(u8 *discid, f32 *size) {
|
|
|
|
wbfs_disc_t *disc = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
u32 sectors;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Open disc */
|
2009-11-15 20:52:58 +01:00
|
|
|
disc = WBFS_OpenDisc(discid);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (!disc)
|
|
|
|
return -2;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Get game size in sectors */
|
2009-11-15 20:52:58 +01:00
|
|
|
sectors = wbfs_sector_used(disc->p, disc->header);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Copy value */
|
2009-11-15 20:52:58 +01:00
|
|
|
*size = (disc->p->wbfs_sec_sz / GB_SIZE) * sectors;
|
|
|
|
|
|
|
|
/* Close disc */
|
|
|
|
WBFS_CloseDisc(disc);
|
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
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 WBFS_DiskSpace(f32 *used, f32 *free) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) return WBFS_FAT_DiskSpace(used, free);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
f32 ssize;
|
|
|
|
u32 cnt;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* No device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Count used blocks */
|
|
|
|
cnt = wbfs_count_usedblocks(hdd);
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Sector size in GB */
|
|
|
|
ssize = hdd->wbfs_sec_sz / GB_SIZE;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Copy values */
|
|
|
|
*free = ssize * cnt;
|
|
|
|
*used = ssize * (hdd->n_wbfs_sec - cnt);
|
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
|
|
|
}
|
|
|
|
|
2009-11-22 15:09:08 +01:00
|
|
|
s32 WBFS_RenameGame(u8 *discid, const void *newname)
|
|
|
|
{
|
|
|
|
if (wbfs_part_fat)
|
|
|
|
{
|
|
|
|
return WBFS_FAT_RenameGame(discid, newname);
|
|
|
|
}
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No USB device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
|
|
|
ret = wbfs_ren_disc(hdd, discid,(u8*)newname);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-22 15:09:08 +01:00
|
|
|
s32 WBFS_ReIDGame(u8 *discid, const void *newID)
|
|
|
|
{
|
|
|
|
if (wbfs_part_fat)
|
|
|
|
{
|
|
|
|
return WBFS_FAT_ReIDGame(discid, newID);
|
|
|
|
}
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2009-09-02 10:03:51 +02:00
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No USB device open */
|
|
|
|
if (!hdd)
|
|
|
|
return -1;
|
|
|
|
ret = wbfs_rID_disc(hdd, discid,(u8*)newID);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
f32 WBFS_EstimeGameSize(void) {
|
2009-11-15 20:52:58 +01:00
|
|
|
if (wbfs_part_fat) {
|
|
|
|
u64 comp;
|
|
|
|
WBFS_FAT_DVD_Size(&comp, NULL);
|
|
|
|
return comp;
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-12-10 21:27:36 +01:00
|
|
|
partition_selector_t part_sel;
|
|
|
|
if (Settings.fullcopy) {
|
|
|
|
part_sel = ALL_PARTITIONS;
|
|
|
|
} else {
|
|
|
|
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS;
|
|
|
|
}
|
|
|
|
return wbfs_estimate_disc(hdd, __WBFS_ReadDVD, NULL, part_sel);
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|