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/FileSystem.h
Views: 1401
// Copyright (c) 2012- 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#pragma once1819#include <vector>20#include <string>21#include <cstring>22#include <cstdint>23#include <ctime>2425#include "Common.h"26#include "Common/File/Path.h"27#include "Core/HLE/sceKernel.h"2829enum FileAccess {30FILEACCESS_NONE = 0,31FILEACCESS_READ = 1,32FILEACCESS_WRITE = 2,33FILEACCESS_APPEND = 4,34FILEACCESS_CREATE = 8,35FILEACCESS_TRUNCATE = 16,36FILEACCESS_EXCL = 32,3738FILEACCESS_PSP_FLAGS = 63, // Sum of all the above.3940// Non-PSP flags41FILEACCESS_PPSSPP_QUIET = 128,42};4344enum FileMove {45FILEMOVE_BEGIN = 0,46FILEMOVE_CURRENT = 1,47FILEMOVE_END = 248};4950enum FileType {51FILETYPE_NORMAL = 1,52FILETYPE_DIRECTORY = 253};5455enum class PSPDevType {56INVALID = 0,57BLOCK = 0x04,58FILE = 0x10,59ALIAS = 0x20,60EMU_MASK = 0xFF,61EMU_LBN = 0x10000,62};63ENUM_CLASS_BITOPS(PSPDevType);6465enum class FileSystemFlags {66NONE = 0,67SIMULATE_FAT32 = 1,68UMD = 2,69CARD = 4,70FLASH = 8,71STRIP_PSP = 16,72};73ENUM_CLASS_BITOPS(FileSystemFlags);7475class IHandleAllocator {76public:77virtual ~IHandleAllocator() {}78virtual u32 GetNewHandle() = 0;79virtual void FreeHandle(u32 handle) = 0;80};8182class SequentialHandleAllocator : public IHandleAllocator {83public:84SequentialHandleAllocator() : handle_(1) {}8586SequentialHandleAllocator(SequentialHandleAllocator &) = delete;87void operator =(SequentialHandleAllocator &) = delete;8889u32 GetNewHandle() override {90u32 res = handle_++;91if (handle_ < 0) {92// Some code assumes it'll never become 0.93handle_ = 1;94}95return res;96}97void FreeHandle(u32 handle) override {}98private:99int handle_;100};101102struct PSPFileInfo {103PSPFileInfo() {104}105106void DoState(PointerWrap &p);107108std::string name;109s64 size = 0;110u32 access = 0; //unix 777111bool exists = false;112FileType type = FILETYPE_NORMAL;113114tm atime{};115tm ctime{};116tm mtime{};117118bool isOnSectorSystem = false;119u32 startSector = 0;120u32 numSectors = 0;121u32 sectorSize = 0;122};123124125class IFileSystem {126public:127virtual ~IFileSystem() {}128129virtual void DoState(PointerWrap &p) = 0;130virtual std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) = 0;131virtual int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) = 0;132virtual void CloseFile(u32 handle) = 0;133virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size) = 0;134virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) = 0;135virtual size_t WriteFile(u32 handle, const u8 *pointer, s64 size) = 0;136virtual size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) = 0;137virtual size_t SeekFile(u32 handle, s32 position, FileMove type) = 0;138virtual PSPFileInfo GetFileInfo(std::string filename) = 0;139virtual bool OwnsHandle(u32 handle) = 0;140virtual bool MkDir(const std::string &dirname) = 0;141virtual bool RmDir(const std::string &dirname) = 0;142virtual int RenameFile(const std::string &from, const std::string &to) = 0;143virtual bool RemoveFile(const std::string &filename) = 0;144virtual int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) = 0;145virtual PSPDevType DevType(u32 handle) = 0;146virtual FileSystemFlags Flags() = 0;147virtual u64 FreeSpace(const std::string &path) = 0;148virtual bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) = 0;149};150151152class EmptyFileSystem : public IFileSystem {153public:154void DoState(PointerWrap &p) override {}155std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override {156if (exists)157*exists = false;158std::vector<PSPFileInfo> vec;159return vec;160}161int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override {return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND;}162void CloseFile(u32 handle) override {}163size_t ReadFile(u32 handle, u8 *pointer, s64 size) override {return 0;}164size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {return 0;}165size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {return 0;}166size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {return 0;}167size_t SeekFile(u32 handle, s32 position, FileMove type) override {return 0;}168PSPFileInfo GetFileInfo(std::string filename) override {PSPFileInfo f; return f;}169bool OwnsHandle(u32 handle) override {return false;}170bool MkDir(const std::string &dirname) override {return false;}171bool RmDir(const std::string &dirname) override {return false;}172int RenameFile(const std::string &from, const std::string &to) override {return -1;}173bool RemoveFile(const std::string &filename) override {return false;}174int Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override { return SCE_KERNEL_ERROR_ERRNO_FUNCTION_NOT_SUPPORTED; }175PSPDevType DevType(u32 handle) override { return PSPDevType::INVALID; }176FileSystemFlags Flags() override { return FileSystemFlags::NONE; }177u64 FreeSpace(const std::string &path) override { return 0; }178bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }179};180181182183184