PSPFileInfo ISOFileSystem::GetFileInfo(std::string filename) { if (filename.compare(0,8,"/sce_lbn") == 0) { u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF; parseLBN(filename, §orStart, &readSize); PSPFileInfo fileInfo; fileInfo.name = filename; fileInfo.exists = true; fileInfo.size = readSize; fileInfo.startSector = sectorStart; fileInfo.isOnSectorSystem = true; fileInfo.numSectors = (readSize + sectorSize - 1) / sectorSize; return fileInfo; } TreeEntry *entry = GetFromPath(filename, false); PSPFileInfo x; if (!entry) { x.size = 0; x.exists = false; } else { x.name = entry->name; x.access = FILEACCESS_READ; x.size = entry->size; x.exists = true; x.type = entry->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.isOnSectorSystem = true; x.startSector = entry->startingPosition / 2048; } return x; }
std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) { std::vector<PSPFileInfo> myVector; TreeEntry *entry = GetFromPath(path); if (!entry) { return myVector; } for (size_t i=0; i<entry->children.size(); i++) { TreeEntry *e = entry->children[i]; if(!strcmp(e->name.c_str(), ".") || !strcmp(e->name.c_str(), "..")) // do not include the relative entries in the list continue; PSPFileInfo x; x.name = e->name; x.access = FILEACCESS_READ; x.size = e->size; x.type = e->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.isOnSectorSystem = true; x.startSector = e->startingPosition/2048; myVector.push_back(x); } return myVector; }
std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) { std::vector<PSPFileInfo> myVector; TreeEntry *entry = GetFromPath(path); if (!entry) return myVector; const std::string dot("."); const std::string dotdot(".."); for (size_t i = 0; i < entry->children.size(); i++) { TreeEntry *e = entry->children[i]; // do not include the relative entries in the list if (e->name == dot || e->name == dotdot) continue; PSPFileInfo x; x.name = e->name; x.access = FILEACCESS_READ; x.size = e->size; x.type = e->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.isOnSectorSystem = true; x.startSector = e->startingPosition/2048; x.sectorSize = sectorSize; x.numSectors = (e->size + sectorSize - 1) / sectorSize; memset(&x.atime, 0, sizeof(x.atime)); memset(&x.mtime, 0, sizeof(x.mtime)); memset(&x.ctime, 0, sizeof(x.ctime)); myVector.push_back(x); } return myVector; }
std::vector<PSPFileInfo> ISOFileSystem::GetDirListing(std::string path) { std::vector<PSPFileInfo> myVector; TreeEntry *entry = GetFromPath(path); if (!entry) { return myVector; } // fake the . and .. PSPFileInfo x; x.type = FILETYPE_DIRECTORY; x.name = "."; x.isOnSectorSystem = true; myVector.push_back(x); x.name = ".."; myVector.push_back(x); for (size_t i=0; i<entry->children.size(); i++) { TreeEntry *e = entry->children[i]; PSPFileInfo x; x.name = e->name; x.access = FILEACCESS_READ; x.size = e->size; x.type = e->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.isOnSectorSystem = true; x.startSector = entry->startingPosition/2048; myVector.push_back(x); } return myVector; }
void ISOFileSystem::DoState(PointerWrap &p) { auto s = p.Section("ISOFileSystem", 1); if (!s) return; int n = (int) entries.size(); p.Do(n); if (p.mode == p.MODE_READ) { entries.clear(); for (int i = 0; i < n; ++i) { u32 fd = 0; OpenFileEntry of; p.Do(fd); p.Do(of.seekPos); p.Do(of.isRawSector); p.Do(of.isBlockSectorMode); p.Do(of.sectorStart); p.Do(of.openSize); bool hasFile = false; p.Do(hasFile); if (hasFile) { std::string path; p.Do(path); of.file = GetFromPath(path); } else { of.file = NULL; } entries[fd] = of; } } else { for (EntryMap::iterator it = entries.begin(), end = entries.end(); it != end; ++it) { OpenFileEntry &of = it->second; p.Do(it->first); p.Do(of.seekPos); p.Do(of.isRawSector); p.Do(of.isBlockSectorMode); p.Do(of.sectorStart); p.Do(of.openSize); bool hasFile = of.file != NULL; p.Do(hasFile); if (hasFile) { std::string path = ""; path = EntryFullPath(of.file); p.Do(path); } } } }
u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { OpenFileEntry entry; entry.isRawSector = false; entry.isBlockSectorMode = false; if (filename.compare(0, 8, "/sce_lbn") == 0) { // Raw sector read. u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF; parseLBN(filename, §orStart, &readSize); if (sectorStart > blockDevice->GetNumBlocks()) { WARN_LOG(FILESYS, "Unable to open raw sector, out of range: %s, sector %08x, max %08x", filename.c_str(), sectorStart, blockDevice->GetNumBlocks()); return 0; } else if (sectorStart == blockDevice->GetNumBlocks()) { ERROR_LOG(FILESYS, "Should not be able to open the block after the last on disc! %08x", sectorStart); } DEBUG_LOG(FILESYS, "Got a raw sector open: %s, sector %08x, size %08x", filename.c_str(), sectorStart, readSize); u32 newHandle = hAlloc->GetNewHandle(); entry.seekPos = 0; entry.file = 0; entry.isRawSector = true; entry.sectorStart = sectorStart; entry.openSize = readSize; // when open as "umd1:/sce_lbn0x0_size0x6B49D200", that mean open umd1 as a block device. // the param in sceIoLseek and sceIoRead is lba mode. we must mark it. if (strncmp(devicename, "umd0:", 5)==0 || strncmp(devicename, "umd1:", 5)==0) entry.isBlockSectorMode = true; entries[newHandle] = entry; return newHandle; } if (access & FILEACCESS_WRITE) { ERROR_LOG(FILESYS, "Can't open file %s with write access on an ISO partition", filename.c_str()); return 0; } // May return entireISO for "umd0:" entry.file = GetFromPath(filename); if (!entry.file){ return 0; } if (entry.file == &entireISO) entry.isBlockSectorMode = true; entry.seekPos = 0; u32 newHandle = hAlloc->GetNewHandle(); entries[newHandle] = entry; return newHandle; }
u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access) { // LBN unittest /* u32 a, b; if (parseLBN("/sce_lbn0x307aa_size0xefffe000", &a, &b)) { ERROR_LOG(FILESYS, "lbn: %08x %08x", a, b); } else { ERROR_LOG(FILESYS, "faillbn: %08x %08x", a, b); }*/ OpenFileEntry entry; if (filename.compare(0,8,"/sce_lbn") == 0) { 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; entry.file = 0; entry.isRawSector = true; entry.sectorStart = sectorStart; entry.openSize = readSize; entries[newHandle] = entry; return newHandle; } entry.isRawSector = false; if (access & FILEACCESS_WRITE) { ERROR_LOG(FILESYS, "Can't open file %s with write access on an ISO partition", filename.c_str()); return 0; } // May return entireISO for "umd0:" entry.file = GetFromPath(filename); if (!entry.file) return 0; entry.seekPos = 0; u32 newHandle = hAlloc->GetNewHandle(); entries[newHandle] = entry; return newHandle; }
PSPFileInfo ISOFileSystem::GetFileInfo(std::string filename) { TreeEntry *entry = GetFromPath(filename); PSPFileInfo x; if (!entry) { x.size=0; } else { x.name = entry->name; x.access = FILEACCESS_READ; x.size = entry->size; x.type = entry->isDirectory ? FILETYPE_DIRECTORY : FILETYPE_NORMAL; x.isOnSectorSystem = true; x.startSector = entry->startingPosition/2048; } return x; }
u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access) { OpenFileEntry entry; if (filename.compare(0,8,"/sce_lbn") == 0) { std::string yo = filename; filename.erase(0,10); u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF; sscanf(filename.c_str(), "%08x", §orStart); filename.erase(0,filename.find('_') + 5); sscanf(filename.c_str(), "%08x", &readSize); INFO_LOG(FILESYS, "Got a raw sector read %s, sector %08x, size %08x", yo.c_str(), sectorStart, readSize); u32 newHandle = hAlloc->GetNewHandle(); entry.seekPos = 0; entry.file = 0; entry.isRawSector = true; entry.sectorStart = sectorStart; entry.openSize = readSize; entries[newHandle] = entry; return newHandle; } entry.isRawSector = false; if (access & FILEACCESS_WRITE) { ERROR_LOG(FILESYS, "Can't open file %s with write access on an ISO partition", filename.c_str()); return 0; } // May return entireISO for "umd0:" entry.file = GetFromPath(filename); if (!entry.file) return 0; entry.seekPos = 0; u32 newHandle = hAlloc->GetNewHandle(); entries[newHandle] = entry; return newHandle; }
void ISOFileSystem::DoState(PointerWrap &p) { int n = (int) entries.size(); p.Do(n); if (p.mode == p.MODE_READ) { entries.clear(); for (int i = 0; i < n; ++i) { u32 fd; p.Do(fd); std::string path; p.Do(path); OpenFileEntry of; of.file = path.empty() ? NULL : GetFromPath(path); p.Do(of.seekPos); p.Do(of.isRawSector); p.Do(of.sectorStart); p.Do(of.openSize); entries[fd] = of; } } else { for (EntryMap::iterator it = entries.begin(), end = entries.end(); it != end; ++it) { p.Do(it->first); std::string path = ""; if (it->second.file != NULL) path = EntryFullPath(it->second.file); p.Do(path); p.Do(it->second.seekPos); p.Do(it->second.isRawSector); p.Do(it->second.sectorStart); p.Do(it->second.openSize); } } p.DoMarker("ISOFileSystem"); }
bool CRenameCommand::valid() const { return !GetFromPath().empty() && !GetToPath().empty() && !GetFromFile().empty() && !GetToFile().empty(); }