summaryrefslogtreecommitdiff
path: root/Source/Core/Common/SysConf.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2018-03-11 12:05:12 +0100
committerLéo Lam <leo@innovatetechnologi.es>2018-04-12 22:16:37 +0200
commit0856d4a68a61b274353b1b46d7eb8f725402bf5b (patch)
treebd7b543f4678fe96dbca136fde4e2b3e47122b0d /Source/Core/Common/SysConf.cpp
parent3744a6d3f542d56837f8bce20c22e6e49ede85c0 (diff)
SysConf: Migrate to new filesystem interface
It was discovered that some titles rely on filesystem metadata to work properly. Currently, in master they either simply won't find their save files (for example Bolt) or will complain about the Wii system memory being corrupted (on first use or every time depending on the title). In order to even be able to keep track of file metadata, we first need to eliminate all direct accesses to the NAND and make all kinds of operations go through the filesystem code added in PR 6421. This commit starts the migration process by making SysConf use the new FS interface.
Diffstat (limited to 'Source/Core/Common/SysConf.cpp')
-rw-r--r--Source/Core/Common/SysConf.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/Source/Core/Common/SysConf.cpp b/Source/Core/Common/SysConf.cpp
index 22e902d042..36ab4fa325 100644
--- a/Source/Core/Common/SysConf.cpp
+++ b/Source/Core/Common/SysConf.cpp
@@ -14,6 +14,7 @@
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/Swap.h"
+#include "Core/IOS/FS/FileSystem.h"
constexpr size_t SYSCONF_SIZE = 0x4000;
@@ -35,9 +36,8 @@ static size_t GetNonArrayEntrySize(SysConf::Entry::Type type)
return 0;
}
}
-SysConf::SysConf(const Common::FromWhichRoot root_type)
+SysConf::SysConf(std::shared_ptr<IOS::HLE::FS::FileSystem> fs) : m_fs{fs}
{
- m_file_name = Common::RootUserPath(root_type) + DIR_SEP WII_SYSCONF_DIR DIR_SEP WII_SYSCONF;
Load();
}
@@ -55,39 +55,40 @@ void SysConf::Load()
{
Clear();
- if (File::GetSize(m_file_name) != SYSCONF_SIZE || !LoadFromFile(m_file_name))
+ const auto file = m_fs->OpenFile(IOS::HLE::FS::Uid{0}, IOS::HLE::FS::Gid{0},
+ "/shared2/sys/SYSCONF", IOS::HLE::FS::Mode::Read);
+ if (!file || file->GetStatus()->size != SYSCONF_SIZE || !LoadFromFile(*file))
{
WARN_LOG(CORE, "No valid SYSCONF detected. Creating a new one.");
InsertDefaultEntries();
}
}
-bool SysConf::LoadFromFile(const std::string& file_name)
+bool SysConf::LoadFromFile(const IOS::HLE::FS::FileHandle& file)
{
- File::IOFile file(file_name, "rb");
- file.Seek(4, SEEK_SET);
+ file.Seek(4, IOS::HLE::FS::SeekMode::Set);
u16 number_of_entries;
- file.ReadBytes(&number_of_entries, sizeof(number_of_entries));
+ file.Read(&number_of_entries, 1);
number_of_entries = Common::swap16(number_of_entries);
std::vector<u16> offsets(number_of_entries);
for (u16& offset : offsets)
{
- file.ReadBytes(&offset, sizeof(offset));
+ file.Read(&offset, 1);
offset = Common::swap16(offset);
}
for (const u16 offset : offsets)
{
- file.Seek(offset, SEEK_SET);
+ file.Seek(offset, IOS::HLE::FS::SeekMode::Set);
// Metadata
u8 description = 0;
- file.ReadBytes(&description, sizeof(description));
+ file.Read(&description, 1);
const Entry::Type type = static_cast<Entry::Type>((description & 0xe0) >> 5);
const u8 name_length = (description & 0x1f) + 1;
std::string name(name_length, '\0');
- file.ReadBytes(&name[0], name.size());
+ file.Read(&name[0], name.size());
// Data
std::vector<u8> data;
@@ -96,7 +97,7 @@ bool SysConf::LoadFromFile(const std::string& file_name)
case Entry::Type::BigArray:
{
u16 data_length = 0;
- file.ReadBytes(&data_length, sizeof(data_length));
+ file.Read(&data_length, 1);
// The stored u16 is length - 1, not length.
data.resize(Common::swap16(data_length) + 1);
break;
@@ -104,7 +105,7 @@ bool SysConf::LoadFromFile(const std::string& file_name)
case Entry::Type::SmallArray:
{
u8 data_length = 0;
- file.ReadBytes(&data_length, sizeof(data_length));
+ file.Read(&data_length, 1);
data.resize(data_length + 1);
break;
}
@@ -121,7 +122,7 @@ bool SysConf::LoadFromFile(const std::string& file_name)
return false;
}
- file.ReadBytes(data.data(), data.size());
+ file.Read(data.data(), data.size());
AddEntry({type, name, std::move(data)});
}
return true;
@@ -194,14 +195,19 @@ bool SysConf::Save() const
std::copy(footer.cbegin(), footer.cend(), buffer.end() - footer.size());
// Write the new data.
- const std::string temp_file = m_file_name + ".tmp";
- File::CreateFullPath(temp_file);
+ const std::string temp_file = "/tmp/SYSCONF";
+ constexpr u32 SYSMENU_UID = 0x1000;
+ constexpr u16 SYSMENU_GID = 1;
+ constexpr auto rw_mode = IOS::HLE::FS::Mode::ReadWrite;
{
- File::IOFile file(temp_file, "wb");
- if (!file.WriteBytes(buffer.data(), buffer.size()))
+ m_fs->CreateFile(SYSMENU_UID, SYSMENU_GID, temp_file, 0, rw_mode, rw_mode, rw_mode);
+ auto file = m_fs->OpenFile(SYSMENU_UID, SYSMENU_GID, temp_file, IOS::HLE::FS::Mode::Write);
+ if (!file || !file->Write(buffer.data(), buffer.size()))
return false;
}
- return File::RenameSync(temp_file, m_file_name);
+ m_fs->CreateDirectory(SYSMENU_UID, SYSMENU_GID, "/shared2/sys", 0, rw_mode, rw_mode, rw_mode);
+ const auto result = m_fs->Rename(SYSMENU_UID, SYSMENU_GID, temp_file, "/shared2/sys/SYSCONF");
+ return result == IOS::HLE::FS::ResultCode::Success;
}
SysConf::Entry::Entry(Type type_, const std::string& name_) : type(type_), name(name_)