CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/FileSystems/ISOFileSystem.h
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <map>20#include <list>21#include <memory>2223#include "FileSystem.h"2425#include "BlockDevices.h"2627bool parseLBN(const std::string &filename, u32 *sectorStart, u32 *readSize);2829class ISOFileSystem : public IFileSystem {30public:31ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);32~ISOFileSystem();3334void DoState(PointerWrap &p) override;35std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;36int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;37void CloseFile(u32 handle) override;38size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;39size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;40size_t SeekFile(u32 handle, s32 position, FileMove type) override;41PSPFileInfo GetFileInfo(std::string filename) override;42bool OwnsHandle(u32 handle) override;43int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;44PSPDevType DevType(u32 handle) override;45FileSystemFlags Flags() override;46u64 FreeSpace(const std::string &path) override { return 0; }4748size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;49size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;5051bool MkDir(const std::string &dirname) override {return false;}52bool RmDir(const std::string &dirname) override { return false; }53int RenameFile(const std::string &from, const std::string &to) override { return -1; }54bool RemoveFile(const std::string &filename) override { return false; }5556bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }5758private:59struct TreeEntry {60~TreeEntry();6162// Recursive function that reconstructs the path by looking at the parent pointers.63std::string BuildPath();6465std::string name;66u32 flags = 0;67u32 startingPosition = 0;68s64 size = 0;69bool isDirectory = false;7071u32 startsector = 0;72u32 dirsize = 0;7374TreeEntry *parent = nullptr;7576bool valid = false;77std::vector<TreeEntry *> children;78};7980struct OpenFileEntry {81TreeEntry *file;82unsigned int seekPos; // TODO: Make 64-bit?83bool isRawSector; // "/sce_lbn" mode84bool isBlockSectorMode; // "umd:" mode: all sizes and offsets are in 2048 byte chunks85u32 sectorStart;86u32 openSize;87};8889typedef std::map<u32, OpenFileEntry> EntryMap;90EntryMap entries;91IHandleAllocator *hAlloc;92TreeEntry *treeroot;93BlockDevice *blockDevice;94u32 lastReadBlock_;9596TreeEntry entireISO;9798void ReadDirectory(TreeEntry *root);99TreeEntry *GetFromPath(const std::string &path, bool catchError = true);100std::string EntryFullPath(TreeEntry *e);101};102103// On the "umd0:" device, any file you open is the entire ISO.104// Simply wrap around an ISOFileSystem which has all the necessary machinery, while changing105// the filenames to "", to achieve this.106class ISOBlockSystem : public IFileSystem {107public:108ISOBlockSystem(std::shared_ptr<IFileSystem> isoFileSystem) : isoFileSystem_(isoFileSystem) {}109110void DoState(PointerWrap &p) override {111// This is a bit iffy, as block device savestates already are iffy (loads/saves multiple times for multiple mounts..)112isoFileSystem_->DoState(p);113}114115std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override {116if (exists)117*exists = true;118return std::vector<PSPFileInfo>();119}120int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override {121return isoFileSystem_->OpenFile("", access, devicename);122}123void CloseFile(u32 handle) override {124isoFileSystem_->CloseFile(handle);125}126size_t ReadFile(u32 handle, u8 *pointer, s64 size) override {127return isoFileSystem_->ReadFile(handle, pointer, size);128}129size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {130return isoFileSystem_->ReadFile(handle, pointer, size, usec);131}132size_t SeekFile(u32 handle, s32 position, FileMove type) override {133return isoFileSystem_->SeekFile(handle, position, type);134}135PSPFileInfo GetFileInfo(std::string filename) override {136return isoFileSystem_->GetFileInfo("");137}138bool OwnsHandle(u32 handle) override {139return isoFileSystem_->OwnsHandle(handle);140}141int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override {142return isoFileSystem_->Ioctl(handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);143}144PSPDevType DevType(u32 handle) override {145return isoFileSystem_->DevType(handle);146}147FileSystemFlags Flags() override { return isoFileSystem_->Flags(); }148u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }149150size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {151return isoFileSystem_->WriteFile(handle, pointer, size);152}153size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {154return isoFileSystem_->WriteFile(handle, pointer, size, usec);155}156bool MkDir(const std::string &dirname) override { return false; }157bool RmDir(const std::string &dirname) override { return false; }158int RenameFile(const std::string &from, const std::string &to) override { return -1; }159bool RemoveFile(const std::string &filename) override { return false; }160161bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }162163private:164std::shared_ptr<IFileSystem> isoFileSystem_;165};166167168