IOS/ES: Deduplicate fields for opened content entries

Now that we have a proper Content structure for contents,
let's just use it instead of duplicating the fields.
This commit is contained in:
Léo Lam 2017-02-25 15:21:18 +01:00
parent c4137c2880
commit 345d252ef3
2 changed files with 38 additions and 53 deletions

View File

@ -168,38 +168,23 @@ void ES::DoState(PointerWrap& p)
u32 Count = (u32)(m_ContentAccessMap.size()); u32 Count = (u32)(m_ContentAccessMap.size());
p.Do(Count); p.Do(Count);
u32 CFD = 0;
u32 Position = 0;
u64 TitleID = 0;
u16 Index = 0;
if (p.GetMode() == PointerWrap::MODE_READ) if (p.GetMode() == PointerWrap::MODE_READ)
{ {
for (u32 i = 0; i < Count; i++) for (u32 i = 0; i < Count; i++)
{ {
p.Do(CFD); u32 cfd = 0;
p.Do(Position); OpenedContent content;
p.Do(TitleID); p.Do(cfd);
p.Do(Index); p.Do(content);
CFD = OpenTitleContent(CFD, TitleID, Index); cfd = OpenTitleContent(cfd, content.m_title_id, content.m_content.index);
if (CFD != 0xffffffff)
{
m_ContentAccessMap[CFD].m_Position = Position;
}
} }
} }
else else
{ {
for (auto& pair : m_ContentAccessMap) for (const auto& pair : m_ContentAccessMap)
{ {
CFD = pair.first; p.Do(pair.first);
SContentAccess& Access = pair.second; p.Do(pair.second);
Position = Access.m_Position;
TitleID = Access.m_TitleID;
Index = Access.m_Index;
p.Do(CFD);
p.Do(Position);
p.Do(TitleID);
p.Do(Index);
} }
} }
} }
@ -243,15 +228,14 @@ u32 ES::OpenTitleContent(u32 CFD, u64 TitleID, u16 Index)
return 0xffffffff; // TODO: what is the correct error value here? return 0xffffffff; // TODO: what is the correct error value here?
} }
SContentAccess Access; OpenedContent content;
Access.m_Position = 0; content.m_position = 0;
Access.m_Index = pContent->m_metadata.index; content.m_content = pContent->m_metadata;
Access.m_Size = static_cast<u32>(pContent->m_metadata.size); content.m_title_id = TitleID;
Access.m_TitleID = TitleID;
pContent->m_Data->Open(); pContent->m_Data->Open();
m_ContentAccessMap[CFD] = Access; m_ContentAccessMap[CFD] = content;
return CFD; return CFD;
} }
@ -599,29 +583,30 @@ IPCCommandResult ES::ReadContent(const IOCtlVRequest& request)
{ {
return GetDefaultReply(-1); return GetDefaultReply(-1);
} }
SContentAccess& rContent = itr->second; OpenedContent& rContent = itr->second;
u8* pDest = Memory::GetPointer(Addr); u8* pDest = Memory::GetPointer(Addr);
if (rContent.m_Position + Size > rContent.m_Size) if (rContent.m_position + Size > rContent.m_content.size)
{ {
Size = rContent.m_Size - rContent.m_Position; Size = static_cast<u32>(rContent.m_content.size) - rContent.m_position;
} }
if (Size > 0) if (Size > 0)
{ {
if (pDest) if (pDest)
{ {
const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(rContent.m_TitleID); const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(rContent.m_title_id);
// ContentLoader should never be invalid; rContent has been created by it. // ContentLoader should never be invalid; rContent has been created by it.
if (ContentLoader.IsValid() && ContentLoader.GetTicket().IsValid()) if (ContentLoader.IsValid() && ContentLoader.GetTicket().IsValid())
{ {
const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(rContent.m_Index); const DiscIO::SNANDContent* pContent =
if (!pContent->m_Data->GetRange(rContent.m_Position, Size, pDest)) ContentLoader.GetContentByIndex(rContent.m_content.index);
ERROR_LOG(IOS_ES, "ES: failed to read %u bytes from %u!", Size, rContent.m_Position); if (!pContent->m_Data->GetRange(rContent.m_position, Size, pDest))
ERROR_LOG(IOS_ES, "ES: failed to read %u bytes from %u!", Size, rContent.m_position);
} }
rContent.m_Position += Size; rContent.m_position += Size;
} }
else else
{ {
@ -631,7 +616,7 @@ IPCCommandResult ES::ReadContent(const IOCtlVRequest& request)
DEBUG_LOG(IOS_ES, DEBUG_LOG(IOS_ES,
"IOCTL_ES_READCONTENT: CFD %x, Address 0x%x, Size %i -> stream pos %i (Index %i)", CFD, "IOCTL_ES_READCONTENT: CFD %x, Address 0x%x, Size %i -> stream pos %i (Index %i)", CFD,
Addr, Size, rContent.m_Position, rContent.m_Index); Addr, Size, rContent.m_position, rContent.m_content.index);
return GetDefaultReply(Size); return GetDefaultReply(Size);
} }
@ -651,11 +636,12 @@ IPCCommandResult ES::CloseContent(const IOCtlVRequest& request)
return GetDefaultReply(-1); return GetDefaultReply(-1);
} }
const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(itr->second.m_TitleID); const DiscIO::CNANDContentLoader& ContentLoader = AccessContentDevice(itr->second.m_title_id);
// ContentLoader should never be invalid; we shouldn't be here if ES_OPENCONTENT failed before. // ContentLoader should never be invalid; we shouldn't be here if ES_OPENCONTENT failed before.
if (ContentLoader.IsValid()) if (ContentLoader.IsValid())
{ {
const DiscIO::SNANDContent* pContent = ContentLoader.GetContentByIndex(itr->second.m_Index); const DiscIO::SNANDContent* pContent =
ContentLoader.GetContentByIndex(itr->second.m_content.index);
pContent->m_Data->Close(); pContent->m_Data->Close();
} }
@ -678,27 +664,27 @@ IPCCommandResult ES::SeekContent(const IOCtlVRequest& request)
{ {
return GetDefaultReply(-1); return GetDefaultReply(-1);
} }
SContentAccess& rContent = itr->second; OpenedContent& rContent = itr->second;
switch (Mode) switch (Mode)
{ {
case 0: // SET case 0: // SET
rContent.m_Position = Addr; rContent.m_position = Addr;
break; break;
case 1: // CUR case 1: // CUR
rContent.m_Position += Addr; rContent.m_position += Addr;
break; break;
case 2: // END case 2: // END
rContent.m_Position = rContent.m_Size + Addr; rContent.m_position = static_cast<u32>(rContent.m_content.size) + Addr;
break; break;
} }
DEBUG_LOG(IOS_ES, "IOCTL_ES_SEEKCONTENT: CFD %x, Address 0x%x, Mode %i -> Pos %i", CFD, Addr, DEBUG_LOG(IOS_ES, "IOCTL_ES_SEEKCONTENT: CFD %x, Address 0x%x, Mode %i -> Pos %i", CFD, Addr,
Mode, rContent.m_Position); Mode, rContent.m_position);
return GetDefaultReply(rContent.m_Position); return GetDefaultReply(rContent.m_position);
} }
IPCCommandResult ES::GetTitleDirectory(const IOCtlVRequest& request) IPCCommandResult ES::GetTitleDirectory(const IOCtlVRequest& request)

View File

@ -131,12 +131,11 @@ private:
ES_HASH_SIZE_WRONG = -2014, // HASH !=20 ES_HASH_SIZE_WRONG = -2014, // HASH !=20
}; };
struct SContentAccess struct OpenedContent
{ {
u32 m_Position; u64 m_title_id;
u64 m_TitleID; IOS::ES::Content m_content;
u16 m_Index; u32 m_position;
u32 m_Size;
}; };
struct ecc_cert_t struct ecc_cert_t
@ -199,8 +198,8 @@ private:
u32 OpenTitleContent(u32 CFD, u64 TitleID, u16 Index); u32 OpenTitleContent(u32 CFD, u64 TitleID, u16 Index);
using CContentAccessMap = std::map<u32, SContentAccess>; using ContentAccessMap = std::map<u32, OpenedContent>;
CContentAccessMap m_ContentAccessMap; ContentAccessMap m_ContentAccessMap;
std::vector<u64> m_TitleIDs; std::vector<u64> m_TitleIDs;
u64 m_TitleID = -1; u64 m_TitleID = -1;