Skip to content

Commit

Permalink
Savestates/sys_fs: Fix file saving
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Oct 2, 2023
1 parent 26a61e8 commit 8c7132b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
24 changes: 16 additions & 8 deletions rpcs3/Emu/Cell/lv2/sys_fs.cpp
Expand Up @@ -502,20 +502,28 @@ void lv2_file::save(utils::serial& ar)
fs::file_id test_s = test.get_id();
fs::file_id file_s = file.get_id();

return test_s.is_coherent_with(file_s);
return !test_s.is_coherent_with(file_s);
}();

if (in_mem)
{
sys_fs.error("Saving \'%s\' LV2 file descriptor in memory! (exists=%s, type=%s, flags=0x%x)", name.data(), fs::is_file(real_path), type, flags);
}

ar(in_mem);

if (in_mem)
{
ar(file.to_vector<u8>());
ar(file.get_stat());
fs::stat_t stats = file.get_stat();

sys_fs.error("Saving \'%s\' LV2 file descriptor in memory! (exists=%s, type=%s, flags=0x%x, size=0x%x)", name.data(), fs::is_file(real_path), type, flags, stats.size);

const usz old_end = ar.pad_from_end(stats.size);

if (usz read_size = file.read_at(0, &ar.data[old_end], stats.size); read_size != stats.size)
{
ensure(read_size < stats.size);
sys_fs.error("Read less than expected! (new-size=0x%x)", read_size);
stats.size = read_size;
ar.data.resize(old_end + stats.size);
}

ar(stats);
}

ar(file.pos());
Expand Down
8 changes: 8 additions & 0 deletions rpcs3/util/serialization.hpp
Expand Up @@ -324,6 +324,14 @@ namespace utils
return pos;
}

usz pad_from_end(usz forwards)
{
ensure(is_writing());
pos = data.size();
data.resize(pos + forwards);
return pos;
}

template <typename T> requires (std::is_copy_constructible_v<std::remove_const_t<T>>) && (std::is_constructible_v<std::remove_const_t<T>> || Bitcopy<std::remove_const_t<T>> ||
std::is_constructible_v<std::remove_const_t<T>, stx::exact_t<serial&>> || TupleAlike<std::remove_const_t<T>>)
operator T()
Expand Down

0 comments on commit 8c7132b

Please sign in to comment.