Use g_fxo for cellSysCache

This commit is contained in:
Nekotekina 2019-08-26 16:04:16 +03:00
parent d2eba2387b
commit e41b234dc4
2 changed files with 18 additions and 16 deletions

View File

@ -70,6 +70,12 @@ extern void sysutil_send_system_cmd(u64 status, u64 param)
} }
} }
struct syscache
{
atomic_t<u32> state = 0;
std::string cache_path;
};
template <> template <>
void fmt_class_string<CellSysutilLang>::format(std::string& out, u64 arg) void fmt_class_string<CellSysutilLang>::format(std::string& out, u64 arg)
{ {
@ -307,27 +313,21 @@ s32 cellSysCacheClear()
{ {
cellSysutil.warning("cellSysCacheClear()"); cellSysutil.warning("cellSysCacheClear()");
// Get the param as a shared ptr, then decipher the cacheid from it const auto cache = g_fxo->get<syscache>();
// (Instead of assuming naively that the param is passed as argument)
std::shared_ptr<CellSysCacheParam> param = fxm::get<CellSysCacheParam>();
// Unit test for param ptr, since it may be null at the time of get() if (!cache->state)
if (!param)
{ {
return CELL_SYSCACHE_ERROR_NOTMOUNTED; return CELL_SYSCACHE_ERROR_NOTMOUNTED;
} }
const std::string& cache_id = param->cacheId; std::string local_dir = vfs::get(cache->cache_path);
const std::string& cache_path = "/dev_hdd1/cache/" + cache_id; if (!fs::exists(local_dir) || !fs::is_dir(local_dir))
const std::string& dir_path = vfs::get(cache_path);
if (!fs::exists(dir_path) || !fs::is_dir(dir_path))
{ {
return CELL_SYSCACHE_ERROR_ACCESS_ERROR; return CELL_SYSCACHE_ERROR_ACCESS_ERROR;
} }
fs::remove_all(dir_path, false); fs::remove_all(local_dir, false);
return CELL_SYSCACHE_RET_OK_CLEARED; return CELL_SYSCACHE_RET_OK_CLEARED;
} }
@ -336,22 +336,24 @@ s32 cellSysCacheMount(vm::ptr<CellSysCacheParam> param)
{ {
cellSysutil.warning("cellSysCacheMount(param=*0x%x)", param); cellSysutil.warning("cellSysCacheMount(param=*0x%x)", param);
const auto cache = g_fxo->get<syscache>();
if (!param || !memchr(param->cacheId, '\0', CELL_SYSCACHE_ID_SIZE)) if (!param || !memchr(param->cacheId, '\0', CELL_SYSCACHE_ID_SIZE))
{ {
return CELL_SYSCACHE_ERROR_PARAM; return CELL_SYSCACHE_ERROR_PARAM;
} }
const std::string& cache_id = param->cacheId; std::string cache_id = param->cacheId;
const std::string& cache_path = "/dev_hdd1/cache/" + cache_id; std::string cache_path = "/dev_hdd1/cache/" + cache_id;
strcpy_trunc(param->getCachePath, cache_path); strcpy_trunc(param->getCachePath, cache_path);
// TODO: implement (what?)
fxm::make_always<CellSysCacheParam>(*param);
if (!fs::create_dir(vfs::get(cache_path)) && !cache_id.empty()) if (!fs::create_dir(vfs::get(cache_path)) && !cache_id.empty())
{ {
return CELL_SYSCACHE_RET_OK_RELAYED; return CELL_SYSCACHE_RET_OK_RELAYED;
} }
cache->cache_path = std::move(cache_path);
cache->state = 1;
return CELL_SYSCACHE_RET_OK_CLEARED; return CELL_SYSCACHE_RET_OK_CLEARED;
} }

View File

@ -194,7 +194,7 @@ struct CellSysCacheParam
{ {
char cacheId[CELL_SYSCACHE_ID_SIZE]; char cacheId[CELL_SYSCACHE_ID_SIZE];
char getCachePath[CELL_SYSCACHE_PATH_MAX]; char getCachePath[CELL_SYSCACHE_PATH_MAX];
vm::ptr<void> reserved; vm::bptr<void> reserved;
}; };
extern void sysutil_register_cb(std::function<s32(ppu_thread&)>&&); extern void sysutil_register_cb(std::function<s32(ppu_thread&)>&&);