void release_storage() { if (device == 0) { #ifdef DEBUG printf("[+] Release SD ... "); #endif fatUnmount("sd"); __io_wiisd.shutdown(); SDmounted = FALSE; #ifdef DEBUG printf("OK!\n"); #endif } else { #ifdef DEBUG printf("[+] Release USB ... "); #endif fatUnmount("usb"); __io_usbstorage.shutdown(); USBmounted = FALSE; #ifdef DEBUG printf("OK!\n"); #endif } }
/* 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; }
/**************************************************************************** * UnmountAllFAT * Unmounts all FAT devices ***************************************************************************/ void UnmountAllFAT() { #ifdef HW_RVL fatUnmount("sd:"); fatUnmount("usb:"); #else fatUnmount("carda:"); fatUnmount("cardb:"); #endif }
static void fsdev_exit(void) { if (iosuhaxMount) { fatUnmount("sd:"); fatUnmount("usb:"); if (mcp_hook_fd >= 0) MCPHookClose(); else IOSUHAX_Close(); } else unmount_sd_fat("sd"); }
// WARNING: after we move any data into EXECUTE_ADDR, we can no longer use any // heap memory and are restricted to the stack only static void rarch_console_exec(const char *path) { RARCH_LOG("Attempt to load executable: [%s].\n", path); FILE * fp = fopen(path, "rb"); if (fp == NULL) { RARCH_ERR("Could not open DOL file %s.\n", path); return; } fseek(fp, 0, SEEK_END); size_t size = ftell(fp); fseek(fp, 0, SEEK_SET); // try to allocate a buffer for it. if we can't, fail void *dol = malloc(size); if (!dol) { RARCH_ERR("Could not execute DOL file %s.\n", path); fclose(fp); return; } fread(dol, 1, size, fp); fclose(fp); fatUnmount("carda:"); fatUnmount("cardb:"); fatUnmount("sd:"); fatUnmount("usb:"); __io_wiisd.shutdown(); __io_usbstorage.shutdown(); // luckily for us, newlib's memmove doesn't allocate a seperate buffer for // copying in situations of overlap, so it's safe to do this memmove(EXECUTE_ADDR, dol, size); DCFlushRange(EXECUTE_ADDR, size); dol_copy_argv_path(); size_t booter_size = booter_end - booter_start; memcpy(BOOTER_ADDR, booter_start, booter_size); DCFlushRange(BOOTER_ADDR, booter_size); RARCH_LOG("jumping to %08x\n", (unsigned) BOOTER_ADDR); SYS_ResetSystem(SYS_SHUTDOWN,0,0); __lwp_thread_stopmultitasking((void (*)(void)) BOOTER_ADDR); }
int USBDevice_Init() { #ifdef DEBUG_FAT gprintf("\nUSBDevice_Init()"); #endif //closing all open Files write back the cache and then shutdown em! fatUnmount("USB:/"); //right now mounts first FAT-partition //try first mount with cIOS // if (!fatMount("USB", &__io_wiiums, 0, CACHE, SECTORS)) { // //try now mount with libogc if (!fatMount("USB", &__io_usbstorage2, 0, CACHE, SECTORS)) { #ifdef DEBUG_FAT gprintf(":-1"); #endif return -1; } // } fat_usb_mount = 1; fat_usb_sec = _FAT_startSector; #ifdef DEBUG_FAT gprintf(":0"); #endif return 0; }
int SDCard_Init() { #ifdef DEBUG_FAT gprintf("\nSDCard_Init()"); #endif //closing all open Files write back the cache and then shutdown em! fatUnmount("SD:/"); //right now mounts first FAT-partition if (fatMount("SD", &__io_wiisd, 0, CACHE, SECTORS)) { fat_sd_mount = MOUNT_SD; fat_sd_sec = _FAT_startSector; #ifdef DEBUG_FAT gprintf(":1"); #endif return 1; } else if (fatMount("SD", &__io_sdhc, 0, CACHE, SDHC_SECTOR_SIZE)) { fat_sd_mount = MOUNT_SDHC; fat_sd_sec = _FAT_startSector; #ifdef DEBUG_FAT gprintf(":1"); #endif return 1; } #ifdef DEBUG_FAT gprintf(":-1"); #endif return -1; }
void WBFSDevice_deInit() { //closing all open Files write back the cache and then shutdown em! fatUnmount("WBFS:/"); fat_wbfs_mount = 0; fat_wbfs_sec = 0; }
static void *gx_devthread(void *a) { struct timespec timeout = {0}; timeout.tv_sec = 1; timeout.tv_nsec = 0; while (1) { LWP_MutexLock(gx_device_mutex); unsigned i; for (i = 0; i < GX_DEVICE_END; i++) { if (gx_devices[i].mounted && !gx_devices[i].interface->isInserted()) { gx_devices[i].mounted = false; char n[8]; snprintf(n, sizeof(n), "%s:", gx_devices[i].name); fatUnmount(n); } } LWP_MutexUnlock(gx_device_mutex); LWP_MutexLock(gx_device_cond_mutex); LWP_CondTimedWait(gx_device_cond, gx_device_cond_mutex, &timeout); LWP_MutexUnlock(gx_device_cond_mutex); } return NULL; }
static void UnmountPartitions(int device) { char mount[11]; int i; for (i = 0; i < MAX_DEVICES; i++) { switch (part[device][i].type) { case T_FAT: part[device][i].type = 0; sprintf(mount, "%s:", part[device][i].mount); fatUnmount(mount); break; case T_NTFS: part[device][i].type = 0; ntfsUnmount(part[device][i].mount, false); break; case T_EXT2: part[device][i].type = 0; ext2Unmount(part[device][i].mount); break; case T_ISO9660: part[device][i].type = 0; sprintf(mount, "%s:", part[device][i].mount); ISO9660_Unmount(mount); break; } part[device][i].name[0] = 0; part[device][i].mount[0] = 0; part[device][i].sector = 0; part[device][i].interface = NULL; } }
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); } }
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; }
void Fat_Unmount(fatDevice *dev) { /* Unmount device */ fatUnmount(dev->mount); /* Shutdown interface */ dev->interface->shutdown(); }
void die(char *msg) { if (f!=NULL) fclose(f); printf(msg); sleep(5); fatUnmount("sd"); __io_wiisd.shutdown(); exit(0); }
/* * Unmounts the file system */ void wii_unmount() { if( mounted ) { if( wii_is_usb ) { fatUnmount( "usb:/" ); __io_usbstorage.shutdown(); } else { fatUnmount( "sd:/" ); __io_wiisd.shutdown(); } mounted = FALSE; } }
void SDCard_deInit() { #ifdef DEBUG_FAT gprintf("\nSDCard_deInit()"); #endif //closing all open Files write back the cache and then shutdown em! fatUnmount("SD:/"); fat_sd_mount = MOUNT_NONE; fat_sd_sec = 0; }
void USBDevice_deInit() { #ifdef DEBUG_FAT gprintf("\nUSBDevice_deInit()"); #endif //closing all open Files write back the cache and then shutdown em! fatUnmount("USB:/"); fat_usb_mount = 0; fat_usb_sec = 0; }
void Close_USB() { fatUnmount("usb"); if (isUSB2) { __io_usbstorage2.shutdown(); } else { __io_usbstorage.shutdown(); } }
s32 Fat_Unmount(void){ s32 ret; // Unmount device fatUnmount(DEV_MOUNT); // Shutdown SDHC interface ret = interface->shutdown(); if (!ret) return -1; return 0; }
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 Fat_UnmountSDHC(void) { s32 ret; /* Unmount device */ fatUnmount(SDHC_MOUNT); /* Shutdown SDHC interface */ ret = __io_sdhc.shutdown(); if (!ret) return -1; return 0; }
void deinitFAT() { //First unmount all the devs... fatUnmount ("fat"); //...and then shutdown em! #ifdef HW_RVL __io_wiisd.shutdown(); __io_usbstorage.shutdown(); #else if(MEM_CARD) __io_gcsda.shutdown(); if(!MEM_CARD) __io_gcsdb.shutdown(); #endif }
void unmountDevice () { if (inuse != NULL) { if (matchStr(inuse->root, "dvd")) { ISO9660_Unmount(); } else { fatUnmount(inuse->root); } inuse = NULL; } }
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; }
/* call to apply the codes and cleanup */ void apply_sd_codes(bool apply) { extern u8 *filebuff; extern u32 filesize; extern FILE *fp; if (apply){ memcpy((void*)0x800027E8,filebuff,filesize); *(vu8*)0x80001807 = 0x01; } free(filebuff); fclose(fp); fatUnmount("sdhc"); __io_wiisd.shutdown(); sleep(2); }
int WBFSDevice_Init(u32 sector) { //closing all open Files write back the cache and then shutdown em! fatUnmount("WBFS:/"); //right now mounts first FAT-partition //try first mount with cIOS // if (!fatMount("WBFS", &__io_wiiums, 0, CACHE, SECTORS)) { //try now mount with libogc if (!fatMount("WBFS", &__io_usbstorage2, 0, CACHE, SECTORS)) { return -1; } // } fat_wbfs_mount = 1; fat_wbfs_sec = _FAT_startSector; if (sector && fat_wbfs_sec != sector) { // This is an error situation...actually, but is ignored in Config loader also // Should ask Oggzee about it... } return 0; }
static void *gx_devthread(void *a) { while (1) { LWP_MutexLock(gx_device_mutex); unsigned i; for (i = 0; i < GX_DEVICE_END; i++) { if (gx_devices[i].mounted && !gx_devices[i].interface->isInserted()) { gx_devices[i].mounted = false; char n[8]; snprintf(n, sizeof(n), "%s:", gx_devices[i].name); fatUnmount(n); } } LWP_MutexUnlock(gx_device_mutex); usleep(100000); } return NULL; }
void PartitionHandle::UnMount(int pos) { if(!interface) return; if(pos >= (int) MountNameList.size()) return; if(MountNameList[pos].size() == 0) return; char DeviceName[20]; snprintf(DeviceName, sizeof(DeviceName), "%s:", MountNameList[pos].c_str()); //closing all open Files write back the cache fatUnmount(DeviceName); //closing all open Files write back the cache ntfsUnmount(DeviceName, true); //closing all open Files write back the cache ext2Unmount(DeviceName); //Remove name from list MountNameList[pos].clear(); }
void PartitionHandle::UnMount(int pos) { if(!interface || (pos >= (int)MountNameList.size()) || (MountNameList[pos].size() == 0)) return; WBFS_Close(); char DeviceSyn[10]; memcpy(DeviceSyn, MountName(pos), 8); strcat(DeviceSyn, ":"); DeviceSyn[9] = '\0'; if(strncmp(GetFSName(pos), "WBFS", 4) == 0) { wbfs_t *wbfshandle = GetWbfsHandle(pos); if(wbfshandle) wbfs_close(wbfshandle); gprintf("WBFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "FAT", 3) == 0) { fatUnmount(DeviceSyn); gprintf("FAT Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "NTFS", 4) == 0) { ntfsUnmount(DeviceSyn, true); gprintf("NTFS Partition at %s unmounted.\n", DeviceSyn); } else if(strncmp(GetFSName(pos), "LINUX", 5) == 0) { ext2Unmount(DeviceSyn); gprintf("EXT Partition at %s unmounted.\n", DeviceSyn); } /* Remove name from list */ MountNameList[pos].clear(); SetWbfsHandle(pos, NULL); }
/* WARNING: after we move any data * into EXECUTE_ADDR, we can no longer use any * heap memory and are restricted to the stack only. */ void system_exec_wii(const char *_path, bool should_load_game) { FILE *fp; size_t size, booter_size; void *dol; char path[PATH_MAX_LENGTH]; char game_path[PATH_MAX_LENGTH]; #ifndef IS_SALAMANDER bool *verbose = retro_main_verbosity(); bool original_verbose = *verbose; *verbose = true; #endif /* copy heap info into stack so it survives * us moving the .dol into MEM2. */ strlcpy(path, _path, sizeof(path)); if (should_load_game) { #ifdef IS_SALAMANDER strlcpy(game_path, gx_rom_path, sizeof(game_path)); #else char *fullpath = NULL; runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath); strlcpy(game_path, fullpath, sizeof(game_path)); #endif } RARCH_LOG("Attempt to load executable: [%s]\n", path); fp = fopen(path, "rb"); if (fp == NULL) { RARCH_ERR("Could not open DOL file %s.\n", path); goto exit; } fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); /* try to allocate a buffer for it. if we can't, fail. */ dol = malloc(size); if (!dol) { RARCH_ERR("Could not execute DOL file %s.\n", path); fclose(fp); goto exit; } fread(dol, 1, size, fp); fclose(fp); fatUnmount("carda:"); fatUnmount("cardb:"); fatUnmount("sd:"); fatUnmount("usb:"); __io_wiisd.shutdown(); __io_usbstorage.shutdown(); /* don't use memcpy, there might be an overlap. */ memmove(EXECUTE_ADDR, dol, size); DCFlushRange(EXECUTE_ADDR, size); dol_copy_argv_path(path, should_load_game ? game_path : NULL); booter_size = booter_end - booter_start; memcpy(BOOTER_ADDR, booter_start, booter_size); DCFlushRange(BOOTER_ADDR, booter_size); RARCH_LOG("jumping to %08x\n", (unsigned) BOOTER_ADDR); SYS_ResetSystem(SYS_SHUTDOWN,0,0); __lwp_thread_stopmultitasking((void (*)(void)) BOOTER_ADDR); exit: (void)0; #ifndef IS_SALAMANDER *verbose = original_verbose; #endif }