From a59fe8eb0f497e358fc8d7a2a493aed71dc880cb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 9 Jan 2013 00:10:52 -0800 Subject: [PATCH 1/5] Fix sce_lbn parsing for missing 0x, etc. --- Core/FileSystems/ISOFileSystem.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index a8ea984e43..dc25459134 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -27,15 +27,29 @@ const int sectorSize = 2048; static bool parseLBN(std::string filename, u32 *sectorStart, u32 *readSize) { - if (filename.substr(0, 8) != "/sce_lbn") + // Looks like: /sce_lbn0x10_size0x100 or /sce_lbn10_size100 (always hex.) + if (filename.compare(0, sizeof("/sce_lbn") - 1, "/sce_lbn") != 0) return false; - std::string prev = filename; - filename.erase(0, 10); - if (sscanf(filename.c_str(), "%08x", sectorStart) != 1) - WARN_LOG(FILESYS, "Invalid LBN reference: %s", prev.c_str()); - filename.erase(0, filename.find("_size") + 7); - if (sscanf(filename.c_str(), "%08x", readSize) != 1) - WARN_LOG(FILESYS, "Incomplete LBN reference: %s", prev.c_str()); + + size_t pos = sizeof("/sce_lbn") - 1; + const char *filename_c = filename.c_str(); + + int offset = 0; + if (sscanf(filename_c + pos, "%x%n", sectorStart, &offset) != 1) + WARN_LOG(FILESYS, "Invalid LBN reference: %s", filename_c); + pos += offset; + + if (filename.compare(pos, sizeof("_size") - 1, "_size") != 0) + WARN_LOG(FILESYS, "Invalid LBN reference: %s", filename_c); + pos += sizeof("_size") - 1; + + offset = 0; + if (sscanf(filename_c + pos, "%x%n", readSize, &offset) != 1) + WARN_LOG(FILESYS, "Invalid LBN reference: %s", filename_c); + pos += offset; + + if (filename.size() > pos) + WARN_LOG(FILESYS, "Incomplete LBN reference: %s", filename_c); return true; } From b7be025bde8562e44a615e29b6afb954fd1b1d8f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 9 Jan 2013 00:43:07 -0800 Subject: [PATCH 2/5] Fix basic seeking within an lbn raw file. --- Core/FileSystems/ISOFileSystem.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index dc25459134..8796c74bc5 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -411,8 +411,7 @@ size_t ISOFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) u32 positionOnIso; if (e.isRawSector) { - // TODO: this seems bogus - positionOnIso = e.sectorStart * 2048; + positionOnIso = e.sectorStart * 2048 + e.seekPos; if (e.seekPos + size > e.openSize) { @@ -487,7 +486,7 @@ size_t ISOFileSystem::SeekFile(u32 handle, s32 position, FileMove type) break; case FILEMOVE_END: if (e.isRawSector) - e.seekPos = e.openSize; + e.seekPos = e.openSize + position; else e.seekPos = (unsigned int)(e.file->size + position); break; From 3e3e9b761fdf7bec7d8482f709dc39357be88720 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 9 Jan 2013 00:46:47 -0800 Subject: [PATCH 3/5] Fix it so headless can actually mount isos. --- Core/PSPLoaders.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index 7915b80d66..db8233343b 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -62,7 +62,7 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string) //pspFileSystem.Mount("host0:",umd2); pspFileSystem.Mount("umd0:", umd2); pspFileSystem.Mount("umd1:", umd2); - pspFileSystem.Mount("disc0:", umd2); + pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); pspFileSystem.Mount("UMD0:", umd2); pspFileSystem.Mount("UMD1:", umd2); @@ -116,6 +116,19 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string) bool Load_PSP_ELF_PBP(const char *filename, std::string *error_string) { + // This is really just for headless, might need tweaking later. + if (!PSP_CoreParameter().mountIso.empty()) + { + ISOFileSystem *umd2 = new ISOFileSystem(&pspFileSystem, constructBlockDevice(PSP_CoreParameter().mountIso.c_str())); + + pspFileSystem.Mount("umd1:", umd2); + pspFileSystem.Mount("disc0:", umd2); + pspFileSystem.Mount("umd:", umd2); + pspFileSystem.Mount("UMD1:", umd2); + pspFileSystem.Mount("DISC0:", umd2); + pspFileSystem.Mount("UMD:", umd2); + } + std::string full_path = filename; std::string path, file, extension; SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); From 6327c6e629dd21dbccd73fdab811e43966965aba Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 9 Jan 2013 00:57:44 -0800 Subject: [PATCH 4/5] Make filesystem prefix matching case fold. Even Ms0:/, disC0:/ and HoSt0:/ etc. work. --- Core/FileSystems/MetaFileSystem.cpp | 4 ++-- Core/PSPLoaders.cpp | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index ad144396d8..fde8036b24 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -169,7 +169,7 @@ bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpat // Special handling: host0:command.txt (as seen in Super Monkey Ball Adventures, for example) // appears to mean the current directory on the UMD. Let's just assume the current directory. std::string inpath = _inpath; - if (inpath.substr(0, 6) == "host0:") { + if (strncasecmp(inpath.c_str(), "host0:", 5) == 0) { INFO_LOG(HLE, "Host0 path detected, stripping: %s", inpath.c_str()); inpath = inpath.substr(6); } @@ -179,7 +179,7 @@ bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpat for (size_t i = 0; i < fileSystems.size(); i++) { size_t prefLen = fileSystems[i].prefix.size(); - if (fileSystems[i].prefix == realpath.substr(0, prefLen)) + if (strncasecmp(fileSystems[i].prefix.c_str(), realpath.c_str(), prefLen) == 0) { outpath = realpath.substr(prefLen); *system = fileSystems[i].system; diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index db8233343b..0e1c599a68 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -64,10 +64,6 @@ bool Load_PSP_ISO(const char *filename, std::string *error_string) pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); - pspFileSystem.Mount("UMD0:", umd2); - pspFileSystem.Mount("UMD1:", umd2); - pspFileSystem.Mount("DISC0:", umd2); - pspFileSystem.Mount("UMD:", umd2); std::string sfoPath("disc0:/PSP_GAME/PARAM.SFO"); PSPFileInfo fileInfo = pspFileSystem.GetFileInfo(sfoPath.c_str()); @@ -124,9 +120,6 @@ bool Load_PSP_ELF_PBP(const char *filename, std::string *error_string) pspFileSystem.Mount("umd1:", umd2); pspFileSystem.Mount("disc0:", umd2); pspFileSystem.Mount("umd:", umd2); - pspFileSystem.Mount("UMD1:", umd2); - pspFileSystem.Mount("DISC0:", umd2); - pspFileSystem.Mount("UMD:", umd2); } std::string full_path = filename; From d26bebc685472e3d5d6ad4e8941fe6b097b7cbf3 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 9 Jan 2013 01:13:38 -0800 Subject: [PATCH 5/5] Return an error if the raw lbn is too high. --- Core/FileSystems/ISOFileSystem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 8796c74bc5..2a2403cff5 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -337,6 +337,12 @@ u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access) { u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF; parseLBN(filename, §orStart, &readSize); + if (sectorStart >= blockDevice->GetNumBlocks()) + { + WARN_LOG(FILESYS, "Unable to open raw sector: %s, sector %08x, max %08x", filename.c_str(), sectorStart, blockDevice->GetNumBlocks()); + return 0; + } + INFO_LOG(FILESYS, "Got a raw sector open: %s, sector %08x, size %08x", filename.c_str(), sectorStart, readSize); u32 newHandle = hAlloc->GetNewHandle(); entry.seekPos = 0;