-added thread for IOS58 mode which reads a random sector from the

usb hdd every second if the hdd is more than 20 seconds idle to
keep it alive, it gets resetted as soon as wiiflow does some action
with it
This commit is contained in:
fix94.1 2012-09-11 17:09:14 +00:00
parent 49ada11bb9
commit d7e5460f31
5 changed files with 138 additions and 4 deletions

View File

@ -33,6 +33,7 @@
#include "DeviceHandler.hpp" #include "DeviceHandler.hpp"
#include "defines.h" #include "defines.h"
#include "sdhc.h" #include "sdhc.h"
#include "usbthread.h"
#include "usbstorage.h" #include "usbstorage.h"
#include "usbstorage_libogc.h" #include "usbstorage_libogc.h"
#include "loader/cios.h" #include "loader/cios.h"
@ -69,6 +70,9 @@ void DeviceHandler::MountAll()
void DeviceHandler::UnMountAll() void DeviceHandler::UnMountAll()
{ {
/* Kill possible USB thread */
KillUSBKeepAliveThread();
for(u32 i = SD; i < MAXDEVICES; i++) for(u32 i = SD; i < MAXDEVICES; i++)
UnMount(i); UnMount(i);
@ -172,6 +176,8 @@ bool DeviceHandler::MountUSB(int pos)
bool DeviceHandler::MountAllUSB() bool DeviceHandler::MountAllUSB()
{ {
/* Kill possible USB thread */
KillUSBKeepAliveThread();
/* Wait for our slowass HDD */ /* Wait for our slowass HDD */
WaitForDevice(GetUSB0Interface()); WaitForDevice(GetUSB0Interface());
/* Get Partitions and Mount them */ /* Get Partitions and Mount them */
@ -190,9 +196,12 @@ bool DeviceHandler::MountAllUSB()
if(MountUSB(i)) if(MountUSB(i))
result = true; result = true;
} }
if(result && usb_libogc_mode)
CreateUSBKeepAliveThread();
return result; return result;
} }
/*
bool DeviceHandler::MountUSBPort1() bool DeviceHandler::MountUSBPort1()
{ {
if(!usb1)// && (Settings.USBPort == 1 || Settings.USBPort == 2)) if(!usb1)// && (Settings.USBPort == 1 || Settings.USBPort == 2))
@ -219,6 +228,7 @@ bool DeviceHandler::MountUSBPort1()
return result; return result;
} }
*/
void DeviceHandler::UnMountUSB(int pos) void DeviceHandler::UnMountUSB(int pos)
{ {
@ -304,7 +314,6 @@ int DeviceHandler::GetFSType(int dev)
return -1; return -1;
} }
u16 DeviceHandler::GetUSBPartitionCount() u16 DeviceHandler::GetUSBPartitionCount()
{ {
if(!instance) if(!instance)

View File

@ -34,6 +34,7 @@
#include "usbstorage.h" #include "usbstorage.h"
#include "usbstorage_libogc.h" #include "usbstorage_libogc.h"
#include "usbthread.h"
#include "gecko/gecko.h" #include "gecko/gecko.h"
/* IOCTL commands */ /* IOCTL commands */
@ -90,6 +91,7 @@ s32 USBStorage2_Init(u32 port)
if(usb_libogc_mode) if(usb_libogc_mode)
{ {
USBKeepAliveThreadReset();
__io_usbstorage_ogc.startup(); __io_usbstorage_ogc.startup();
return (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0) ? IPC_ENOENT : 0; return (USBStorage2_GetCapacity(port, &hdd_sector_size[port]) == 0) ? IPC_ENOENT : 0;
} }
@ -128,7 +130,10 @@ void USBStorage2_Deinit()
{ {
/* Close USB device */ /* Close USB device */
if(usb_libogc_mode) if(usb_libogc_mode)
{
USBKeepAliveThreadReset();
__io_usbstorage_ogc.shutdown(); __io_usbstorage_ogc.shutdown();
}
else if(fd >= 0) else if(fd >= 0)
IOS_Close(fd); // not sure to close the fd is needed IOS_Close(fd); // not sure to close the fd is needed
@ -176,7 +181,10 @@ s32 USBStorage2_GetCapacity(u32 port, u32 *_sector_size)
u32 sectorSize = 0; u32 sectorSize = 0;
USBStorage2_SetPort(port); USBStorage2_SetPort(port);
if(usb_libogc_mode) if(usb_libogc_mode)
{
USBKeepAliveThreadReset();
USB_OGC_GetCapacity(&numSectors, &sectorSize); USB_OGC_GetCapacity(&numSectors, &sectorSize);
}
else else
numSectors = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", &sectorSize); numSectors = IOS_IoctlvFormat(hid, fd, USB_IOCTL_UMS_GET_CAPACITY, ":i", &sectorSize);
@ -201,12 +209,19 @@ s32 USBStorage2_GetCapacity(u32 port, u32 *_sector_size)
s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer) s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer)
{ {
s32 ret = -1;
if(usb_libogc_mode) if(usb_libogc_mode)
return __io_usbstorage_ogc.readSectors(sector, numSectors, buffer); {
USBKeepAliveThreadReset();
reading = true;
ret = __io_usbstorage_ogc.readSectors(sector, numSectors, buffer);
reading = false;
return ret;
}
bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer); bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer);
u8 *buf = (u8 *)buffer; u8 *buf = (u8 *)buffer;
s32 ret = -1;
/* Device not opened */ /* Device not opened */
if(fd < 0) if(fd < 0)
@ -251,7 +266,10 @@ s32 USBStorage2_ReadSectors(u32 port, u32 sector, u32 numSectors, void *buffer)
s32 USBStorage2_WriteSectors(u32 port, u32 sector, u32 numSectors, const void *buffer) s32 USBStorage2_WriteSectors(u32 port, u32 sector, u32 numSectors, const void *buffer)
{ {
if(usb_libogc_mode) if(usb_libogc_mode)
{
USBKeepAliveThreadReset();
return __io_usbstorage_ogc.writeSectors(sector, numSectors, buffer); return __io_usbstorage_ogc.writeSectors(sector, numSectors, buffer);
}
bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer); bool isMEM2Buffer = __USBStorage_isMEM2Buffer(buffer);
u8 *buf = (u8 *)buffer; u8 *buf = (u8 *)buffer;

View File

@ -0,0 +1,73 @@
/****************************************************************************
* Copyright (C) 2012 FIX94
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <ogc/cache.h>
#include <ogc/lwp.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include "usbthread.h"
#include "usbstorage.h"
#include "gecko/gecko.h"
lwp_t USB_Thread = LWP_THREAD_NULL;
volatile bool CheckUSB = false;
volatile bool idle = false;
volatile time_t start = 0;
u8 sector[4096];
void *KeepUSBAlive(void *nothing)
{
int NumberSectors = USBStorage2_GetCapacity(0, NULL);
start = time(NULL);
srand(start);
while(CheckUSB)
{
if(idle || (time(NULL) - start) > 19)
{
USBStorage2_ReadSectors(0, rand() % NumberSectors, 1, sector);
idle = true;
}
sleep(1);
}
return nothing;
}
void CreateUSBKeepAliveThread()
{
CheckUSB = true;
LWP_CreateThread(&USB_Thread, KeepUSBAlive, NULL, NULL, 0, 40);
}
void KillUSBKeepAliveThread()
{
CheckUSB = false;
USBKeepAliveThreadReset();
if(USB_Thread != LWP_THREAD_NULL)
{
LWP_JoinThread(USB_Thread, NULL);
USB_Thread = LWP_THREAD_NULL;
}
}
void USBKeepAliveThreadReset()
{
while(reading)
usleep(100);
start = time(NULL);
idle = false;
}

View File

@ -0,0 +1,34 @@
/****************************************************************************
* Copyright (C) 2012 FIX94
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef _USBTHREAD_H_
#define _USBTHREAD_H_
#ifdef __cplusplus
extern "C"
{
#endif
void CreateUSBKeepAliveThread();
void KillUSBKeepAliveThread();
void USBKeepAliveThreadReset();
static volatile bool reading = false;
#ifdef __cplusplus
}
#endif
#endif /* _USBTHREAD_H_ */

View File

@ -44,7 +44,7 @@ void Open_Inputs(void)
WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR); WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetIdleTimeout(60*5); // idle after 5 minutes WPAD_SetIdleTimeout(60 * 2); // idle after 2 minutes
} }
void Close_Inputs(void) void Close_Inputs(void)