2012-11-01 16:19:01 +01:00
|
|
|
// 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
|
2012-11-04 23:01:49 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
// 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>
|
2013-03-31 20:58:24 -07:00
|
|
|
#include <list>
|
2021-07-24 10:31:15 +02:00
|
|
|
#include <memory>
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
#include "FileSystem.h"
|
|
|
|
|
|
|
|
#include "BlockDevices.h"
|
|
|
|
|
2013-07-23 17:24:33 +02:00
|
|
|
bool parseLBN(std::string filename, u32 *sectorStart, u32 *readSize);
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2015-09-17 20:29:37 +02:00
|
|
|
class ISOFileSystem : public IFileSystem {
|
2013-01-02 21:00:10 +01:00
|
|
|
public:
|
2016-02-29 01:13:57 +01:00
|
|
|
ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);
|
2013-01-02 21:00:10 +01:00
|
|
|
~ISOFileSystem();
|
2014-07-27 23:42:46 +02:00
|
|
|
|
|
|
|
void DoState(PointerWrap &p) override;
|
2022-10-09 09:08:18 -07:00
|
|
|
std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override;
|
2019-10-20 11:03:37 -07:00
|
|
|
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override;
|
2014-07-27 23:42:46 +02:00
|
|
|
void CloseFile(u32 handle) override;
|
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size) override;
|
2013-12-27 16:36:51 -08:00
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
|
2014-07-27 23:42:46 +02:00
|
|
|
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;
|
2020-05-21 17:57:41 -07:00
|
|
|
PSPDevType DevType(u32 handle) override;
|
2020-05-21 16:10:08 -07:00
|
|
|
FileSystemFlags Flags() override;
|
2014-10-31 23:48:08 -07:00
|
|
|
u64 FreeSpace(const std::string &path) override { return 0; }
|
2014-07-27 23:42:46 +02:00
|
|
|
|
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
|
2013-12-27 16:36:51 -08:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
|
|
|
|
|
2014-07-27 23:42:46 +02:00
|
|
|
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; }
|
2013-01-02 21:00:10 +01:00
|
|
|
|
2021-09-11 17:18:39 +02:00
|
|
|
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
|
|
|
|
|
2013-01-02 21:00:10 +01:00
|
|
|
private:
|
2015-09-17 20:29:37 +02:00
|
|
|
struct TreeEntry {
|
2014-07-27 23:42:46 +02:00
|
|
|
~TreeEntry();
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
std::string name;
|
2021-07-18 16:00:07 +02:00
|
|
|
u32 flags = 0;
|
|
|
|
u32 startingPosition = 0;
|
|
|
|
s64 size = 0;
|
|
|
|
bool isDirectory = false;
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2021-07-18 16:00:07 +02:00
|
|
|
u32 startsector = 0;
|
|
|
|
u32 dirsize = 0;
|
2016-02-28 11:46:21 +01:00
|
|
|
|
2021-07-18 16:00:07 +02:00
|
|
|
TreeEntry *parent = nullptr;
|
2016-02-28 11:51:15 +01:00
|
|
|
|
2021-07-18 16:00:07 +02:00
|
|
|
bool valid = false;
|
2015-09-07 17:39:17 -07:00
|
|
|
std::vector<TreeEntry *> children;
|
2012-11-01 16:19:01 +01:00
|
|
|
};
|
|
|
|
|
2015-09-17 20:29:37 +02:00
|
|
|
struct OpenFileEntry {
|
2012-11-01 16:19:01 +01:00
|
|
|
TreeEntry *file;
|
|
|
|
unsigned int seekPos; // TODO: Make 64-bit?
|
|
|
|
bool isRawSector; // "/sce_lbn" mode
|
2013-07-08 12:35:07 +08:00
|
|
|
bool isBlockSectorMode; // "umd:" mode: all sizes and offsets are in 2048 byte chunks
|
2012-11-01 16:19:01 +01:00
|
|
|
u32 sectorStart;
|
|
|
|
u32 openSize;
|
|
|
|
};
|
2015-09-17 20:29:37 +02:00
|
|
|
|
2012-11-01 16:19:01 +01:00
|
|
|
typedef std::map<u32,OpenFileEntry> EntryMap;
|
|
|
|
EntryMap entries;
|
|
|
|
IHandleAllocator *hAlloc;
|
|
|
|
TreeEntry *treeroot;
|
|
|
|
BlockDevice *blockDevice;
|
2013-12-27 16:49:35 -08:00
|
|
|
u32 lastReadBlock_;
|
2012-11-01 16:19:01 +01:00
|
|
|
|
|
|
|
TreeEntry entireISO;
|
|
|
|
|
2016-02-28 11:51:15 +01:00
|
|
|
void ReadDirectory(TreeEntry *root);
|
2015-09-07 18:43:10 -07:00
|
|
|
TreeEntry *GetFromPath(const std::string &path, bool catchError = true);
|
2012-12-27 22:14:31 -08:00
|
|
|
std::string EntryFullPath(TreeEntry *e);
|
2012-11-01 16:19:01 +01:00
|
|
|
};
|
2014-07-27 23:42:46 +02:00
|
|
|
|
|
|
|
// 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.
|
2014-07-28 00:00:54 +02:00
|
|
|
class ISOBlockSystem : public IFileSystem {
|
2014-07-27 23:42:46 +02:00
|
|
|
public:
|
2021-07-24 10:31:15 +02:00
|
|
|
ISOBlockSystem(std::shared_ptr<IFileSystem> isoFileSystem) : isoFileSystem_(isoFileSystem) {}
|
2014-07-27 23:42:46 +02:00
|
|
|
|
2014-07-28 00:00:54 +02:00
|
|
|
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);
|
|
|
|
}
|
2014-07-27 23:42:46 +02:00
|
|
|
|
2022-10-09 09:08:18 -07:00
|
|
|
std::vector<PSPFileInfo> GetDirListing(const std::string &path, bool *exists = nullptr) override {
|
|
|
|
if (exists)
|
|
|
|
*exists = true;
|
|
|
|
return std::vector<PSPFileInfo>();
|
|
|
|
}
|
2019-10-20 11:03:37 -07:00
|
|
|
int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override {
|
2014-07-27 23:42:46 +02:00
|
|
|
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);
|
|
|
|
}
|
2013-12-27 16:36:51 -08:00
|
|
|
size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {
|
|
|
|
return isoFileSystem_->ReadFile(handle, pointer, size, usec);
|
|
|
|
}
|
2014-07-27 23:42:46 +02:00
|
|
|
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);
|
|
|
|
}
|
2020-05-21 17:57:41 -07:00
|
|
|
PSPDevType DevType(u32 handle) override {
|
2014-07-27 23:42:46 +02:00
|
|
|
return isoFileSystem_->DevType(handle);
|
|
|
|
}
|
2020-05-21 15:55:25 -07:00
|
|
|
FileSystemFlags Flags() override { return isoFileSystem_->Flags(); }
|
2014-10-31 23:48:08 -07:00
|
|
|
u64 FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
|
2014-07-27 23:42:46 +02:00
|
|
|
|
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
|
|
|
|
return isoFileSystem_->WriteFile(handle, pointer, size);
|
|
|
|
}
|
2013-12-27 16:36:51 -08:00
|
|
|
size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {
|
|
|
|
return isoFileSystem_->WriteFile(handle, pointer, size, usec);
|
|
|
|
}
|
2014-07-27 23:42:46 +02:00
|
|
|
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; }
|
|
|
|
|
2021-09-11 17:18:39 +02:00
|
|
|
bool ComputeRecursiveDirSizeIfFast(const std::string &path, int64_t *size) override { return false; }
|
|
|
|
|
2014-07-27 23:42:46 +02:00
|
|
|
private:
|
2021-07-24 10:31:15 +02:00
|
|
|
std::shared_ptr<IFileSystem> isoFileSystem_;
|
2013-12-27 16:36:51 -08:00
|
|
|
};
|