2010-02-22 22:29:47 +01:00
|
|
|
/*-------------------------------------------------------------
|
|
|
|
|
|
|
|
usbstorage_starlet.c -- USB mass storage support, inside starlet
|
|
|
|
Copyright (C) 2009 Kwiirk
|
|
|
|
|
2010-02-25 13:08:03 +01:00
|
|
|
If this driver is linked before libogc, this will replace the original
|
2010-02-22 22:29:47 +01:00
|
|
|
usbstorage driver by svpe from libogc
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
1. The origin of this software must not be misrepresented; you
|
2010-02-22 22:29:47 +01:00
|
|
|
must not claim that you wrote the original software. If you use
|
|
|
|
this software in a product, an acknowledgment in the product
|
|
|
|
documentation would be appreciated but is not required.
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
2. Altered source versions must be plainly marked as such, and
|
2010-02-22 22:29:47 +01:00
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
3. This notice may not be removed or altered from any source
|
2010-02-22 22:29:47 +01:00
|
|
|
distribution.
|
|
|
|
|
|
|
|
-------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "usbstorage2.h"
|
|
|
|
|
|
|
|
/* IOCTL commands */
|
2010-09-19 01:16:05 +02:00
|
|
|
#define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8))
|
|
|
|
#define USB_IOCTL_UMS_INIT (UMS_BASE+0x1)
|
2010-02-22 22:29:47 +01:00
|
|
|
#define USB_IOCTL_UMS_GET_CAPACITY (UMS_BASE+0x2)
|
|
|
|
#define USB_IOCTL_UMS_READ_SECTORS (UMS_BASE+0x3)
|
2010-09-19 01:16:05 +02:00
|
|
|
#define USB_IOCTL_UMS_WRITE_SECTORS (UMS_BASE+0x4)
|
|
|
|
#define USB_IOCTL_UMS_READ_STRESS (UMS_BASE+0x5)
|
|
|
|
#define USB_IOCTL_UMS_SET_VERBOSE (UMS_BASE+0x6)
|
|
|
|
#define USB_IOCTL_UMS_UMOUNT (UMS_BASE+0x10)
|
|
|
|
#define USB_IOCTL_UMS_WATCHDOG (UMS_BASE+0x80)
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
#define USB_IOCTL_UMS_TESTMODE (UMS_BASE+0x81)
|
2010-02-22 22:29:47 +01:00
|
|
|
|
|
|
|
#define WBFS_BASE (('W'<<24)|('F'<<16)|('S'<<8))
|
2010-09-19 01:16:05 +02:00
|
|
|
#define USB_IOCTL_WBFS_OPEN_DISC (WBFS_BASE+0x1)
|
|
|
|
#define USB_IOCTL_WBFS_READ_DISC (WBFS_BASE+0x2)
|
|
|
|
#define USB_IOCTL_WBFS_READ_DIRECT_DISC (WBFS_BASE+0x3)
|
|
|
|
#define USB_IOCTL_WBFS_STS_DISC (WBFS_BASE+0x4)
|
|
|
|
#define USB_IOCTL_WBFS_SET_DEVICE (WBFS_BASE+0x50)
|
2010-05-29 09:38:54 +02:00
|
|
|
#define USB_IOCTL_WBFS_SET_FRAGLIST (WBFS_BASE+0x51)
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
#define UMS_HEAPSIZE 0x1000 //0x10000
|
2010-02-22 22:29:47 +01:00
|
|
|
|
|
|
|
/* Variables */
|
2010-09-19 01:16:05 +02:00
|
|
|
static char fs[] ATTRIBUTE_ALIGN( 32 ) = "/dev/usb2";
|
|
|
|
static char fs2[] ATTRIBUTE_ALIGN( 32 ) = "/dev/usb/ehc";
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static char fsoff[] ATTRIBUTE_ALIGN( 32 ) = "/dev/usb2/OFF";
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-02-22 22:29:47 +01:00
|
|
|
static s32 hid = -1, fd = -1;
|
|
|
|
static u32 sector_size;
|
2010-09-19 01:16:05 +02:00
|
|
|
static int mounted = 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_Umount( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( fd >= 0 && mounted )
|
|
|
|
{
|
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_UMOUNT, ":" );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return IPC_ENOENT;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_Watchdog( u32 on_off )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( fd >= 0 )
|
|
|
|
{
|
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_WATCHDOG, "i:", on_off );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return IPC_ENOENT;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_TestMode( u32 on_off )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( fd >= 0 )
|
|
|
|
{
|
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_TESTMODE, "i:", on_off );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return IPC_ENOENT;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
inline s32 __USBStorage2_isMEM2Buffer( const void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 high_addr = ( ( u32 )buffer ) >> 24;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ( high_addr == 0x90 ) || ( high_addr == 0xD0 );
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_GetCapacity( u32 *_sector_size )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( fd >= 0 )
|
|
|
|
{
|
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", §or_size );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( ret && _sector_size )
|
|
|
|
*_sector_size = sector_size;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return IPC_ENOENT;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_EHC_Off( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
USBStorage2_Deinit();
|
|
|
|
fd = IOS_Open( fsoff, 0 );
|
|
|
|
USBStorage2_Deinit();
|
|
|
|
return 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_Init( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret, ret2;
|
|
|
|
static u32 sector_size = 0;
|
|
|
|
|
|
|
|
/* Already open */
|
|
|
|
if ( fd >= 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Create heap */
|
|
|
|
if ( hid < 0 )
|
|
|
|
{
|
|
|
|
hid = iosCreateHeap( UMS_HEAPSIZE );
|
|
|
|
if ( hid < 0 )
|
|
|
|
return IPC_ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open USB device */
|
|
|
|
fd = IOS_Open( fs, 0 );
|
|
|
|
if ( fd < 0 ) fd = IOS_Open( fs2, 0 );
|
|
|
|
|
|
|
|
if ( fd < 0 )
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
/* Initialize USB storage */
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_INIT, ":" );
|
|
|
|
if ( ret < 0 ) goto err;
|
|
|
|
if ( ret > 1 ) ret = 0;
|
|
|
|
ret2 = ret;
|
|
|
|
|
|
|
|
/* Get device capacity */
|
|
|
|
ret = USBStorage2_GetCapacity( §or_size );
|
|
|
|
if ( !ret )
|
|
|
|
{
|
|
|
|
ret = -1;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if ( ret2 == 0 && sector_size != 512 ) // check for HD sector size 512 bytes
|
|
|
|
{
|
|
|
|
ret = -20001;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if ( ret2 == 1 && sector_size != 2048 ) // check for DVD sector size 2048 bytes
|
|
|
|
{
|
|
|
|
ret = -20002;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
mounted = 1;
|
|
|
|
return ret2; // 0->HDD, 1->DVD
|
2010-02-22 22:29:47 +01:00
|
|
|
|
|
|
|
err:
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Close USB device */
|
|
|
|
if ( fd >= 0 )
|
|
|
|
{
|
|
|
|
IOS_Close( fd );
|
|
|
|
fd = -1;
|
|
|
|
}
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void USBStorage2_Deinit( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
mounted = 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Close USB device */
|
|
|
|
if ( fd >= 0 )
|
|
|
|
{
|
|
|
|
IOS_Close( fd );
|
|
|
|
fd = -1;
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
extern void* SYS_AllocArena2MemLo( u32 size, u32 align );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static void *mem2_ptr = NULL;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_ReadSectors( u32 sector, u32 numSectors, void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
void *buf = ( void * )buffer;
|
|
|
|
u32 len = ( sector_size * numSectors );
|
|
|
|
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* Device not opened */
|
|
|
|
if ( fd < 0 )
|
|
|
|
return fd;
|
|
|
|
if ( !mem2_ptr ) mem2_ptr = SYS_AllocArena2MemLo( 2048 * 256, 32 );
|
|
|
|
/* MEM1 buffer */
|
|
|
|
if ( !__USBStorage2_isMEM2Buffer( buffer ) )
|
|
|
|
{
|
|
|
|
/* Allocate memory */
|
|
|
|
buf = mem2_ptr; //iosAlloc(hid, len);
|
|
|
|
if ( !buf )
|
|
|
|
return IPC_ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read data */
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_READ_SECTORS, "ii:d", sector, numSectors, buf, len );
|
|
|
|
|
|
|
|
/* Copy data */
|
|
|
|
if ( buf != buffer )
|
|
|
|
{
|
|
|
|
memcpy( buffer, buf, len );
|
|
|
|
//iosFree(hid, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage2_WriteSectors( u32 sector, u32 numSectors, const void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
void *buf = ( void * )buffer;
|
|
|
|
u32 len = ( sector_size * numSectors );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Device not opened */
|
|
|
|
if ( fd < 0 )
|
|
|
|
return fd;
|
|
|
|
if ( !mem2_ptr ) mem2_ptr = SYS_AllocArena2MemLo( 2048 * 256, 32 );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* MEM1 buffer */
|
|
|
|
if ( !__USBStorage2_isMEM2Buffer( buffer ) )
|
|
|
|
{
|
|
|
|
/* Allocate memory */
|
|
|
|
buf = mem2_ptr; //buf = iosAlloc(hid, len);
|
|
|
|
if ( !buf )
|
|
|
|
return IPC_ENOMEM;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Copy data */
|
|
|
|
memcpy( buf, buffer, len );
|
|
|
|
}
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Write data */
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_UMS_WRITE_SECTORS, "ii:d", sector, numSectors, buf, len );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Free memory */
|
|
|
|
if ( buf != buffer )
|
|
|
|
iosFree( hid, buf );
|
2010-02-25 15:55:42 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_Startup( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
return USBStorage2_Init() == 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_IsInserted( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
return ( USBStorage2_GetCapacity( NULL ) >= 0 );
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_ReadSectors( u32 sector, u32 numSectors, void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 retval;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
retval = USBStorage2_ReadSectors( sector, numSectors, buffer );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( retval < 0 )
|
|
|
|
return false;
|
|
|
|
return true;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_WriteSectors( u32 sector, u32 numSectors, const void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 retval;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
retval = USBStorage2_WriteSectors( sector, numSectors, buffer );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( retval < 0 )
|
|
|
|
return false;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return true;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_ClearStatus( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
return true;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __usbstorage_Shutdown( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
//if(mounted) USBStorage2_Umount();
|
|
|
|
USBStorage2_Deinit();
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
mounted = 0;
|
|
|
|
return true;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
const DISC_INTERFACE __io_usbstorage2 =
|
|
|
|
{
|
|
|
|
DEVICE_TYPE_WII_UMS,
|
|
|
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_USB,
|
|
|
|
( FN_MEDIUM_STARTUP )&__usbstorage_Startup,
|
|
|
|
( FN_MEDIUM_ISINSERTED )&__usbstorage_IsInserted,
|
|
|
|
( FN_MEDIUM_READSECTORS )&__usbstorage_ReadSectors,
|
|
|
|
( FN_MEDIUM_WRITESECTORS )&__usbstorage_WriteSectors,
|
|
|
|
( FN_MEDIUM_CLEARSTATUS )&__usbstorage_ClearStatus,
|
|
|
|
( FN_MEDIUM_SHUTDOWN )&__usbstorage_Shutdown
|
2010-02-22 22:29:47 +01:00
|
|
|
};
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool __io_usb_ReadSectors( u32 sector, u32 count, void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret = USBStorage2_ReadSectors( sector, count, buffer );
|
|
|
|
return ret > 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bool __io_usb_WriteSectors( u32 sector, u32 count, void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret = USBStorage2_WriteSectors( sector, count, buffer );
|
|
|
|
return ret > 0;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static bool __io_usb_NOP( void )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
// do nothing
|
|
|
|
return true;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
const DISC_INTERFACE __io_usbstorage2_ro =
|
|
|
|
{
|
|
|
|
DEVICE_TYPE_WII_UMS,
|
|
|
|
FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_USB,
|
|
|
|
( FN_MEDIUM_STARTUP )&__usbstorage_Startup,
|
|
|
|
( FN_MEDIUM_ISINSERTED )&__usbstorage_IsInserted,
|
|
|
|
( FN_MEDIUM_READSECTORS )&__usbstorage_ReadSectors,
|
|
|
|
( FN_MEDIUM_WRITESECTORS )&__io_usb_NOP,
|
|
|
|
( FN_MEDIUM_CLEARSTATUS )&__usbstorage_ClearStatus,
|
|
|
|
( FN_MEDIUM_SHUTDOWN )&__usbstorage_Shutdown
|
2010-02-22 22:29:47 +01:00
|
|
|
};
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage_WBFS_Open( char *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 len = 8;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Device not opened */
|
|
|
|
if ( fd < 0 )
|
|
|
|
return fd;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
extern u32 wbfs_part_lba;
|
|
|
|
u32 part = wbfs_part_lba;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Read data */
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_WBFS_OPEN_DISC, "dd:", buffer, len, &part, 4 );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// woffset is in 32bit words, len is in bytes
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage_WBFS_Read( u32 woffset, u32 len, void *buffer )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
USBStorage2_Init();
|
|
|
|
/* Device not opened */
|
|
|
|
if ( fd < 0 )
|
|
|
|
return fd;
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Read data */
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_WBFS_READ_DISC, "ii:d", woffset, len, buffer, len );
|
2010-02-22 22:29:47 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage_WBFS_SetDevice( int dev )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
|
|
|
static s32 retval = 0;
|
|
|
|
retval = 0;
|
|
|
|
USBStorage2_Init();
|
|
|
|
// Device not opened
|
|
|
|
if ( fd < 0 ) return fd;
|
|
|
|
// ioctl
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_WBFS_SET_DEVICE, "i:i", dev, &retval );
|
|
|
|
if ( retval ) return retval;
|
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 USBStorage_WBFS_SetFragList( void *p, int size )
|
2010-02-22 22:29:47 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
|
|
|
USBStorage2_Init();
|
|
|
|
// Device not opened
|
|
|
|
if ( fd < 0 ) return fd;
|
|
|
|
// ioctl
|
|
|
|
ret = IOS_IoctlvFormat( hid, fd, USB_IOCTL_WBFS_SET_FRAGLIST, "d:", p, size );
|
|
|
|
return ret;
|
2010-02-22 22:29:47 +01:00
|
|
|
}
|