1
// Copyright (c) 2012- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
23
#include "base/mutex.h"
24
#include "Core/FileSystems/FileSystem.h"
26
class MetaFileSystem : public IHandleAllocator, public IFileSystem {
33
bool operator == (const MountPoint &other) const {
34
return prefix == other.prefix && system == other.system;
38
std::vector<MountPoint> fileSystems;
40
typedef std::map<int, std::string> currentDir_t;
41
currentDir_t currentDir;
43
std::string startingDirectory;
52
void Mount(std::string prefix, IFileSystem *system);
53
void Unmount(std::string prefix, IFileSystem *system);
54
void Remount(IFileSystem *oldSystem, IFileSystem *newSystem);
56
IFileSystem *GetSystem(const std::string &prefix);
57
IFileSystem *GetSystemFromFilename(const std::string &filename);
59
void ThreadEnded(int threadID);
63
u32 GetNewHandle() override {
70
void FreeHandle(u32 handle) override {}
72
void DoState(PointerWrap &p) override;
74
IFileSystem *GetHandleOwner(u32 handle);
75
bool MapFilePath(const std::string &inpath, std::string &outpath, MountPoint **system);
77
inline bool MapFilePath(const std::string &_inpath, std::string &outpath, IFileSystem **system) {
78
MountPoint *mountPoint;
79
if (MapFilePath(_inpath, outpath, &mountPoint)) {
80
*system = mountPoint->system;
87
std::string NormalizePrefix(std::string prefix) const;
89
// Only possible if a file system is a DirectoryFileSystem or similar.
90
bool GetHostPath(const std::string &inpath, std::string &outpath) override;
92
std::vector<PSPFileInfo> GetDirListing(std::string path) override;
93
u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override;
94
u32 OpenWithError(int &error, std::string filename, FileAccess access, const char *devicename = NULL);
95
void CloseFile(u32 handle) override;
96
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
97
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
98
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
99
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
100
size_t SeekFile(u32 handle, s32 position, FileMove type) override;
101
PSPFileInfo GetFileInfo(std::string filename) override;
102
bool OwnsHandle(u32 handle) override { return false; }
103
inline size_t GetSeekPos(u32 handle)
105
return SeekFile(handle, 0, FILEMOVE_CURRENT);
108
virtual int ChDir(const std::string &dir);
110
bool MkDir(const std::string &dirname) override;
111
bool RmDir(const std::string &dirname) override;
112
int RenameFile(const std::string &from, const std::string &to) override;
113
bool RemoveFile(const std::string &filename) override;
114
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
115
int DevType(u32 handle) override;
116
int Flags() override { return 0; }
117
u64 FreeSpace(const std::string &path) override;
119
// Convenience helper - returns < 0 on failure.
120
int ReadEntireFile(const std::string &filename, std::vector<u8> &data);
122
void SetStartingDirectory(const std::string &dir) {
123
lock_guard guard(lock);
124
startingDirectory = dir;