2009-10-01 01:10:58 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
#include <ogc/mutex.h>
|
|
|
|
#include <ogc/system.h>
|
|
|
|
#include <ogc/usbstorage.h>
|
|
|
|
#include <sdcard/wiisd_io.h>
|
|
|
|
|
2009-10-13 23:19:23 +02:00
|
|
|
#include "usbloader/sdhc.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "usbloader/usbstorage.h"
|
2009-11-15 22:30:44 +01:00
|
|
|
#include "libfat/fat.h"
|
2009-12-11 00:05:32 +01:00
|
|
|
#include "gecko.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
//these are the only stable and speed is good
|
2009-11-15 20:52:58 +01:00
|
|
|
#define CACHE 32
|
2009-10-01 01:10:58 +02:00
|
|
|
#define SECTORS 64
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
#define MOUNT_NONE 0
|
|
|
|
#define MOUNT_SD 1
|
|
|
|
#define MOUNT_SDHC 2
|
|
|
|
|
2009-10-13 23:19:23 +02:00
|
|
|
extern DISC_INTERFACE __io_sdhc;
|
2009-11-15 20:52:58 +01:00
|
|
|
extern sec_t _FAT_startSector;
|
|
|
|
|
|
|
|
int fat_sd_mount = MOUNT_NONE;
|
|
|
|
sec_t fat_sd_sec = 0; // u32
|
|
|
|
|
|
|
|
int fat_usb_mount = 0;
|
|
|
|
sec_t fat_usb_sec = 0;
|
|
|
|
|
|
|
|
int fat_wbfs_mount = 0;
|
|
|
|
sec_t fat_wbfs_sec = 0;
|
2009-10-13 23:19:23 +02:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
int USBDevice_Init() {
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf("\nUSBDevice_Init()");
|
|
|
|
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("USB:/");
|
|
|
|
//right now mounts first FAT-partition
|
2009-11-15 20:52:58 +01:00
|
|
|
|
|
|
|
//try first mount with cIOS
|
|
|
|
if (!fatMount("USB", &__io_wiiums, 0, CACHE, SECTORS)) {
|
2009-10-01 01:10:58 +02:00
|
|
|
//try now mount with libogc
|
2009-11-15 20:52:58 +01:00
|
|
|
if (!fatMount("USB", &__io_usbstorage, 0, CACHE, SECTORS)) {
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf(":-1");
|
2009-11-15 20:52:58 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2009-11-15 22:30:44 +01:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
fat_usb_mount = 1;
|
|
|
|
fat_usb_sec = _FAT_startSector;
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf(":0");
|
2009-11-15 20:52:58 +01:00
|
|
|
return 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void USBDevice_deInit() {
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf("\nUSBDevice_deInit()");
|
2009-10-01 01:10:58 +02:00
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("USB:/");
|
2009-11-15 20:52:58 +01:00
|
|
|
|
|
|
|
fat_usb_mount = 0;
|
|
|
|
fat_usb_sec = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int WBFSDevice_Init(u32 sector) {
|
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("WBFS:/");
|
|
|
|
//right now mounts first FAT-partition
|
|
|
|
|
|
|
|
//try first mount with cIOS
|
|
|
|
if (!fatMount("WBFS", &__io_wiiums, 0, CACHE, SECTORS)) {
|
|
|
|
//try now mount with libogc
|
|
|
|
if (!fatMount("WBFS", &__io_usbstorage, 0, CACHE, SECTORS)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-11-15 22:30:44 +01:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
fat_wbfs_mount = 1;
|
|
|
|
fat_wbfs_sec = _FAT_startSector;
|
|
|
|
if (sector && fat_wbfs_sec != sector) {
|
|
|
|
// This is an error situation...actually, but is ignored in Config loader also
|
|
|
|
// Should ask Oggzee about it...
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WBFSDevice_deInit() {
|
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("WBFS:/");
|
|
|
|
|
|
|
|
fat_wbfs_mount = 0;
|
|
|
|
fat_wbfs_sec = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int isInserted(const char *path) {
|
|
|
|
if (!strncmp(path, "USB:", 4))
|
|
|
|
return 1;
|
|
|
|
|
2009-10-13 23:19:23 +02:00
|
|
|
return __io_sdhc.isInserted() || __io_wiisd.isInserted();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2009-11-15 20:52:58 +01:00
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
int SDCard_Init() {
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf("\nSDCard_Init()");
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("SD:/");
|
|
|
|
//right now mounts first FAT-partition
|
2009-11-15 20:52:58 +01:00
|
|
|
if (fatMount("SD", &__io_wiisd, 0, CACHE, SECTORS)) {
|
|
|
|
fat_sd_mount = MOUNT_SD;
|
|
|
|
fat_sd_sec = _FAT_startSector;
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf(":1");
|
2009-10-18 23:23:54 +02:00
|
|
|
return 1;
|
2009-11-15 20:52:58 +01:00
|
|
|
}
|
|
|
|
else if (fatMount("SD", &__io_sdhc, 0, CACHE, SDHC_SECTOR_SIZE)) {
|
|
|
|
fat_sd_mount = MOUNT_SDHC;
|
|
|
|
fat_sd_sec = _FAT_startSector;
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf(":1");
|
2009-10-13 23:19:23 +02:00
|
|
|
return 1;
|
2009-11-15 20:52:58 +01:00
|
|
|
}
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf(":-1");
|
2009-10-01 01:10:58 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SDCard_deInit() {
|
2009-12-11 00:05:32 +01:00
|
|
|
gprintf("\nSDCard_deInit()");
|
2009-10-01 01:10:58 +02:00
|
|
|
//closing all open Files write back the cache and then shutdown em!
|
|
|
|
fatUnmount("SD:/");
|
2009-11-15 22:30:44 +01:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
fat_sd_mount = MOUNT_NONE;
|
|
|
|
fat_sd_sec = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|