add USB/SD hot-swap!

This commit is contained in:
dborth 2008-10-28 06:50:07 +00:00
parent 00a5439321
commit 9cf7e9904d
2 changed files with 66 additions and 54 deletions

View File

@ -27,77 +27,84 @@
FILE * fatfile; FILE * fatfile;
/**************************************************************************** /****************************************************************************
* fat_is_mounted * MountFAT
* to check whether FAT media are detected. * Attempts to mount the FAT device specified
****************************************************************************/ * Sets libfat to use the device by default
* Enables read-ahead cache for SD/USB
***************************************************************************/
bool MountFAT(PARTITION_INTERFACE part)
{
bool mounted = fatMountNormalInterface(part, 8);
bool FatIsMounted(PARTITION_INTERFACE partition) { if(mounted)
char prefix[] = "fatX:/"; {
prefix[3] = partition + '0'; fatSetDefaultInterface(part);
DIR_ITER *dir = diropen(prefix); #ifdef HW_RVL
if (dir) { if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
dirclose(dir); fatEnableReadAhead (part, 6, 64);
return true; #endif
} }
return false; return mounted;
} }
/**************************************************************************** /****************************************************************************
* changeFATInterface * UnmountFAT
* Checks if the device (method) specified is available, and * Unmounts the FAT device specified
* sets libfat to use the device ***************************************************************************/
****************************************************************************/ void UnmountFAT(PARTITION_INTERFACE part)
{
if(!fatUnmount(part))
fatUnsafeUnmount(part);
}
/****************************************************************************
* UnmountAllFAT
* Unmounts all FAT devices
***************************************************************************/
void UnmountAllFAT()
{
#ifdef HW_RVL
UnmountFAT(PI_INTERNAL_SD);
UnmountFAT(PI_USBSTORAGE);
#endif
UnmountFAT(PI_SDGECKO_A);
UnmountFAT(PI_SDGECKO_B);
}
/****************************************************************************
* ChangeFATInterface
* Unmounts all devices and attempts to mount/configure the device specified
***************************************************************************/
bool ChangeFATInterface(int method, bool silent) bool ChangeFATInterface(int method, bool silent)
{ {
bool devFound = false; bool mounted = false;
// unmount all FAT devices
UnmountAllFAT();
if(method == METHOD_SD) if(method == METHOD_SD)
{ {
// check which SD device is loaded
#ifdef HW_RVL #ifdef HW_RVL
if (FatIsMounted(PI_INTERNAL_SD)) mounted = MountFAT(PI_INTERNAL_SD); // try Wii internal SD
{
devFound = true;
fatSetDefaultInterface(PI_INTERNAL_SD);
fatEnableReadAhead (PI_INTERNAL_SD, 6, 64);
}
#endif #endif
if (!devFound && FatIsMounted(PI_SDGECKO_A)) if(!mounted) // internal SD not found
{ mounted = MountFAT(PI_SDGECKO_A); // try SD Gecko on slot A
devFound = true; if(!mounted) // internal SD and SD Gecko (on slot A) not found
fatSetDefaultInterface(PI_SDGECKO_A); mounted = MountFAT(PI_SDGECKO_B); // try SD Gecko on slot B
} if(!mounted && !silent) // no SD device found
if(!devFound && FatIsMounted(PI_SDGECKO_B))
{
devFound = true;
fatSetDefaultInterface(PI_SDGECKO_B);
}
if(!devFound)
{
if(!silent)
WaitPrompt ((char *)"SD card not found!"); WaitPrompt ((char *)"SD card not found!");
} }
}
else if(method == METHOD_USB) else if(method == METHOD_USB)
{ {
#ifdef HW_RVL #ifdef HW_RVL
if(FatIsMounted(PI_USBSTORAGE)) mounted = MountFAT(PI_USBSTORAGE);
{ if(!mounted && !silent)
devFound = true; WaitPrompt ((char *)"USB drive not found!");
fatSetDefaultInterface(PI_USBSTORAGE);
fatEnableReadAhead (PI_USBSTORAGE, 6, 64);
}
else
{
if(!silent)
WaitPrompt ((char *)"USB flash drive not found!");
}
#endif #endif
} }
return devFound; return mounted;
} }
/*************************************************************************** /***************************************************************************

View File

@ -404,7 +404,7 @@ int FileSelector (int method)
if (!maxfiles) if (!maxfiles)
{ {
WaitPrompt ((char*) "Error reading directory !"); WaitPrompt ((char*) "Error reading directory!");
haverom = 1; // quit menu haverom = 1; // quit menu
} }
} }
@ -415,6 +415,11 @@ int FileSelector (int method)
} }
else // this is a file else // this is a file
{ {
// better do another unmount/remount, just in case
if(method == METHOD_SD || method == METHOD_USB)
if(!ChangeFATInterface(method, NOTSILENT))
return 0;
// 7z file - let's open it up to select a file inside // 7z file - let's open it up to select a file inside
if(IsSz()) if(IsSz())
{ {
@ -422,7 +427,7 @@ int FileSelector (int method)
if(!MakeROMPath(szpath, method)) if(!MakeROMPath(szpath, method))
{ {
WaitPrompt((char*) "Maximum filepath length reached!"); WaitPrompt((char*) "Maximum filepath length reached!");
return -1; return 0;
} }
int szfiles = SzParse(szpath, method); int szfiles = SzParse(szpath, method);
if(szfiles) if(szfiles)