2929#include <unistd.h>
3030#include <sys/dir.h>
3131#include "fileBrowser.h"
32+ #include "../main/ata.h"
3233#include <sdcard/gcsd.h>
3334
34- extern BOOL hasLoadedROM ;
3535extern int stop ;
3636
3737#ifdef HW_RVL
@@ -42,16 +42,19 @@ extern int stop;
4242#include <sdcard/wiisd_io.h>
4343#include <ogc/usbstorage.h>
4444const DISC_INTERFACE * frontsd = & __io_wiisd ;
45- const DISC_INTERFACE * usb = & __io_usbstorage ;
45+ const DISC_INTERFACE * usbmsd = & __io_usbstorage ;
4646#endif
4747const DISC_INTERFACE * carda = & __io_gcsda ;
4848const DISC_INTERFACE * cardb = & __io_gcsdb ;
49+ const DISC_INTERFACE * ideexia = & __io_ataa ;
50+ const DISC_INTERFACE * ideexib = & __io_atab ;
4951
5052// Threaded insertion/removal detection
5153#define THREAD_SLEEP 100
52- #define FRONTSD 1
53- #define CARD_A 2
54- #define CARD_B 3
54+ #define CARD_A 1
55+ #define CARD_B 2
56+ #define FRONTSD 3
57+ #define USBMSD 3
5558static lwp_t removalThread = LWP_THREAD_NULL ;
5659static int rThreadRun = 0 ;
5760static int rThreadCreated = 0 ;
@@ -128,36 +131,16 @@ static void *removalCallback (void *arg)
128131
129132 while (1 )
130133 {
131- switch (sdMounted ) //some kind of SD is mounted
132- {
133- #ifdef HW_RVL
134- case FRONTSD : //check which one, if removed, set as unmounted
135- if (!frontsd -> isInserted ()) {
136- sdNeedsUnmount = sdMounted ;
137- sdMounted = 0 ;
138- }
139- break ;
140- #endif
141- /* //Polling EXI is bad with locks, so lets not do it.
142- case CARD_A: //check which one, if removed, set as unmounted
143- if(!carda->isInserted()) {
144- sdNeedsUnmount=sdMounted;
145- sdMounted=0;
146- }
147- break;
148- case CARD_B: //check which one, if removed, set as unmounted
149- if(!cardb->isInserted()) {
150- sdNeedsUnmount=sdMounted;
151- sdMounted=0;
152- }
153- break;
154- */
155- }
156134#ifdef HW_RVL
157- if (usbMounted ) // check if the device was removed
158- if (!usb -> isInserted ()) {
135+ if (sdMounted == FRONTSD )
136+ if (!frontsd -> isInserted ()) {
137+ sdNeedsUnmount = FRONTSD ;
138+ sdMounted = 0 ;
139+ }
140+ if (usbMounted == USBMSD )
141+ if (!usbmsd -> isInserted ()) {
142+ usbNeedsUnmount = USBMSD ;
159143 usbMounted = 0 ;
160- usbNeedsUnmount = 1 ;
161144 }
162145#endif
163146
@@ -265,26 +248,21 @@ int fileBrowser_libfat_init(fileBrowser_file* f){
265248 if (f -> name [0 ] == 's' ) { //SD
266249 if (!sdMounted ) { //if there's nothing currently mounted
267250 pauseRemovalThread ();
268- if (sdNeedsUnmount ) {
251+ if (sdNeedsUnmount == FRONTSD ) {
269252 fatUnmount ("sd" );
270- if (sdNeedsUnmount == FRONTSD )
271- frontsd -> shutdown ();
272- else if (sdNeedsUnmount == CARD_A )
273- carda -> shutdown ();
274- else if (sdNeedsUnmount == CARD_B )
275- cardb -> shutdown ();
253+ frontsd -> shutdown ();
276254 sdNeedsUnmount = 0 ;
277255 }
278256 if (fatMountSimple ("sd" , frontsd )) {
279257 sdMounted = FRONTSD ;
280258 res = 1 ;
281259 }
282- else if (fatMountSimple ("sd" , carda )) {
283- sdMounted = CARD_A ;
260+ else if (fatMountSimple ("sd" , cardb )) {
261+ sdMounted = CARD_B ;
284262 res = 1 ;
285263 }
286- else if (fatMountSimple ("sd" , cardb )) {
287- sdMounted = CARD_B ;
264+ else if (fatMountSimple ("sd" , carda )) {
265+ sdMounted = CARD_A ;
288266 res = 1 ;
289267 }
290268 continueRemovalThread ();
@@ -296,47 +274,63 @@ int fileBrowser_libfat_init(fileBrowser_file* f){
296274 else if (f -> name [0 ] == 'u' ) {
297275 if (!usbMounted ) {
298276 pauseRemovalThread ();
299- if (usbNeedsUnmount ) {
277+ if (usbNeedsUnmount == USBMSD ) {
300278 fatUnmount ("usb" );
301- usb -> shutdown ();
279+ usbmsd -> shutdown ();
302280 usbNeedsUnmount = 0 ;
303281 }
304- if (fatMountSimple ("usb" , usb ))
305- usbMounted = 1 ;
282+ usleep (devsleep );
283+ if (fatMountSimple ("usb" , usbmsd )) {
284+ usbMounted = USBMSD ;
285+ res = 1 ;
286+ }
287+ else if (fatMountSimple ("usb" , ideexib )) {
288+ usbMounted = CARD_B ;
289+ res = 1 ;
290+ }
291+ else if (fatMountSimple ("usb" , ideexia )) {
292+ usbMounted = CARD_A ;
293+ res = 1 ;
294+ }
306295 continueRemovalThread ();
307- return usbMounted ;
296+ return res ;
308297 }
309298 else
310299 return 1 ;
311300 }
312- return res ;
313301#else
314- if (!sdMounted ) { //GC has only SD
315-
316- if (sdNeedsUnmount ) fatUnmount ("sd" );
317- switch (sdNeedsUnmount ){ //unmount previous devices
318- case CARD_A :
319- carda -> shutdown ();
320- break ;
321- case CARD_B :
322- cardb -> shutdown ();
323- break ;
302+ if (f -> name [0 ] == 's' ) {
303+ if (!sdMounted ) {
304+ if (fatMountSimple ("sd" , cardb )) {
305+ sdMounted = CARD_B ;
306+ res = 1 ;
307+ }
308+ else if (fatMountSimple ("sd" , carda )) {
309+ sdMounted = CARD_A ;
310+ res = 1 ;
311+ }
312+ return res ;
313+ }
314+ else
315+ return 1 ;
316+ }
317+ else if (f -> name [0 ] == 'u' ) {
318+ if (!usbMounted ) {
319+ if (fatMountSimple ("usb" , ideexib )) {
320+ usbMounted = CARD_B ;
321+ res = 1 ;
322+ }
323+ else if (fatMountSimple ("usb" , ideexia )) {
324+ usbMounted = CARD_A ;
325+ res = 1 ;
326+ }
327+ return res ;
324328 }
325- if (carda -> startup ()) {
326- res |= fatMountSimple ("sd" , carda );
327- if (res )
328- sdMounted = CARD_A ;
329- }
330- else if (cardb -> startup () && !res ) {
331- res |= fatMountSimple ("sd" , cardb );
332- if (res )
333- sdMounted = CARD_B ;
334- }
335-
336- return res ;
329+ else
330+ return 1 ;
337331 }
338- return 1 ; //we're always ok
339332#endif
333+ return res ;
340334}
341335
342336int fileBrowser_libfat_deinit (fileBrowser_file * f ){
0 commit comments