CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/FileSystems/BlobFileSystem.cpp
Views: 1401
// Copyright (c) 2017- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <ctime>18#include "Core/FileSystems/BlobFileSystem.h"1920BlobFileSystem::BlobFileSystem(IHandleAllocator *hAlloc, FileLoader *fileLoader, std::string alias)21: alloc_(hAlloc), fileLoader_(fileLoader), alias_(alias) {22}2324BlobFileSystem::~BlobFileSystem() {25// TODO: Who deletes fileLoader?26}2728void BlobFileSystem::DoState(PointerWrap &p) {29// Not used in real emulation.30}3132std::vector<PSPFileInfo> BlobFileSystem::GetDirListing(const std::string &path, bool *exists) {33std::vector<PSPFileInfo> listing;34listing.push_back(GetFileInfo(alias_));35if (exists)36*exists = true;37return listing;38}3940int BlobFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) {41u32 newHandle = alloc_->GetNewHandle();42entries_[newHandle] = 0;43return newHandle;44}4546void BlobFileSystem::CloseFile(u32 handle) {47alloc_->FreeHandle(handle);48entries_.erase(handle);49}5051size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {52auto entry = entries_.find(handle);53if (entry != entries_.end()) {54s64 readSize = (s64)fileLoader_->ReadAt(entry->second, (size_t)size, pointer);55entry->second += readSize;56return (size_t)readSize;57}58return 0;59}6061size_t BlobFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) {62usec = 0;63return ReadFile(handle, pointer, size);64}6566size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {67return 0;68}6970size_t BlobFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) {71return 0;72}7374size_t BlobFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {75auto entry = entries_.find(handle);76if (entry != entries_.end()) {77switch (type) {78case FILEMOVE_BEGIN:79entry->second = position;80break;81case FILEMOVE_CURRENT:82entry->second += position;83break;84case FILEMOVE_END:85entry->second = fileLoader_->FileSize() + position;86break;87}88return (size_t)entry->second;89}90return 0;91}9293PSPFileInfo BlobFileSystem::GetFileInfo(std::string filename) {94PSPFileInfo info{};95info.name = alias_;96info.size = fileLoader_->FileSize();97info.access = 0666;98info.exists = true;99info.type = FILETYPE_NORMAL;100return info;101}102103bool BlobFileSystem::OwnsHandle(u32 handle) {104auto entry = entries_.find(handle);105return entry != entries_.end();106}107108int BlobFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) {109return -1;110}111112PSPDevType BlobFileSystem::DevType(u32 handle) {113return PSPDevType::FILE;114}115116bool BlobFileSystem::MkDir(const std::string &dirname) {117return false;118}119120bool BlobFileSystem::RmDir(const std::string &dirname) {121return false;122}123124int BlobFileSystem::RenameFile(const std::string &from, const std::string &to) {125return -1;126}127128bool BlobFileSystem::RemoveFile(const std::string &filename) {129return false;130}131132u64 BlobFileSystem::FreeSpace(const std::string &path) {133return 0;134}135136137