static bool do_format(const std::string &mountpoint) { if (mountpoint == SYSTEM || mountpoint == CACHE) { // Need to mount the partition if we're using an image file and it // hasn't been mounted int needs_mount = (mountpoint == SYSTEM) && (access("/mb/system.img", F_OK) == 0) && (access(STAMP_FILE, F_OK) != 0); if (needs_mount && !do_mount(mountpoint)) { LOGE(TAG "Failed to mount {}", mountpoint); return false; } if (!wipe_directory(mountpoint, true)) { LOGE(TAG "Failed to wipe {}", mountpoint); return false; } if (needs_mount && !do_unmount(mountpoint)) { LOGE(TAG "Failed to unmount {}", mountpoint); return false; } } else if (mountpoint == DATA) { if (!wipe_directory(mountpoint, false)) { LOGE(TAG "Failed to wipe {}", mountpoint); return false; } } LOGD(TAG "Formatted {}", mountpoint); return true; }
/*! * \brief Log wiping of directory * * \note The path will be wiped only if it is a directory. The recursive * deletion does not follow symlinks. * * \param mountpoint Mountpoint root to wipe * \param wipe_media Whether the first-level "media" path should be deleted * * \return True if the path was wiped or doesn't exist. False, otherwise */ static bool log_wipe_directory(const std::string &mountpoint, const std::vector<std::string> &exclusions) { if (exclusions.empty()) { LOGV("Wiping directory %s", mountpoint.c_str()); } else { LOGV("Wiping directory %s (excluding %s)", mountpoint.c_str(), util::join(exclusions, ", ").c_str()); } struct stat sb; if (stat(mountpoint.c_str(), &sb) < 0) { if (errno != ENOENT) { LOGE("%s: Failed to stat: %s", mountpoint.c_str(), strerror(errno)); return false; } else { return true; } } if (!S_ISDIR(sb.st_mode)) { LOGE("%s: Cannot wipe path: not a directory", mountpoint.c_str()); return false; } bool ret = wipe_directory(mountpoint, exclusions); LOGV("-> %s", ret ? "Succeeded" : "Failed"); return ret; }
/***************************************************************************** Function: osd_shut_machine Description: Deinitialize all stuff that have been inited in osd_int_machine Parameters: none Return: nothing *****************************************************************************/ void osd_shut_machine (void) { free(XBuf); if (sound_driver == 1) osd_snd_set_volume (0); if (timerId != NULL) SDL_RemoveTimer(timerId); #ifndef SDL /* closing joypad device */ close ((int)fd[0]); #endif if (dump_snd) fclose(out_snd); TrashSound(); SDL_Quit(); wipe_directory(tmp_basepath); }
static bool do_format(const char *mountpoint) { if (!get_paths(mountpoint, nullptr, nullptr)) { LOGE(TAG "%s: Invalid mountpoint", mountpoint); return false; } bool needs_mount = !util::is_mounted(mountpoint); if (needs_mount && !do_mount(mountpoint)) { LOGE(TAG "%s: Failed to mount path", mountpoint); return false; } std::vector<std::string> exclusions; if (strcmp(mountpoint, DATA) == 0) { exclusions.push_back("media"); } if (!wipe_directory(mountpoint, exclusions)) { LOGE(TAG "%s: Failed to wipe directory", mountpoint); return false; } if (needs_mount && !do_unmount(mountpoint)) { LOGE(TAG "%s: Failed to unmount path", mountpoint); return false; } LOGD(TAG "Successfully formatted %s", mountpoint); return true; }