WFS: Implement current/home path expansion.

This commit is contained in:
Pierre Bourdon 2017-08-05 19:51:29 +02:00
parent 5a4900bc96
commit c14ab0dd53
2 changed files with 42 additions and 4 deletions

View File

@ -117,12 +117,26 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
Memory::Memset(request.buffer_out, 0, request.buffer_out_size);
break;
case IOCTL_WFS_SET_HOMEDIR:
m_home_directory =
Memory::GetString(request.buffer_in + 2, Memory::Read_U16(request.buffer_in));
INFO_LOG(IOS, "IOCTL_WFS_SET_HOMEDIR: %s", m_home_directory.c_str());
break;
case IOCTL_WFS_CHDIR:
m_current_directory =
Memory::GetString(request.buffer_in + 2, Memory::Read_U16(request.buffer_in));
INFO_LOG(IOS, "IOCTL_WFS_CHDIR: %s", m_current_directory.c_str());
break;
case IOCTL_WFS_OPEN:
{
u32 mode = Memory::Read_U32(request.buffer_in);
u16 path_len = Memory::Read_U16(request.buffer_in + 0x20);
std::string path = Memory::GetString(request.buffer_in + 0x22, path_len);
path = ExpandPath(path);
u16 fd = GetNewFileDescriptor();
FileDescriptor* fd_obj = &m_fds[fd];
fd_obj->in_use = true;
@ -190,6 +204,24 @@ IPCCommandResult WFSSRV::IOCtl(const IOCtlRequest& request)
return GetDefaultReply(return_error_code);
}
std::string WFSSRV::ExpandPath(const std::string& path) const
{
std::string expanded;
if (!path.empty() && path[0] == '~')
{
expanded = m_home_directory + "/" + path.substr(1);
}
else if (path.empty() || path[0] != '/')
{
expanded = m_current_directory + "/" + path;
}
else
{
expanded = path;
}
return expanded;
}
WFSSRV::FileDescriptor* WFSSRV::FindFileDescriptor(u16 fd)
{
if (fd >= m_fds.size() || !m_fds[fd].in_use)

View File

@ -35,6 +35,12 @@ private:
// WFS device name, e.g. msc01/msc02.
std::string m_device_name;
// Home / current directories.
std::string m_home_directory;
std::string m_current_directory;
std::string ExpandPath(const std::string& path) const;
enum
{
IOCTL_WFS_INIT = 0x02,
@ -78,13 +84,13 @@ private:
};
std::vector<FileDescriptor> m_fds;
// List of addresses of IPC requests left hanging that need closing at
// shutdown time.
std::vector<u32> m_hanging;
FileDescriptor* FindFileDescriptor(u16 fd);
u16 GetNewFileDescriptor();
void ReleaseFileDescriptor(u16 fd);
// List of addresses of IPC requests left hanging that need closing at
// shutdown time.
std::vector<u32> m_hanging;
};
} // namespace Device
} // namespace HLE