mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #6766 from leoetlino/ncd
IOS/NCD: Migrate to new filesystem interface
This commit is contained in:
commit
c3d88a622d
@ -61,4 +61,29 @@ void FileSystem::Init()
|
||||
if (Delete(0, 0, "/tmp") == ResultCode::Success)
|
||||
CreateDirectory(0, 0, "/tmp", 0, Mode::ReadWrite, Mode::ReadWrite, Mode::ReadWrite);
|
||||
}
|
||||
|
||||
ResultCode FileSystem::CreateFullPath(Uid uid, Gid gid, const std::string& path,
|
||||
FileAttribute attribute, Mode owner, Mode group, Mode other)
|
||||
{
|
||||
std::string::size_type position = 1;
|
||||
while (true)
|
||||
{
|
||||
position = path.find('/', position);
|
||||
if (position == std::string::npos)
|
||||
return ResultCode::Success;
|
||||
|
||||
const std::string subpath = path.substr(0, position);
|
||||
const Result<Metadata> metadata = GetMetadata(uid, gid, subpath);
|
||||
if (!metadata && metadata.Error() != ResultCode::NotFound)
|
||||
return metadata.Error();
|
||||
if (metadata && metadata->is_file)
|
||||
return ResultCode::Invalid;
|
||||
|
||||
const ResultCode result = CreateDirectory(uid, gid, subpath, attribute, owner, group, other);
|
||||
if (result != ResultCode::Success && result != ResultCode::AlreadyExists)
|
||||
return result;
|
||||
|
||||
++position;
|
||||
}
|
||||
}
|
||||
} // namespace IOS::HLE::FS
|
||||
|
@ -157,6 +157,11 @@ public:
|
||||
FileAttribute attribute, Mode owner_mode, Mode group_mode,
|
||||
Mode other_mode) = 0;
|
||||
|
||||
/// Create any parent directories for a path with the specified metadata.
|
||||
/// Example: "/a/b" to create directory /a; "/a/b/" to create directories /a and /a/b
|
||||
ResultCode CreateFullPath(Uid caller_uid, Gid caller_gid, const std::string& path,
|
||||
FileAttribute attribute, Mode ownerm, Mode group, Mode other);
|
||||
|
||||
/// Delete a file or directory with the specified path.
|
||||
virtual ResultCode Delete(Uid caller_uid, Gid caller_gid, const std::string& path) = 0;
|
||||
/// Rename a file or directory with the specified path.
|
||||
|
@ -21,6 +21,7 @@ namespace Device
|
||||
{
|
||||
NetNCDManage::NetNCDManage(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
|
||||
{
|
||||
config.ReadConfig(ios.GetFS().get());
|
||||
}
|
||||
|
||||
IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
|
||||
@ -51,14 +52,14 @@ IPCCommandResult NetNCDManage::IOCtlV(const IOCtlVRequest& request)
|
||||
|
||||
case IOCTLV_NCD_READCONFIG:
|
||||
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_READCONFIG");
|
||||
config.ReadConfig();
|
||||
config.ReadConfig(m_ios.GetFS().get());
|
||||
config.WriteToMem(request.io_vectors.at(0).address);
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_WRITECONFIG:
|
||||
INFO_LOG(IOS_NET, "NET_NCD_MANAGE: IOCTLV_NCD_WRITECONFIG");
|
||||
config.ReadFromMem(request.in_vectors.at(0).address);
|
||||
config.WriteConfig();
|
||||
config.WriteConfig(m_ios.GetFS().get());
|
||||
break;
|
||||
|
||||
case IOCTLV_NCD_GETLINKSTATUS:
|
||||
|
@ -8,10 +8,10 @@
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/File.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/IOS/FS/FileSystem.h"
|
||||
#include "Core/IOS/IOS.h"
|
||||
|
||||
namespace IOS
|
||||
{
|
||||
@ -19,36 +19,34 @@ namespace HLE
|
||||
{
|
||||
namespace Net
|
||||
{
|
||||
WiiNetConfig::WiiNetConfig()
|
||||
{
|
||||
m_path = File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR "/net/02/config.dat";
|
||||
ReadConfig();
|
||||
}
|
||||
static const std::string CONFIG_PATH = "/shared2/sys/net/02/config.dat";
|
||||
|
||||
void WiiNetConfig::ReadConfig()
|
||||
{
|
||||
if (!File::IOFile(m_path, "rb").ReadBytes(&m_data, sizeof(m_data)))
|
||||
ResetConfig();
|
||||
}
|
||||
WiiNetConfig::WiiNetConfig() = default;
|
||||
|
||||
void WiiNetConfig::WriteConfig() const
|
||||
void WiiNetConfig::ReadConfig(FS::FileSystem* fs)
|
||||
{
|
||||
if (!File::Exists(m_path))
|
||||
{
|
||||
if (!File::CreateFullPath(File::GetUserPath(D_SESSION_WIIROOT_IDX) + "/" WII_SYSCONF_DIR
|
||||
"/net/02/"))
|
||||
{
|
||||
ERROR_LOG(IOS_NET, "Failed to create directory for network config file");
|
||||
}
|
||||
const auto file = fs->OpenFile(PID_NCD, PID_NCD, CONFIG_PATH, FS::Mode::Read);
|
||||
if (file && file->Read(&m_data, 1))
|
||||
return;
|
||||
}
|
||||
|
||||
File::IOFile(m_path, "wb").WriteBytes(&m_data, sizeof(m_data));
|
||||
ResetConfig(fs);
|
||||
}
|
||||
|
||||
void WiiNetConfig::ResetConfig()
|
||||
void WiiNetConfig::WriteConfig(FS::FileSystem* fs) const
|
||||
{
|
||||
if (File::Exists(m_path))
|
||||
File::Delete(m_path);
|
||||
fs->CreateFullPath(PID_NCD, PID_NCD, CONFIG_PATH, 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite,
|
||||
FS::Mode::ReadWrite);
|
||||
fs->CreateFile(PID_NCD, PID_NCD, CONFIG_PATH, 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite,
|
||||
FS::Mode::ReadWrite);
|
||||
const auto file = fs->OpenFile(PID_NCD, PID_NCD, CONFIG_PATH, FS::Mode::Write);
|
||||
if (!file || !file->Write(&m_data, 1))
|
||||
ERROR_LOG(IOS_NET, "Failed to write config");
|
||||
}
|
||||
|
||||
void WiiNetConfig::ResetConfig(FS::FileSystem* fs)
|
||||
{
|
||||
fs->Delete(PID_NCD, PID_NCD, CONFIG_PATH);
|
||||
|
||||
memset(&m_data, 0, sizeof(m_data));
|
||||
m_data.connType = ConfigData::IF_WIRED;
|
||||
@ -56,7 +54,7 @@ void WiiNetConfig::ResetConfig()
|
||||
ConnectionSettings::WIRED_IF | ConnectionSettings::DNS_DHCP | ConnectionSettings::IP_DHCP |
|
||||
ConnectionSettings::CONNECTION_TEST_OK | ConnectionSettings::CONNECTION_SELECTED;
|
||||
|
||||
WriteConfig();
|
||||
WriteConfig(fs);
|
||||
}
|
||||
|
||||
void WiiNetConfig::WriteToMem(const u32 address) const
|
||||
|
@ -11,6 +11,11 @@ namespace IOS
|
||||
{
|
||||
namespace HLE
|
||||
{
|
||||
namespace FS
|
||||
{
|
||||
class FileSystem;
|
||||
}
|
||||
|
||||
namespace Net
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
@ -105,9 +110,9 @@ class WiiNetConfig final
|
||||
public:
|
||||
WiiNetConfig();
|
||||
|
||||
void ReadConfig();
|
||||
void WriteConfig() const;
|
||||
void ResetConfig();
|
||||
void ReadConfig(FS::FileSystem* fs);
|
||||
void WriteConfig(FS::FileSystem* fs) const;
|
||||
void ResetConfig(FS::FileSystem* fs);
|
||||
|
||||
void WriteToMem(u32 address) const;
|
||||
void ReadFromMem(u32 address);
|
||||
@ -135,7 +140,6 @@ private:
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
std::string m_path;
|
||||
ConfigData m_data;
|
||||
};
|
||||
} // namespace Net
|
||||
|
Loading…
Reference in New Issue
Block a user