Skip to content

Commit

Permalink
Implement Rename in IOMAN.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Aug 12, 2024
1 parent 55e98a8 commit bb39333
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Source/iop/Ioman_Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace Iop
//Return false to indicate that device doesn't support GetStat.
return false;
}
virtual void Rename(const char*, const char*)
{
throw std::runtime_error("Renaming not supported.");
}
};

typedef std::shared_ptr<CDevice> DevicePtr;
Expand Down
37 changes: 37 additions & 0 deletions Source/iop/Iop_Ioman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using namespace Iop;
#define FUNCTION_CHSTAT "ChStat"
#define FUNCTION_ADDDRV "AddDrv"
#define FUNCTION_DELDRV "DelDrv"
#define FUNCTION_RENAME "Rename"
#define FUNCTION_MOUNT "Mount"
#define FUNCTION_UMOUNT "Umount"
#define FUNCTION_SEEK64 "Seek64"
Expand Down Expand Up @@ -214,6 +215,9 @@ std::string CIoman::GetFunctionName(unsigned int functionId) const
case 21:
return FUNCTION_DELDRV;
break;
case 25:
return FUNCTION_RENAME;
break;
case 31:
return FUNCTION_DEVCTL;
break;
Expand Down Expand Up @@ -530,6 +534,34 @@ uint32 CIoman::DelDrv(uint32 drvNamePtr)
return -1;
}

int32 CIoman::Rename(const char* srcPath, const char* dstPath)
{
CLog::GetInstance().Print(LOG_NAME, FUNCTION_RENAME "(srcPath = '%s', dstPath = '%s');\r\n",
srcPath, dstPath);
int32 result = -1;
try
{
auto srcPathInfo = SplitPath(srcPath);
auto dstPathInfo = SplitPath(dstPath);
if(srcPathInfo.deviceName != dstPathInfo.deviceName)
{
throw std::runtime_error("Renaming files across devices not supported.");
}
auto deviceIterator = m_devices.find(srcPathInfo.deviceName);
if(deviceIterator == m_devices.end())
{
throw std::runtime_error("Device not found.");
}
deviceIterator->second->Rename(srcPathInfo.devicePath.c_str(), dstPathInfo.devicePath.c_str());
}
catch(const std::exception& except)
{
CLog::GetInstance().Warn(LOG_NAME, "%s: Error occured while trying to rename file '%s' to '%s'\r\n",
__FUNCTION__, srcPath, dstPath, except.what());
}
return result;
}

int32 CIoman::DevCtlVirtual(CMIPS& context)
{
uint32 deviceNamePtr = context.m_State.nGPR[CMIPS::A0].nV0;
Expand Down Expand Up @@ -1043,6 +1075,11 @@ void CIoman::Invoke(CMIPS& context, unsigned int functionId)
context.m_State.nGPR[CMIPS::V0].nD0 = static_cast<int32>(DelDrv(
context.m_State.nGPR[CMIPS::A0].nV0));
break;
case 25:
context.m_State.nGPR[CMIPS::V0].nD0 = Rename(
reinterpret_cast<const char*>(&m_ram[context.m_State.nGPR[CMIPS::A0].nV[0]]),
reinterpret_cast<const char*>(&m_ram[context.m_State.nGPR[CMIPS::A1].nV[0]]));
break;
case 31:
context.m_State.nGPR[CMIPS::V0].nD0 = DevCtlVirtual(context);
break;
Expand Down
1 change: 1 addition & 0 deletions Source/iop/Iop_Ioman.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Iop
uint32 GetStat(const char*, Ioman::STAT*);
int32 ChStat(const char*, Ioman::STAT*, uint32);
uint32 DelDrv(uint32);
int32 Rename(const char*, const char*);
int32 Mount(const char*, const char*);
int32 Umount(const char*);
uint64 Seek64(uint32, int64, uint32);
Expand Down
8 changes: 8 additions & 0 deletions Source/iop/ioman/DirectoryDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ void CDirectoryDevice::MakeDirectory(const char* devicePath)
throw std::runtime_error("Failed to create directory.");
}
}

void CDirectoryDevice::Rename(const char* srcDevicePath, const char* dstDevicePath)
{
auto basePath = GetBasePath();
auto srcPath = Iop::PathUtils::MakeHostPath(basePath, srcDevicePath);
auto dstPath = Iop::PathUtils::MakeHostPath(basePath, dstDevicePath);
fs::rename(srcPath, dstPath);
}
1 change: 1 addition & 0 deletions Source/iop/ioman/DirectoryDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Iop
Framework::CStream* GetFile(uint32, const char*) override;
DirectoryIteratorPtr GetDirectory(const char*) override;
void MakeDirectory(const char*) override;
void Rename(const char*, const char*) override;

protected:
virtual fs::path GetBasePath() = 0;
Expand Down

0 comments on commit bb39333

Please sign in to comment.