forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISOFileSystem.h
166 lines (136 loc) · 6.11 KB
/
ISOFileSystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2012- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include <map>
#include <list>
#include <memory>
#include "FileSystem.h"
#include "BlockDevices.h"
bool parseLBN(const std::string &filename, u32 *sectorStart, u32 *readSize);
class ISOFileSystem : public IFileSystem {
public:
ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);
~ISOFileSystem();
void DoState(PointerWrap &p) override;
std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;
void CloseFile(u32 handle) override;
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
size_t SeekFile(u32 handle, s32 position, FileMove type) override;
PSPFileInfo GetFileInfo(std::string filename) override;
bool OwnsHandle(u32 handle) override;
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
PSPDevType DevType(u32 handle) override;
FileSystemFlags Flags() override;
u64 FreeSpace(const std::string &path) override { return 0; }
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
bool MkDir(const std::string &dirname) override {return false;}
bool RmDir(const std::string &dirname) override { return false; }
int RenameFile(const std::string &from, const std::string &to) override { return -1; }
bool RemoveFile(const std::string &filename) override { return false; }
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
private:
struct TreeEntry {
~TreeEntry();
// Recursive function that reconstructs the path by looking at the parent pointers.
std::string BuildPath();
std::string name;
u32 flags = 0;
u32 startingPosition = 0;
s64 size = 0;
bool isDirectory = false;
u32 startsector = 0;
u32 dirsize = 0;
TreeEntry *parent = nullptr;
bool valid = false;
std::vector<TreeEntry *> children;
};
struct OpenFileEntry {
TreeEntry *file;
unsigned int seekPos; // TODO: Make 64-bit?
bool isRawSector; // "/sce_lbn" mode
bool isBlockSectorMode; // "umd:" mode: all sizes and offsets are in 2048 byte chunks
u32 sectorStart;
u32 openSize;
};
typedef std::map<u32,OpenFileEntry> EntryMap;
EntryMap entries;
IHandleAllocator *hAlloc;
TreeEntry *treeroot;
BlockDevice *blockDevice;
u32 lastReadBlock_;
TreeEntry entireISO;
void ReadDirectory(TreeEntry *root);
TreeEntry *GetFromPath(const std::string &path, bool catchError = true);
std::string EntryFullPath(TreeEntry *e);
};
// On the "umd0:" device, any file you open is the entire ISO.
// Simply wrap around an ISOFileSystem which has all the necessary machinery, while changing
// the filenames to "", to achieve this.
class ISOBlockSystem : public IFileSystem {
public:
ISOBlockSystem(std::shared_ptr<IFileSystem> isoFileSystem) : isoFileSystem_(isoFileSystem) {}
void DoState(PointerWrap &p) override {
// This is a bit iffy, as block device savestates already are iffy (loads/saves multiple times for multiple mounts..)
isoFileSystem_->DoState(p);
}
std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override {
if (exists)
*exists = true;
return std::vector<PSPFileInfo>();
}
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override {
return isoFileSystem_->OpenFile("", access, devicename);
}
void CloseFile(u32 handle) override {
isoFileSystem_->CloseFile(handle);
}
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override {
return isoFileSystem_->ReadFile(handle, pointer, size);
}
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {
return isoFileSystem_->ReadFile(handle, pointer, size, usec);
}
size_t SeekFile(u32 handle, s32 position, FileMove type) override {
return isoFileSystem_->SeekFile(handle, position, type);
}
PSPFileInfo GetFileInfo(std::string filename) override {
return isoFileSystem_->GetFileInfo("");
}
bool OwnsHandle(u32 handle) override {
return isoFileSystem_->OwnsHandle(handle);
}
int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override {
return isoFileSystem_->Ioctl(handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
}
PSPDevType DevType(u32 handle) override {
return isoFileSystem_->DevType(handle);
}
FileSystemFlags Flags() override { return isoFileSystem_->Flags(); }
u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
return isoFileSystem_->WriteFile(handle, pointer, size);
}
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {
return isoFileSystem_->WriteFile(handle, pointer, size, usec);
}
bool MkDir(const std::string &dirname) override { return false; }
bool RmDir(const std::string &dirname) override { return false; }
int RenameFile(const std::string &from, const std::string &to) override { return -1; }
bool RemoveFile(const std::string &filename) override { return false; }
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
private:
std::shared_ptr<IFileSystem> isoFileSystem_;
};