bool USB::Mount() { if (isMounted) return true; gprintf("Mounting USB Drive \n"); USB::Unmount(); // To Hopefully Wake Up The Drive fatMountSimple("usb", &__io_usbstorage); bool isInserted = __io_usbstorage.isInserted(); gprintf("USB::IsInserted = %d\n", isInserted); if (!isInserted) return false; // USB Drive may be "sleeeeping". // We need to try Mounting a few times to wake it up int retry = 10; while (retry) { isMounted = fatMountSimple("usb", &__io_usbstorage); if (isMounted) break; sleep(1); retry--; } if (isMounted) gprintf("USB Drive Is Mounted\n"); return isMounted; }
bool InitUSB() { printf("Initializing USB FAT subsytem ...\n\n"); fatUnmount("usb:"); // This should wake up the drive bool isMounted = fatMountSimple("usb", &__io_usbstorage); bool isInserted = __io_usbstorage.isInserted(); if (!isInserted) { printf("USB device not found\n\n"); return false; } // USB Drive may be "sleeeeping" // We need to try Mounting a few times to wake it up int retry = 10; while (retry && !isMounted) { sleep(1); isMounted = fatMountSimple("usb", &__io_usbstorage); retry--; } return isMounted; }
/* * Mounts the file system * * return Whether we mounted the file system successfully */ BOOL wii_mount() { if( !mounted ) { if( wii_is_usb ) { if( !__io_usbstorage.startup() || !fatMountSimple( "usb", &__io_usbstorage ) ) { return FALSE; } } else { if( !__io_wiisd.startup() || !fatMountSimple( "sd", &__io_wiisd ) ) { return FALSE; } } chdir( wii_get_app_path() ); mounted = TRUE; } return TRUE; }
static int initFAT(){ int slotagecko = 0; int i =0; s32 ret, memsize, sectsize; for(i=0;i<10;i++){ ret = CARD_ProbeEx(CARD_SLOTA, &memsize, §size); //printf("Ret: %d", ret); if (ret == CARD_ERROR_WRONGDEVICE){ slotagecko = 1; break; } } if (slotagecko) {//Memcard in SLOT B, SD gecko in SLOT A //This will ensure SD gecko is recognized if inserted or changed to another slot after GCMM is executed for(i=0;i<10;i++){ ret = CARD_Probe(CARD_SLOTA); if (ret == CARD_ERROR_WRONGDEVICE) //printf ("SDGecko detected...\n\n"); break; } __io_gcsda.startup(); if (!__io_gcsda.isInserted()) { //printf ("No SD Gecko inserted! Using embedded config.\n\n"); return 0; } if (!fatMountSimple ("fat", &__io_gcsda)) { //printf("Error Mounting SD fat! Using embedded config.\n\n"); return 0; } }else //Memcard in SLOT A, SD gecko in SLOT B { //This will ensure SD gecko is recognized if inserted or changed to another slot after GCMM is executed for(i=0;i<10;i++){ ret = CARD_Probe(CARD_SLOTB); if (ret == CARD_ERROR_WRONGDEVICE) break; } __io_gcsdb.startup(); if (!__io_gcsdb.isInserted()) { //printf ("No SD Gecko inserted! Using default config.\n\n"); return 0; } if (!fatMountSimple ("fat", &__io_gcsdb)) { //printf("Error Mounting SD fat! Using default config.\n\n"); return 0; } } return 1; }
static void frontend_gx_init(void *data) { (void)data; #ifdef HW_RVL IOS_ReloadIOS(IOS_GetVersion()); L2Enhance(); #ifndef IS_SALAMANDER gx_init_mem2(); #endif #endif #if defined(DEBUG) && defined(IS_SALAMANDER) VIDEO_Init(); GXRModeObj *rmode = VIDEO_GetPreferredMode(NULL); void *xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); #endif #ifndef DEBUG __exception_setreload(8); #endif fatInitDefault(); #ifdef HAVE_LOGGER devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_net; #elif defined(HAVE_FILE_LOGGER) && !defined(IS_SALAMANDER) devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_file; #endif #if defined(HW_RVL) && !defined(IS_SALAMANDER) OSThread gx_device_thread; gx_devices[GX_DEVICE_SD].interface = &__io_wiisd; gx_devices[GX_DEVICE_SD].name = "sd"; gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface); gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage; gx_devices[GX_DEVICE_USB].name = "usb"; gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface); OSInitMutex(&gx_device_cond_mutex); OSInitCond(&gx_device_cond); OSInitMutex(&gx_device_mutex); OSCreateThread(&gx_device_thread, gx_devthread, 0, NULL, NULL, 0, 66, 0); #endif }
void mount_storage() { // Determine from the filepath if sd or usb is used if (filename[0] == 115 && filename[1] == 100) { device = 0; } else { device = 1; } if (device == 0) { if(!SDmounted) { #ifdef DEBUG printf("[+] Mounting SD ... "); #endif // initialize sd storage __io_wiisd.startup(); SDmounted = fatMountSimple("sd", &__io_wiisd); #ifdef DEBUG if(SDmounted) printf("OK!\n"); else printf("FAIL!\n"); #endif } } else { if(!USBmounted) { #ifdef DEBUG printf("[+] Mounting USB ... "); #endif // initialize usb storage __io_usbstorage.startup(); USBmounted = fatMountSimple("usb", &__io_usbstorage); #ifdef DEBUG if(USBmounted) printf("OK!\n"); else printf("FAIL!\n"); #endif } } }
static void gx_devthread(void *a) { unsigned i; while (!gx_stop_dev_thread) { slock_lock(gx_device_mutex); for (i = 0; i < GX_DEVICE_END; i++) { if (gx_devices[i].mounted) { if (!gx_devices[i].interface->isInserted()) { char n[8]; gx_devices[i].mounted = false; snprintf(n, sizeof(n), "%s:", gx_devices[i].name); fatUnmount(n); } } else if (gx_devices[i].interface->startup() && gx_devices[i].interface->isInserted()) gx_devices[i].mounted = fatMountSimple(gx_devices[i].name, gx_devices[i].interface); } slock_unlock(gx_device_mutex); slock_lock(gx_device_cond_mutex); scond_wait_timeout(gx_device_cond, gx_device_cond_mutex, 1000000); slock_unlock(gx_device_cond_mutex); } }
/* call APPLY_SD_CODE with bool apply = true to apply the codes */ u32 do_sd_code() { FILE *fp; u8 *filebuff; u32 filesize; u32 ret; char filepath[128]; memset(gameid, 0, 8); memcpy(gameid, (char*)0x80000000, 6); ret = __io_wiisd.startup(); fatMountSimple("sdhc", &__io_wiisd); if (!ret) { /* sd error */ return 3; } fflush(stdout); sprintf(filepath, FILEDIR "/%s", gameid); filepath[18] = 0x2E; filepath[19] = 0x67; filepath[20] = 0x63; filepath[21] = 0x74; filepath[22] = 0; fp = fopen(filepath, "rb"); if (!fp) { /* no codes found */ fatUnmount("sdhc"); __io_wiisd.shutdown(); return 2; } fseek(fp, 0, SEEK_END); filesize = ftell(fp); fseek(fp, 0, SEEK_SET); filebuff = (u8*) malloc (filesize); if(filebuff == 0){ fclose(fp); return 3; } ret = fread(filebuff, 1, filesize, fp); if(ret != filesize){ /* SD Code Error */ free(filebuff); fclose(fp); fatUnmount("sdhc"); __io_wiisd.shutdown(); return 3; } /* sd codes found */ return 1; }
static void system_init(void) { #ifdef HW_RVL IOS_ReloadIOS(IOS_GetVersion()); L2Enhance(); #ifndef IS_SALAMANDER gx_init_mem2(); #endif #endif #ifndef DEBUG __exception_setreload(8); #endif fatInitDefault(); #ifdef HAVE_LOGGER inl_logger_init(); devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_net; #elif defined(HAVE_FILE_LOGGER) inl_logger_init(); #ifndef IS_SALAMANDER devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_file; #endif #endif #if defined(HW_RVL) && !defined(IS_SALAMANDER) lwp_t gx_device_thread; gx_devices[GX_DEVICE_SD].interface = &__io_wiisd; gx_devices[GX_DEVICE_SD].name = "sd"; gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface); gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage; gx_devices[GX_DEVICE_USB].name = "usb"; gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface); LWP_MutexInit(&gx_device_mutex, false); LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66); #endif }
void Init(void* buffer, int size_bytes) { gInstance = &sInstance; gInstance->buffer = buffer; gInstance->size_bytes = size_bytes; fatMountSimple("fat",&discio); gInstance->devops = GetDeviceOpTab(NULL); int zzz=9; }
void initialise_fat() { __io_wiisd.startup(); if (!fatInitDefault()) die("Unable to initialise FAT subsystem, exiting.\n"); fatMountSimple("sd", &__io_wiisd); DIR_ITER *root = diropen("/"); if (!root) die("Cannot open root dir, exiting.\n"); dirclose(root); if (chdir("/")) die("Could not change to root directory, exiting.\n"); }
void main (int argc, char **argv) { // Init libxenon xenos_init(VIDEO_MODE_AUTO); console_init(); xenon_make_it_faster(XENON_SPEED_FULL); #if 0 threading_init(); network_init_sys(); #endif usb_init(); usb_do_poll(); xenon_ata_init(); xenon_atapi_init(); fatInitDefault(); #ifdef CAPS fatMountSimple("udb", &usb2mass_ops_1); printf("CAPTURE BUILD !!!\n"); #endif // Quake II char * newargv[] = { "uda:/q3.elf", //"+set", "game", "baseq2", "+set", "cddir", "uda:/baseq2/" "+set", "basedir" , "uda:/", "+set", "cddir", "uda:/baseq2/", "+set", "cl_maxfps", "400" }; int newargc = sizeof (newargv) / sizeof (char *); Qcommon_Init (newargc, newargv); console_close(); int time, oldtime, newtime; oldtime = Sys_Milliseconds(); while (1) { do { newtime = Sys_Milliseconds (); time = newtime - oldtime; } while (time < 1); Qcommon_Frame (time); oldtime = newtime; } }
static bool MountFAT(int device, int retryCount) { bool mounted = false; char name[10], name2[10]; const DISC_INTERFACE* disc = NULL; retryCount++; if( retryCount <= 0 ) { retryCount = 1; } switch(device) { case DEVICE_SD: sprintf(name, "sd"); sprintf(name2, "sd:"); disc = sd; break; case DEVICE_USB: sprintf(name, "usb"); sprintf(name2, "usb:"); disc = usb; break; default: return false; // unknown device } if(unmountRequired[device]) { unmountRequired[device] = false; fatUnmount(name2); disc->shutdown(); isMounted[device] = false; } while(retryCount) { if(disc->startup() && fatMountSimple(name, disc)) mounted = true; if(mounted) break; usleep( 1000 * 1000 ); // 1 second retryCount--; } isMounted[device] = mounted; return mounted; }
s32 Init_USB() { if (!__io_usbstorage.startup()) { printf("USB storage error, press any button to exit...\n"); return -1; } if (!fatMountSimple("usb", &__io_usbstorage)) { printf("FAT error, press any button to exit...\n"); return -1; } return 0; }
s32 Fat_MountSDHC(void) { s32 ret; /* Initialize SDHC interface */ ret = __io_sdhc.startup(); if (!ret) return -1; /* Mount device */ ret = fatMountSimple(SDHC_MOUNT, &__io_sdhc); if (!ret) return -2; return 0; }
s32 Fat_Mount(fatDevice *dev) { s32 ret; /* Initialize interface */ ret = dev->interface->startup(); if (!ret) return -1; /* Mount device */ ret = fatMountSimple(dev->mount, dev->interface); if (!ret) return -1; return 0; }
bool GetFileToBoot (void) { bool ret = false; if (ret == false) ret = LoadPostloaderFromISFS (); if (ret == false && fatMountSimple("fat", &__io_wiisd)) { ret = LoadFile("fat://apps/postloader/boot.dol"); fatUnmount("fat:/"); __io_wiisd.shutdown(); } return ret; }
s32 Init_SD() { if (!__io_wiisd.startup()) { printf("SD card error, press any button to exit...\n"); return -1; } if (!fatMountSimple("sd", &__io_wiisd)) { printf("FAT error, press any button to exit...\n"); return -1; } return 0; }
s32 Fat_Mount(fatDevice *dev) { char dirpath[256]; s32 ret; /* Initialize interface */ ret = dev->interface->startup(); if (!ret) return -1; /* Mount device */ ret = fatMountSimple(dev->mount, dev->interface); if (!ret) return -2; /* Set root directory */ sprintf(dirpath, "%s:/", dev->mount); chdir(dirpath); return 0; }
s32 Fat_Mount(int dev){ s32 ret; if(dev==SD) interface=&__io_wiisd; else if(dev==USB) interface=&__io_wiiums; else return -1; // Initialize SDHC interface ret = interface->startup(); if (!ret) return -1; // Mount device ret = fatMountSimple(DEV_MOUNT, interface); if (!ret) return -2; return 0; }
mount_state MountFAT(int device) { if (device >= FAT_DEVICES_COUNT) return NOT_MOUNTED; mount_state mounted = MOUNTED; // assume our disc is already mounted if(isMounted[device] == NOT_MOUNTED) { int mount_attempts = 10; while((!fat_interface[device]->startup() || !fatMountSimple( fat_name[device], fat_interface[device] )) && mount_attempts) { --mount_attempts; usleep(10); } if(!mount_attempts) mounted = NOT_MOUNTED; } isMounted[device] = mounted; return mounted; }
void Init_USB() { //Close_USB(); printf("\n"); if (AHBPROT_DISABLED && !USB_PORT_CONNECTED) { USBmnt = false; } else { bool started = false; isUSB2 = (IOS_GetVersion() >= 200); time_t tStart = time(0); while ((time(0) - tStart) < 10) // 10 seconds timeout { Con_ClearLine(); printf("\t- USB drive: %.f...", difftime(time(0), tStart)); if (isUSB2) { started = (__io_usbstorage2.startup() && __io_usbstorage2.isInserted()); } else { started = (__io_usbstorage.startup() && __io_usbstorage.isInserted()); } if (started) break; usleep(50000); } USBmnt = (started && fatMountSimple("usb", (isUSB2 ? &__io_usbstorage2 : &__io_usbstorage))); Con_ClearLine(); } printf("\t- USB drive: %s.\n\n", (USBmnt ? "OK" : "FAILED")); }
void Init_SD() { //Close_SD(); SDmnt = fatMountSimple("sd", &__io_wiisd); printf("\n\t- SD Card: %s.", (SDmnt ? "OK" : "FAILED")); }
void USB::Startup() { USB::Unmount(); // To Hopefully Wake Up The Drive isMounted = fatMountSimple("usb", &__io_usbstorage); }
int menu_entries_parse_list( file_list_t *list, file_list_t *menu_list, const char *dir, const char *label, unsigned type, unsigned default_type_plain, const char *exts, rarch_setting_t *setting) { size_t i, list_size; bool path_is_compressed, push_dir; int device = 0; struct string_list *str_list = NULL; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); (void)device; if (!list || !menu_list) return -1; menu_list_clear(list); if (!*dir) { menu_entries_parse_drive_list(list); menu_driver_populate_entries(dir, label, type); return 0; } #if defined(GEKKO) && defined(HW_RVL) slock_lock(gx_device_mutex); device = gx_get_device_from_path(dir); if (device != -1 && !gx_devices[device].mounted && gx_devices[device].interface->isInserted()) fatMountSimple(gx_devices[device].name, gx_devices[device].interface); slock_unlock(gx_device_mutex); #endif path_is_compressed = path_is_compressed_file(dir); push_dir = (setting && setting->browser_selection_type == ST_DIR); if (path_is_compressed) str_list = compressed_file_list_new(dir,exts); else str_list = dir_list_new(dir, settings->menu.navigation.browser.filter.supported_extensions_enable ? exts : NULL, true); if (push_dir) menu_list_push(list, "<Use this directory>", "", MENU_FILE_USE_DIRECTORY, 0); if (!str_list) return -1; dir_list_sort(str_list, true); list_size = str_list->size; for (i = 0; i < str_list->size; i++) { bool is_dir; const char *path = NULL; menu_file_type_t file_type = MENU_FILE_NONE; switch (str_list->elems[i].attr.i) { case RARCH_DIRECTORY: file_type = MENU_FILE_DIRECTORY; break; case RARCH_COMPRESSED_ARCHIVE: file_type = MENU_FILE_CARCHIVE; break; case RARCH_COMPRESSED_FILE_IN_ARCHIVE: file_type = MENU_FILE_IN_CARCHIVE; break; case RARCH_PLAIN_FILE: default: if (!strcmp(label, "detect_core_list")) { if (path_is_compressed_file(str_list->elems[i].data)) { /* in case of deferred_core_list we have to interpret * every archive as an archive to disallow instant loading */ file_type = MENU_FILE_CARCHIVE; break; } } file_type = (menu_file_type_t)default_type_plain; break; } is_dir = (file_type == MENU_FILE_DIRECTORY); if (push_dir && !is_dir) continue; /* Need to preserve slash first time. */ path = str_list->elems[i].data; if (*dir && !path_is_compressed) path = path_basename(path); #ifdef HAVE_LIBRETRO_MANAGEMENT #ifdef RARCH_CONSOLE if (!strcmp(label, "core_list") && (is_dir || strcasecmp(path, SALAMANDER_FILE) == 0)) continue; #endif #endif /* Push type further down in the chain. * Needed for shader manager currently. */ if (!strcmp(label, "core_list")) { /* Compressed cores are unsupported */ if (file_type == MENU_FILE_CARCHIVE) continue; menu_list_push(list, path, "", is_dir ? MENU_FILE_DIRECTORY : MENU_FILE_CORE, 0); } else menu_list_push(list, path, "", file_type, 0); } string_list_free(str_list); if (!strcmp(label, "core_list")) { driver_t *driver = driver_get_ptr(); menu_list_get_last_stack(driver->menu->menu_list, &dir, NULL, NULL); list_size = file_list_get_size(list); for (i = 0; i < list_size; i++) { char core_path[PATH_MAX_LENGTH], display_name[PATH_MAX_LENGTH]; const char *path = NULL; menu_list_get_at_offset(list, i, &path, NULL, &type); if (type != MENU_FILE_CORE) continue; fill_pathname_join(core_path, dir, path, sizeof(core_path)); if (global->core_info && core_info_list_get_display_name(global->core_info, core_path, display_name, sizeof(display_name))) menu_list_set_alt_at_offset(list, i, display_name); } menu_list_sort_on_alt(list); } menu_list_populate_generic(list, dir, label, type); return 0; }
/* call fileBrowser_libfat_init as much as you like for all devices - returns 0 on device not present/error - returns 1 on ok */ int fileBrowser_libfat_init(fileBrowser_file* f){ int res = 0; if(!rThreadCreated) InitRemovalThread(); #ifdef HW_RVL if(f->name[0] == 's') { //SD if(!sdMounted) { //if there's nothing currently mounted pauseRemovalThread(); if(sdNeedsUnmount) { fatUnmount("sd"); if(sdNeedsUnmount==FRONTSD) frontsd->shutdown(); else if(sdNeedsUnmount==CARD_A) carda->shutdown(); else if(sdNeedsUnmount==CARD_B) cardb->shutdown(); sdNeedsUnmount = 0; } if(fatMountSimple ("sd", frontsd)) { sdMounted = FRONTSD; res = 1; } else if(fatMountSimple ("sd", carda)) { sdMounted = CARD_A; res = 1; } else if(fatMountSimple ("sd", cardb)) { sdMounted = CARD_B; res = 1; } continueRemovalThread(); return res; } else return 1; } else if(f->name[0] == 'u') { if(!usbMounted) { pauseRemovalThread(); if(usbNeedsUnmount) { fatUnmount("usb"); usb->shutdown(); usbNeedsUnmount=0; } if(fatMountSimple ("usb", usb)) usbMounted = 1; continueRemovalThread(); return usbMounted; } else return 1; } return res; #else if(!sdMounted) { //GC has only SD if(sdNeedsUnmount) fatUnmount("sd"); switch(sdNeedsUnmount){ //unmount previous devices case CARD_A: carda->shutdown(); break; case CARD_B: cardb->shutdown(); break; } if(carda->startup()) { res |= fatMountSimple ("sd", carda); if(res) sdMounted = CARD_A; } else if(cardb->startup() && !res) { res |= fatMountSimple ("sd", cardb); if(res) sdMounted = CARD_B; } return res; } return 1; //we're always ok #endif }
int main(void) { int fd,n,mounted=0; int inited=0; ipcmessage* message; memset(&my_reent, 0, sizeof(struct _reent)); memset(my_filestr, 0, sizeof(FILE_STRUCT)*5); memset(file_table, 0, 4*2*5); memset(&dir_state_internal,0,sizeof(DIR_STATE_STRUCT)); dir_internal.device=0; dir_internal.dirStruct=&dir_state_internal; heaphandle = os_heap_create(heapspace, sizeof(heapspace)); void* queuespace = os_heap_alloc(heaphandle, 0x20); queuehandle = os_message_queue_create(queuespace, 8); void* timer1_queuespace = os_heap_alloc(heaphandle, 0x40); timer1_queuehandle = os_message_queue_create(timer1_queuespace, 16); timer1_id=os_create_timer(1000*1000, 1, timer1_queuehandle, 0x666); os_stop_timer(timer1_id); extern DISC_INTERFACE __io_wiisd; inited=__io_wiisd.startup(); msleep(100); os_device_register(DEVICE, queuehandle); while(1) { int result = 1; int ack = 1; os_message_queue_receive(queuehandle,(void *) &message, 0); switch( message->command ) { case IOS_OPEN: { result = -6; //debug_printf("%s try open %sfor fd %d\n",DEVICE,message->open.device,message->open.resultfd); // Checking device name if (0 == strcmp(message->open.device, DEVICE)) { result = message->open.resultfd; } else if (0 == strcmp(message->open.device, DEVICE"/log")) { if(inited && !mounted) mounted=fatMountSimple("sd", &__io_wiisd); if(mounted) { static char log_name[]="sd:/log000.txt"; for(n=0;n<5;n++) if(my_filestr[n].inUse==0) break; fd=-1; if(n!=5) { my_reent._errno=0; fd=_FAT_open_r(&my_reent, &my_filestr[n], log_name, O_CREAT | O_TRUNC | O_RDWR, 0); log_name[9]++; if(log_name[9]>='9') {log_name[9]='0';log_name[8]++;} if(log_name[8]>='9') {log_name[8]='0';log_name[7]++;} if(log_name[7]>='9') {log_name[7]='0';log_name[8]='0';log_name[9]='0';} } if(fd<0) result=-1; else { result=file_table[n][0]=message->open.resultfd; file_table[n][1]= fd; } } } else if (0 == memcmp(message->open.device, DEVICE"/", sizeof(DEVICE))) { if(inited && !mounted) mounted=fatMountSimple("sd", &__io_wiisd); if(mounted) { for(n=0;n<5;n++) if(my_filestr[n].inUse==0) break; fd=-1; if(n!=5) { my_reent._errno=0; fd=_FAT_open_r(&my_reent, &my_filestr[n], message->open.device+sizeof(DEVICE), message->open.mode, 0); } if(fd<0) result=-1; else { result=file_table[n][0]=message->open.resultfd; file_table[n][1]= fd; } } } } break; case IOS_IOCTLV: { result = -1; ioctlv *vec = message->ioctlv.vector; int i,in = message->ioctlv.num_in,io= message->ioctlv.num_io; os_sync_before_read( vec, (in+io)*sizeof(ioctlv)); for(i=0;i<in+io;i++){ os_sync_before_read( vec[i].data, vec[i].len); } #if 0 // list the directory content to directory.txt switch(message->ioctl.command ) { case 0xcacafea: if(inited && !mounted) mounted=fatMountSimple("sd", &__io_wiisd); if(mounted) { my_reent._errno=0; result=-666; if(_FAT_diropen_r(&my_reent, &dir_internal, "sd:/")) { static char log_name2[]="sd:/directory.txt"; char filename[768]; result = 0; my_reent._errno=0; fd=_FAT_open_r(&my_reent, &my_filestr[4], log_name2, O_CREAT | O_TRUNC | O_RDWR, 0); my_reent._errno=0; while(!_FAT_dirnext_r (&my_reent, &dir_internal, filename, &filestat)) { my_reent._errno=0; if(fd>=0) { if(filestat.st_mode & S_IFDIR)_FAT_write_r (&my_reent, fd, "[", 1); // es directorio _FAT_write_r (&my_reent, fd, filename, strlen(filename)); if(filestat.st_mode & S_IFDIR)_FAT_write_r (&my_reent, fd, "]", 1); // es directorio _FAT_write_r (&my_reent, fd, "\n", 1); } } my_reent._errno=0; if(fd>=0) _FAT_close_r (&my_reent, fd);fd=-1; _FAT_dirclose_r(&my_reent, &dir_internal); } } break; } #endif for(i=in;i<in+io;i++){ os_sync_after_write( vec[i].data, vec[i].len); } } break; case IOS_CLOSE: { result = -1; if(mounted) { my_reent._errno=0; for(n=0;n<5;n++) { if(message->fd==file_table[n][0]) { fd=file_table[n][1]; file_table[n][0]=file_table[n][1]=0; _FAT_close_r (&my_reent, fd); result = 0; break; } } for(n=0;n<5;n++) if(my_filestr[n].inUse!=0) break; if(n==5) {fatUnmount ("sd");mounted=0;} } else result=-6; } break; case IOS_READ: { result=-1; if(mounted) { my_reent._errno=0; for(n=0;n<5;n++) { if(message->fd==file_table[n][0]) { fd=file_table[n][1]; result=_FAT_read_r (&my_reent, fd, message->write.data, message->write.length); } } } os_sync_after_write( message->write.data, message->write.length); } break; case IOS_WRITE: { os_sync_before_read( message->write.data, message->write.length); result=-1; if(mounted) { my_reent._errno=0; for(n=0;n<5;n++) { if(message->fd==file_table[n][0]) { fd=file_table[n][1]; result=_FAT_write_r (&my_reent, fd, message->write.data, message->write.length); } } } } break; case IOS_SEEK: { result=-1; if(mounted) { my_reent._errno=0; for(n=0;n<5;n++) { if(message->fd==file_table[n][0]) { fd=file_table[n][1]; result=_FAT_seek_r (&my_reent, fd, message->seek.offset, message->seek.origin); } } } } break; default: result=-1; break; } if (ack) os_message_queue_ack( (void*)message, result ); } return 0; }
static bool MountFAT(int device, int silent) { bool mounted = false; int retry = 1; char name[10], name2[10]; const DISC_INTERFACE* disc = NULL; switch(device) { #ifdef HW_RVL case DEVICE_SD: sprintf(name, "sd"); sprintf(name2, "sd:"); disc = sd; break; case DEVICE_USB: sprintf(name, "usb"); sprintf(name2, "usb:"); disc = usb; break; #else case DEVICE_SD_SLOTA: sprintf(name, "carda"); sprintf(name2, "carda:"); disc = carda; break; case DEVICE_SD_SLOTB: sprintf(name, "cardb"); sprintf(name2, "cardb:"); disc = cardb; break; #endif default: return false; // unknown device } if(unmountRequired[device]) { unmountRequired[device] = false; fatUnmount(name2); disc->shutdown(); isMounted[device] = false; } while(retry) { if(disc->startup() && fatMountSimple(name, disc)) mounted = true; if(mounted || silent) break; #ifdef HW_RVL if(device == DEVICE_SD) retry = ErrorPromptRetry("SD card not found!"); else retry = ErrorPromptRetry("USB drive not found!"); #else retry = ErrorPromptRetry("SD card not found!"); #endif } isMounted[device] = mounted; return mounted; }
int main(int argc, char *argv[]) { #ifdef HW_RVL IOS_ReloadIOS(IOS_GetVersion()); L2Enhance(); gx_init_mem2(); #endif fatInitDefault(); #ifdef HAVE_LOGGER g_extern.verbose = true; logger_init(); devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_net; #elif defined(HAVE_FILE_LOGGER) g_extern.verbose = true; log_fp = fopen("/retroarch-log.txt", "w"); devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; dotab_stdout.write_r = gx_logger_file; #endif #ifdef HW_RVL lwp_t gx_device_thread; gx_devices[GX_DEVICE_SD].interface = &__io_wiisd; gx_devices[GX_DEVICE_SD].name = "sd"; gx_devices[GX_DEVICE_SD].mounted = fatMountSimple(gx_devices[GX_DEVICE_SD].name, gx_devices[GX_DEVICE_SD].interface); gx_devices[GX_DEVICE_USB].interface = &__io_usbstorage; gx_devices[GX_DEVICE_USB].name = "usb"; gx_devices[GX_DEVICE_USB].mounted = fatMountSimple(gx_devices[GX_DEVICE_USB].name, gx_devices[GX_DEVICE_USB].interface); LWP_MutexInit(&gx_device_mutex, false); LWP_CreateThread(&gx_device_thread, gx_devthread, NULL, NULL, 0, 66); #endif get_environment_settings(); make_directories(); config_set_defaults(); input_gx.init(); video_gx.start(); driver.video = &video_gx; gx_video_t *gx = (gx_video_t*)driver.video_data; gx->menu_data = (uint32_t *) menu_framebuf; char tmp_path[PATH_MAX]; const char *extension = default_paths.executable_extension; snprintf(tmp_path, sizeof(tmp_path), "%s/", default_paths.core_dir); const char *path_prefix = tmp_path; char full_path[1024]; snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension); bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix, default_paths.config_file, extension); rarch_settings_set_default(&input_gx); rarch_config_load(default_paths.config_file, path_prefix, extension, find_libretro_file); char core_name[64]; rarch_console_name_from_id(core_name, sizeof(core_name)); char input_path[1024]; snprintf(input_path, sizeof(input_path), "%s/%s.cfg", default_paths.input_presets_dir, core_name); config_read_keybinds(input_path); init_libretro_sym(); input_gx.post_init(); menu_init(); if (argc > 2 && argv[1] != NULL && argv[2] != NULL) { char rom[PATH_MAX]; g_console.external_launcher_support = EXTERN_LAUNCHER_CHANNEL; snprintf(rom, sizeof(rom), "%s%s", argv[1], argv[2]); g_console.zip_extract_mode = ZIP_EXTRACT_TO_CURRENT_DIR_AND_LOAD_FIRST_FILE; rarch_console_load_game_wrap(rom, g_console.zip_extract_mode, S_DELAY_1); rgui_iterate(rgui, RGUI_ACTION_MESSAGE); gx->menu_render = true; rarch_render_cached_frame(); gx->menu_render = false; rarch_startup(default_paths.config_file); } else { g_console.external_launcher_support = EXTERN_LAUNCHER_SALAMANDER; } begin_loop: if(g_console.mode_switch == MODE_EMULATION) { bool repeat = false; input_gx.poll(NULL); video_set_aspect_ratio_func(g_console.aspect_ratio_index); audio_start_func(); do{ repeat = rarch_main_iterate(); }while(repeat && !g_console.frame_advance_enable); audio_stop_func(); } else if(g_console.mode_switch == MODE_MENU) { menu_loop(); if (g_console.mode_switch != MODE_EXIT) rarch_startup(default_paths.config_file); } else goto begin_shutdown; goto begin_loop; begin_shutdown: rarch_config_save(default_paths.config_file); config_save_keybinds(input_path); if(g_console.emulator_initialized) rarch_main_deinit(); input_gx.free(NULL); video_gx.stop(); menu_free(); #ifdef HAVE_LOGGER logger_shutdown(); #elif defined(HAVE_FILE_LOGGER) fclose(log_fp); #endif if(g_console.return_to_launcher) rarch_console_exec(g_console.launch_app_on_exit); exit(0); }
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb, void *userdata, void *ctx) { bool core_chooser = (userdata) ? *(rgui_file_type_t *)userdata == RGUI_SETTINGS_CORE : false; if (!*directory) { #ifdef HW_RVL file_cb(ctx, "sd:", RGUI_FILE_DEVICE, 0); file_cb(ctx, "usb:", RGUI_FILE_DEVICE, 0); #endif file_cb(ctx, "carda:", RGUI_FILE_DEVICE, 0); file_cb(ctx, "cardb:", RGUI_FILE_DEVICE, 0); return true; } #ifdef HW_RVL LWP_MutexLock(gx_device_mutex); int dev = gx_get_device_from_path(directory); if (dev != -1 && !gx_devices[dev].mounted && gx_devices[dev].interface->isInserted()) fatMountSimple(gx_devices[dev].name, gx_devices[dev].interface); LWP_MutexUnlock(gx_device_mutex); #endif char exts[256]; if (core_chooser) strlcpy(exts, "dol|DOL", sizeof(exts)); else strlcpy(exts, rarch_console_get_rom_ext(), sizeof(exts)); struct string_list *ext_list = string_split(exts, "|"); char _dir[PATH_MAX]; snprintf(_dir, sizeof(_dir), "%s/", directory); DIR *dir = opendir(_dir); if (!dir) return false; struct dirent *entry; while ((entry = readdir(dir))) { char stat_path[PATH_MAX]; const char *file_ext = path_get_extension(entry->d_name); snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name); bool is_dir; #ifdef _DIRENT_HAVE_D_TYPE is_dir = (entry->d_type == DT_DIR); if (entry->d_type != DT_REG && !is_dir) continue; #else struct stat st; if (stat(stat_path, &st) < 0) continue; is_dir = S_ISDIR(st.st_mode); if (!S_ISREG(st.st_mode) && !is_dir) continue; #endif if (core_chooser && (is_dir || strcasecmp(entry->d_name, default_paths.salamander_file) == 0)) continue; if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext)) continue; file_cb(ctx, entry->d_name, is_dir ? RGUI_FILE_DIRECTORY : RGUI_FILE_PLAIN, 0); } closedir(dir); string_list_free(ext_list); return true; }