cellSysCache: poison opened cache files on cache clear

Make opened files return CELL_EIO after cache clear.
This commit is contained in:
Nekotekina 2019-11-09 14:35:41 +03:00
parent 73ee6abb0f
commit 0d629743ca
2 changed files with 39 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "cellSysutil.h" #include "cellSysutil.h"
#include "util/init_mutex.hpp" #include "util/init_mutex.hpp"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
@ -71,6 +72,18 @@ struct syscache_info
{ {
cellSysutil.fatal("cellSysCache: failed to clear cache directory '%s%s' (%s)", cache_root, cache_id, fs::g_tls_error); cellSysutil.fatal("cellSysCache: failed to clear cache directory '%s%s' (%s)", cache_root, cache_id, fs::g_tls_error);
} }
// Poison opened files in /dev_hdd1 to return CELL_EIO on access
if (remove_root)
{
idm::select<lv2_fs_object, lv2_file>([](u32 id, lv2_file& file)
{
if (std::memcmp("/dev_hdd1", file.name.data(), 9) == 0)
{
file.lock = 2;
}
});
}
} }
}; };

View File

@ -399,6 +399,11 @@ error_code sys_fs_read(ppu_thread& ppu, u32 fd, vm::ptr<void> buf, u64 nbytes, v
std::lock_guard lock(file->mp->mutex); std::lock_guard lock(file->mp->mutex);
if (file->lock == 2)
{
return CELL_EIO;
}
*nread = file->op_read(buf, nbytes); *nread = file->op_read(buf, nbytes);
return CELL_OK; return CELL_OK;
@ -421,6 +426,11 @@ error_code sys_fs_write(ppu_thread& ppu, u32 fd, vm::cptr<void> buf, u64 nbytes,
if (file->lock) if (file->lock)
{ {
if (file->lock == 2)
{
return CELL_EIO;
}
return CELL_EBUSY; return CELL_EBUSY;
} }
@ -437,7 +447,7 @@ error_code sys_fs_close(ppu_thread& ppu, u32 fd)
const auto file = idm::withdraw<lv2_fs_object, lv2_file>(fd, [](lv2_file& file) -> CellError const auto file = idm::withdraw<lv2_fs_object, lv2_file>(fd, [](lv2_file& file) -> CellError
{ {
if (file.lock) if (file.lock == 1)
{ {
return CELL_EBUSY; return CELL_EBUSY;
} }
@ -706,6 +716,11 @@ error_code sys_fs_fstat(ppu_thread& ppu, u32 fd, vm::ptr<CellFsStat> sb)
std::lock_guard lock(file->mp->mutex); std::lock_guard lock(file->mp->mutex);
if (file->lock == 2)
{
return CELL_EIO;
}
const fs::stat_t& info = file->file.stat(); const fs::stat_t& info = file->file.stat();
sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666;
@ -958,6 +973,11 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr<void> _arg, u32
if (op == 0x8000000b && file->lock) if (op == 0x8000000b && file->lock)
{ {
if (file->lock == 2)
{
return CELL_EIO;
}
return CELL_EBUSY; return CELL_EBUSY;
} }
@ -1448,6 +1468,11 @@ error_code sys_fs_ftruncate(ppu_thread& ppu, u32 fd, u64 size)
std::lock_guard lock(file->mp->mutex); std::lock_guard lock(file->mp->mutex);
if (file->lock == 2)
{
return CELL_EIO;
}
if (file->lock) if (file->lock)
{ {
return CELL_EBUSY; return CELL_EBUSY;