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
BlobFileSystem(IHandleAllocator * hAlloc,FileLoader * fileLoader,std::string alias)21 BlobFileSystem::BlobFileSystem(IHandleAllocator *hAlloc, FileLoader *fileLoader, std::string alias)
22 : alloc_(hAlloc), fileLoader_(fileLoader), alias_(alias) {
23 }
24
~BlobFileSystem()25 BlobFileSystem::~BlobFileSystem() {
26 // TODO: Who deletes fileLoader?
27 }
28
DoState(PointerWrap & p)29 void BlobFileSystem::DoState(PointerWrap &p) {
30 // Not used in real emulation.
31 }
32
GetDirListing(std::string path)33 std::vector<PSPFileInfo> BlobFileSystem::GetDirListing(std::string path) {
34 std::vector<PSPFileInfo> listing;
35 listing.push_back(GetFileInfo(alias_));
36 return listing;
37 }
38
OpenFile(std::string filename,FileAccess access,const char * devicename)39 int BlobFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) {
40 u32 newHandle = alloc_->GetNewHandle();
41 entries_[newHandle] = 0;
42 return newHandle;
43 }
44
CloseFile(u32 handle)45 void BlobFileSystem::CloseFile(u32 handle) {
46 alloc_->FreeHandle(handle);
47 entries_.erase(handle);
48 }
49
ReadFile(u32 handle,u8 * pointer,s64 size)50 size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
51 auto entry = entries_.find(handle);
52 if (entry != entries_.end()) {
53 s64 readSize = (s64)fileLoader_->ReadAt(entry->second, (size_t)size, pointer);
54 entry->second += readSize;
55 return (size_t)readSize;
56 }
57 return 0;
58 }
59
ReadFile(u32 handle,u8 * pointer,s64 size,int & usec)60 size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) {
61 usec = 0;
62 return ReadFile(handle, pointer, size);
63 }
64
WriteFile(u32 handle,const u8 * pointer,s64 size)65 size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
66 return 0;
67 }
68
WriteFile(u32 handle,const u8 * pointer,s64 size,int & usec)69 size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) {
70 return 0;
71 }
72
SeekFile(u32 handle,s32 position,FileMove type)73 size_t BlobFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
74 auto entry = entries_.find(handle);
75 if (entry != entries_.end()) {
76 switch (type) {
77 case FILEMOVE_BEGIN:
78 entry->second = position;
79 break;
80 case FILEMOVE_CURRENT:
81 entry->second += position;
82 break;
83 case FILEMOVE_END:
84 entry->second = fileLoader_->FileSize() + position;
85 break;
86 }
87 return (size_t)entry->second;
88 }
89 return 0;
90 }
91
GetFileInfo(std::string filename)92 PSPFileInfo BlobFileSystem::GetFileInfo(std::string filename) {
93 PSPFileInfo info{};
94 info.name = alias_;
95 info.size = fileLoader_->FileSize();
96 info.access = 0666;
97 info.exists = true;
98 info.type = FILETYPE_NORMAL;
99 return info;
100 }
101
OwnsHandle(u32 handle)102 bool BlobFileSystem::OwnsHandle(u32 handle) {
103 auto entry = entries_.find(handle);
104 return entry != entries_.end();
105 }
106
Ioctl(u32 handle,u32 cmd,u32 indataPtr,u32 inlen,u32 outdataPtr,u32 outlen,int & usec)107 int BlobFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) {
108 return -1;
109 }
110
DevType(u32 handle)111 PSPDevType BlobFileSystem::DevType(u32 handle) {
112 return PSPDevType::FILE;
113 }
114
MkDir(const std::string & dirname)115 bool BlobFileSystem::MkDir(const std::string &dirname) {
116 return false;
117 }
118
RmDir(const std::string & dirname)119 bool BlobFileSystem::RmDir(const std::string &dirname) {
120 return false;
121 }
122
RenameFile(const std::string & from,const std::string & to)123 int BlobFileSystem::RenameFile(const std::string &from, const std::string &to) {
124 return -1;
125 }
126
RemoveFile(const std::string & filename)127 bool BlobFileSystem::RemoveFile(const std::string &filename) {
128 return false;
129 }
130
FreeSpace(const std::string & path)131 u64 BlobFileSystem::FreeSpace(const std::string &path) {
132 return 0;
133 }
134