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 "FileSystem.h"
25
#include "BlockDevices.h"
27
bool parseLBN(std::string filename, u32 *sectorStart, u32 *readSize);
29
class ISOFileSystem : public IFileSystem {
31
ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);
34
void DoState(PointerWrap &p) override;
35
std::vector<PSPFileInfo> GetDirListing(std::string path) override;
36
u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override;
37
void CloseFile(u32 handle) override;
38
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
39
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
40
size_t SeekFile(u32 handle, s32 position, FileMove type) override;
41
PSPFileInfo GetFileInfo(std::string filename) override;
42
bool OwnsHandle(u32 handle) override;
43
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
44
int DevType(u32 handle) override;
45
int Flags() override { return 0; }
46
u64 FreeSpace(const std::string &path) override { return 0; }
48
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
49
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
51
bool GetHostPath(const std::string &inpath, std::string &outpath) override {return false;}
52
bool MkDir(const std::string &dirname) override {return false;}
53
bool RmDir(const std::string &dirname) override { return false; }
54
int RenameFile(const std::string &from, const std::string &to) override { return -1; }
55
bool RemoveFile(const std::string &filename) override { return false; }
59
TreeEntry() : flags(0), valid(false) {}
74
std::vector<TreeEntry *> children;
77
struct OpenFileEntry {
79
unsigned int seekPos; // TODO: Make 64-bit?
80
bool isRawSector; // "/sce_lbn" mode
81
bool isBlockSectorMode; // "umd:" mode: all sizes and offsets are in 2048 byte chunks
86
typedef std::map<u32,OpenFileEntry> EntryMap;
88
IHandleAllocator *hAlloc;
90
BlockDevice *blockDevice;
95
void ReadDirectory(TreeEntry *root);
96
TreeEntry *GetFromPath(const std::string &path, bool catchError = true);
97
std::string EntryFullPath(TreeEntry *e);
100
// On the "umd0:" device, any file you open is the entire ISO.
101
// Simply wrap around an ISOFileSystem which has all the necessary machinery, while changing
102
// the filenames to "", to achieve this.
103
class ISOBlockSystem : public IFileSystem {
105
ISOBlockSystem(ISOFileSystem *isoFileSystem) : isoFileSystem_(isoFileSystem) {}
107
void DoState(PointerWrap &p) override {
108
// This is a bit iffy, as block device savestates already are iffy (loads/saves multiple times for multiple mounts..)
109
isoFileSystem_->DoState(p);
112
std::vector<PSPFileInfo> GetDirListing(std::string path) override { return std::vector<PSPFileInfo>(); }
113
u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override {
114
return isoFileSystem_->OpenFile("", access, devicename);
116
void CloseFile(u32 handle) override {
117
isoFileSystem_->CloseFile(handle);
119
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override {
120
return isoFileSystem_->ReadFile(handle, pointer, size);
122
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {
123
return isoFileSystem_->ReadFile(handle, pointer, size, usec);
125
size_t SeekFile(u32 handle, s32 position, FileMove type) override {
126
return isoFileSystem_->SeekFile(handle, position, type);
128
PSPFileInfo GetFileInfo(std::string filename) override {
129
return isoFileSystem_->GetFileInfo("");
131
bool OwnsHandle(u32 handle) override {
132
return isoFileSystem_->OwnsHandle(handle);
134
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override {
135
return isoFileSystem_->Ioctl(handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
137
int DevType(u32 handle) override {
138
return isoFileSystem_->DevType(handle);
140
int Flags() override { return isoFileSystem_->Flags(); }
141
u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
143
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
144
return isoFileSystem_->WriteFile(handle, pointer, size);
146
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {
147
return isoFileSystem_->WriteFile(handle, pointer, size, usec);
149
bool GetHostPath(const std::string &inpath, std::string &outpath) override { return false; }
150
bool MkDir(const std::string &dirname) override { return false; }
151
bool RmDir(const std::string &dirname) override { return false; }
152
int RenameFile(const std::string &from, const std::string &to) override { return -1; }
153
bool RemoveFile(const std::string &filename) override { return false; }
156
ISOFileSystem *isoFileSystem_;