WFS: Implement RENAME.

This commit is contained in:
Léo Lam 2017-08-16 23:33:34 +02:00
parent 2a8d9a53b7
commit 15f25783a8
2 changed files with 41 additions and 3 deletions

View File

@ -4,6 +4,7 @@
#include "Core/IOS/WFS/WFSSRV.h" #include "Core/IOS/WFS/WFSSRV.h"
#include <algorithm>
#include <cinttypes> #include <cinttypes>
#include <string> #include <string>
#include <vector> #include <vector>
@ -184,6 +185,17 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
break; break;
} }
case IOCTL_WFS_RENAME:
case IOCTL_WFS_RENAME_2:
{
const std::string source_path =
Memory::GetString(request.buffer_in + 2, Memory::Read_U16(request.buffer_in));
const std::string dest_path =
Memory::GetString(request.buffer_in + 512 + 2, Memory::Read_U16(request.buffer_in + 512));
return_error_code = Rename(source_path, dest_path);
break;
}
case IOCTL_WFS_CREATE_OPEN: case IOCTL_WFS_CREATE_OPEN:
case IOCTL_WFS_OPEN: case IOCTL_WFS_OPEN:
{ {
@ -353,6 +365,26 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
return GetDefaultReply(return_error_code); return GetDefaultReply(return_error_code);
} }
s32 WFSSRV::Rename(std::string source, std::string dest) const
{
source = NormalizePath(source);
dest = NormalizePath(dest);
INFO_LOG(IOS_WFS, "IOCTL_WFS_RENAME: %s to %s", source.c_str(), dest.c_str());
const bool opened = std::any_of(m_fds.begin(), m_fds.end(),
[&](const auto& fd) { return fd.in_use && fd.path == source; });
if (opened)
return WFS_FILE_IS_OPENED;
// TODO(wfs): Handle other rename failures
if (!File::Rename(WFS::NativePath(source), WFS::NativePath(dest)))
return WFS_ENOENT;
return IPC_SUCCESS;
}
std::string WFSSRV::NormalizePath(const std::string& path) const std::string WFSSRV::NormalizePath(const std::string& path) const
{ {
std::string expanded; std::string expanded;

View File

@ -24,9 +24,11 @@ std::string NativePath(const std::string& wfs_path);
enum enum
{ {
WFS_EBADFD = -10026, // Invalid file descriptor. WFS_EINVAL = -10003, // Invalid argument.
WFS_EEXIST = -10027, // File already exists. WFS_EBADFD = -10026, // Invalid file descriptor.
WFS_ENOENT = -10028, // No such file or directory. WFS_EEXIST = -10027, // File already exists.
WFS_ENOENT = -10028, // No such file or directory.
WFS_FILE_IS_OPENED = -10032, // Cannot perform operation on an opened file.
}; };
namespace Device namespace Device
@ -38,6 +40,8 @@ public:
IPCCommandResult IOCtl(const IOCtlRequest& request) override; IPCCommandResult IOCtl(const IOCtlRequest& request) override;
s32 Rename(std::string source, std::string dest) const;
private: private:
// WFS device name, e.g. msc01/msc02. // WFS device name, e.g. msc01/msc02.
std::string m_device_name; std::string m_device_name;
@ -66,6 +70,7 @@ private:
IOCTL_WFS_GET_HOMEDIR = 0x12, IOCTL_WFS_GET_HOMEDIR = 0x12,
IOCTL_WFS_GETCWD = 0x13, IOCTL_WFS_GETCWD = 0x13,
IOCTL_WFS_DELETE = 0x15, IOCTL_WFS_DELETE = 0x15,
IOCTL_WFS_RENAME = 0x16,
IOCTL_WFS_GET_ATTRIBUTES = 0x17, IOCTL_WFS_GET_ATTRIBUTES = 0x17,
IOCTL_WFS_CREATE_OPEN = 0x19, IOCTL_WFS_CREATE_OPEN = 0x19,
IOCTL_WFS_OPEN = 0x1A, IOCTL_WFS_OPEN = 0x1A,
@ -75,6 +80,7 @@ private:
IOCTL_WFS_WRITE = 0x22, IOCTL_WFS_WRITE = 0x22,
IOCTL_WFS_ATTACH_DETACH = 0x2d, IOCTL_WFS_ATTACH_DETACH = 0x2d,
IOCTL_WFS_ATTACH_DETACH_2 = 0x2e, IOCTL_WFS_ATTACH_DETACH_2 = 0x2e,
IOCTL_WFS_RENAME_2 = 0x41,
IOCTL_WFS_CLOSE_2 = 0x47, IOCTL_WFS_CLOSE_2 = 0x47,
IOCTL_WFS_READ_ABSOLUTE = 0x48, IOCTL_WFS_READ_ABSOLUTE = 0x48,
IOCTL_WFS_WRITE_ABSOLUTE = 0x49, IOCTL_WFS_WRITE_ABSOLUTE = 0x49,