CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/FileSystems/BlobFileSystem.cpp
Views: 1401
1
// Copyright (c) 2017- PPSSPP Project.
2
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.
6
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.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include <ctime>
19
#include "Core/FileSystems/BlobFileSystem.h"
20
21
BlobFileSystem::BlobFileSystem(IHandleAllocator *hAlloc, FileLoader *fileLoader, std::string alias)
22
: alloc_(hAlloc), fileLoader_(fileLoader), alias_(alias) {
23
}
24
25
BlobFileSystem::~BlobFileSystem() {
26
// TODO: Who deletes fileLoader?
27
}
28
29
void BlobFileSystem::DoState(PointerWrap &p) {
30
// Not used in real emulation.
31
}
32
33
std::vector<PSPFileInfo> BlobFileSystem::GetDirListing(const std::string &path, bool *exists) {
34
std::vector<PSPFileInfo> listing;
35
listing.push_back(GetFileInfo(alias_));
36
if (exists)
37
*exists = true;
38
return listing;
39
}
40
41
int BlobFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) {
42
u32 newHandle = alloc_->GetNewHandle();
43
entries_[newHandle] = 0;
44
return newHandle;
45
}
46
47
void BlobFileSystem::CloseFile(u32 handle) {
48
alloc_->FreeHandle(handle);
49
entries_.erase(handle);
50
}
51
52
size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
53
auto entry = entries_.find(handle);
54
if (entry != entries_.end()) {
55
s64 readSize = (s64)fileLoader_->ReadAt(entry->second, (size_t)size, pointer);
56
entry->second += readSize;
57
return (size_t)readSize;
58
}
59
return 0;
60
}
61
62
size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) {
63
usec = 0;
64
return ReadFile(handle, pointer, size);
65
}
66
67
size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
68
return 0;
69
}
70
71
size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) {
72
return 0;
73
}
74
75
size_t BlobFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
76
auto entry = entries_.find(handle);
77
if (entry != entries_.end()) {
78
switch (type) {
79
case FILEMOVE_BEGIN:
80
entry->second = position;
81
break;
82
case FILEMOVE_CURRENT:
83
entry->second += position;
84
break;
85
case FILEMOVE_END:
86
entry->second = fileLoader_->FileSize() + position;
87
break;
88
}
89
return (size_t)entry->second;
90
}
91
return 0;
92
}
93
94
PSPFileInfo BlobFileSystem::GetFileInfo(std::string filename) {
95
PSPFileInfo info{};
96
info.name = alias_;
97
info.size = fileLoader_->FileSize();
98
info.access = 0666;
99
info.exists = true;
100
info.type = FILETYPE_NORMAL;
101
return info;
102
}
103
104
bool BlobFileSystem::OwnsHandle(u32 handle) {
105
auto entry = entries_.find(handle);
106
return entry != entries_.end();
107
}
108
109
int BlobFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) {
110
return -1;
111
}
112
113
PSPDevType BlobFileSystem::DevType(u32 handle) {
114
return PSPDevType::FILE;
115
}
116
117
bool BlobFileSystem::MkDir(const std::string &dirname) {
118
return false;
119
}
120
121
bool BlobFileSystem::RmDir(const std::string &dirname) {
122
return false;
123
}
124
125
int BlobFileSystem::RenameFile(const std::string &from, const std::string &to) {
126
return -1;
127
}
128
129
bool BlobFileSystem::RemoveFile(const std::string &filename) {
130
return false;
131
}
132
133
u64 BlobFileSystem::FreeSpace(const std::string &path) {
134
return 0;
135
}
136
137