IOS/ES: Implement DeleteTitle

No idea why this wasn't implemented whereas ES_DeleteTicket and
ES_DeleteTitleContent were.

This probably fixes title deletion in old System Menus, and maybe
the new ones as well in some cases; I've seen 4.3 use this ioctlv.
This commit is contained in:
Léo Lam 2017-02-26 01:14:41 +01:00
parent d666363ac4
commit ac43836714
2 changed files with 37 additions and 0 deletions

View File

@ -272,6 +272,8 @@ IPCCommandResult ES::IOCtlV(const IOCtlVRequest& request)
return GetTMDViews(request);
case IOCTL_ES_GETCONSUMPTION:
return GetConsumption(request);
case IOCTL_ES_DELETETITLE:
return DeleteTitle(request);
case IOCTL_ES_DELETETICKET:
return DeleteTicket(request);
case IOCTL_ES_DELETETITLECONTENT:
@ -849,6 +851,40 @@ IPCCommandResult ES::GetConsumption(const IOCtlVRequest& request)
return GetDefaultReply(IPC_SUCCESS);
}
static bool CanDeleteTitle(u64 title_id)
{
// IOS only allows deleting non-system titles (or a system title higher than 00000001-00000101).
return static_cast<u32>(title_id >> 32) != 0x00000001 || static_cast<u32>(title_id) > 0x101;
}
IPCCommandResult ES::DeleteTitle(const IOCtlVRequest& request)
{
if (!request.HasNumberOfValidVectors(1, 0) || request.in_vectors[0].size != 8)
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
const u64 title_id = Memory::Read_U64(request.in_vectors[0].address);
if (!CanDeleteTitle(title_id))
return GetDefaultReply(ES_PARAMETER_SIZE_OR_ALIGNMENT);
const std::string title_dir =
StringFromFormat("%s/title/%08x/%08x/", RootUserPath(Common::FROM_SESSION_ROOT).c_str(),
static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
if (!File::IsDirectory(title_dir) ||
!DiscIO::CNANDContentManager::Access().RemoveTitle(title_id, Common::FROM_SESSION_ROOT))
{
return GetDefaultReply(FS_ENOENT);
}
if (!File::DeleteDirRecursively(title_dir))
{
ERROR_LOG(IOS_ES, "DeleteTitle: Failed to delete title directory: %s", title_dir.c_str());
return GetDefaultReply(FS_EACCESS);
}
return GetDefaultReply(IPC_SUCCESS);
}
IPCCommandResult ES::DeleteTicket(const IOCtlVRequest& request)
{
u64 TitleID = Memory::Read_U64(request.in_vectors[0].address);

View File

@ -175,6 +175,7 @@ private:
IPCCommandResult GetTMDViewCount(const IOCtlVRequest& request);
IPCCommandResult GetTMDViews(const IOCtlVRequest& request);
IPCCommandResult GetConsumption(const IOCtlVRequest& request);
IPCCommandResult DeleteTitle(const IOCtlVRequest& request);
IPCCommandResult DeleteTicket(const IOCtlVRequest& request);
IPCCommandResult DeleteTitleContent(const IOCtlVRequest& request);
IPCCommandResult GetStoredTMDSize(const IOCtlVRequest& request);