~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Core/FileSystems/ISOFileSystem.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012- 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
#pragma once
 
19
 
 
20
#include <map>
 
21
#include <list>
 
22
 
 
23
#include "FileSystem.h"
 
24
 
 
25
#include "BlockDevices.h"
 
26
 
 
27
bool parseLBN(std::string filename, u32 *sectorStart, u32 *readSize);
 
28
 
 
29
class ISOFileSystem : public IFileSystem {
 
30
public:
 
31
        ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);
 
32
        ~ISOFileSystem();
 
33
 
 
34
        void DoState(PointerWrap &p) override;
 
35
        std::vector<PSPFileInfo> GetDirListing(std::string path) override;
 
36
        u32      OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override;
 
37
        void     CloseFile(u32 handle) override;
 
38
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size) override;
 
39
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override;
 
40
        size_t   SeekFile(u32 handle, s32 position, FileMove type) override;
 
41
        PSPFileInfo GetFileInfo(std::string filename) override;
 
42
        bool     OwnsHandle(u32 handle) override;
 
43
        int      Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override;
 
44
        int      DevType(u32 handle) override;
 
45
        int      Flags() override { return 0; }
 
46
        u64      FreeSpace(const std::string &path) override { return 0; }
 
47
 
 
48
        size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override;
 
49
        size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override;
 
50
 
 
51
        bool GetHostPath(const std::string &inpath, std::string &outpath) override {return false;}
 
52
        bool MkDir(const std::string &dirname) override {return false;}
 
53
        bool RmDir(const std::string &dirname) override { return false; }
 
54
        int  RenameFile(const std::string &from, const std::string &to) override { return -1; }
 
55
        bool RemoveFile(const std::string &filename) override { return false; }
 
56
 
 
57
private:
 
58
        struct TreeEntry {
 
59
                TreeEntry() : flags(0), valid(false) {}
 
60
                ~TreeEntry();
 
61
 
 
62
                std::string name;
 
63
                u32 flags;
 
64
                u32 startingPosition;
 
65
                s64 size;
 
66
                bool isDirectory;
 
67
 
 
68
                u32 startsector;
 
69
                u32 dirsize;
 
70
 
 
71
                TreeEntry *parent;
 
72
 
 
73
                bool valid;
 
74
                std::vector<TreeEntry *> children;
 
75
        };
 
76
 
 
77
        struct OpenFileEntry {
 
78
                TreeEntry *file;
 
79
                unsigned int seekPos;  // TODO: Make 64-bit?
 
80
                bool isRawSector;   // "/sce_lbn" mode
 
81
                bool isBlockSectorMode;  // "umd:" mode: all sizes and offsets are in 2048 byte chunks
 
82
                u32 sectorStart;
 
83
                u32 openSize;
 
84
        };
 
85
 
 
86
        typedef std::map<u32,OpenFileEntry> EntryMap;
 
87
        EntryMap entries;
 
88
        IHandleAllocator *hAlloc;
 
89
        TreeEntry *treeroot;
 
90
        BlockDevice *blockDevice;
 
91
        u32 lastReadBlock_;
 
92
 
 
93
        TreeEntry entireISO;
 
94
 
 
95
        void ReadDirectory(TreeEntry *root);
 
96
        TreeEntry *GetFromPath(const std::string &path, bool catchError = true);
 
97
        std::string EntryFullPath(TreeEntry *e);
 
98
};
 
99
 
 
100
// On the "umd0:" device, any file you open is the entire ISO.
 
101
// Simply wrap around an ISOFileSystem which has all the necessary machinery, while changing
 
102
// the filenames to "", to achieve this.
 
103
class ISOBlockSystem : public IFileSystem {
 
104
public:
 
105
        ISOBlockSystem(ISOFileSystem *isoFileSystem) : isoFileSystem_(isoFileSystem) {}
 
106
 
 
107
        void DoState(PointerWrap &p) override {
 
108
                // This is a bit iffy, as block device savestates already are iffy (loads/saves multiple times for multiple mounts..)
 
109
                isoFileSystem_->DoState(p);
 
110
        }
 
111
 
 
112
        std::vector<PSPFileInfo> GetDirListing(std::string path) override { return std::vector<PSPFileInfo>(); }
 
113
        u32      OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override {
 
114
                return isoFileSystem_->OpenFile("", access, devicename);
 
115
        }
 
116
        void     CloseFile(u32 handle) override {
 
117
                isoFileSystem_->CloseFile(handle);
 
118
        }
 
119
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size) override {
 
120
                return isoFileSystem_->ReadFile(handle, pointer, size);
 
121
        }
 
122
        size_t   ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {
 
123
                return isoFileSystem_->ReadFile(handle, pointer, size, usec);
 
124
        }
 
125
        size_t   SeekFile(u32 handle, s32 position, FileMove type) override {
 
126
                return isoFileSystem_->SeekFile(handle, position, type);
 
127
        }
 
128
        PSPFileInfo GetFileInfo(std::string filename) override {
 
129
                return isoFileSystem_->GetFileInfo("");
 
130
        }
 
131
        bool     OwnsHandle(u32 handle) override {
 
132
                return isoFileSystem_->OwnsHandle(handle);
 
133
        }
 
134
        int      Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outdataPtr, u32 outlen, int &usec) override {
 
135
                return isoFileSystem_->Ioctl(handle, cmd, indataPtr, inlen, outdataPtr, outlen, usec);
 
136
        }
 
137
        int      DevType(u32 handle) override {
 
138
                return isoFileSystem_->DevType(handle);
 
139
        }
 
140
        int      Flags() override { return isoFileSystem_->Flags(); }
 
141
        u64      FreeSpace(const std::string &path) override { return isoFileSystem_->FreeSpace(path); }
 
142
 
 
143
        size_t WriteFile(u32 handle, const u8 *pointer, s64 size) override {
 
144
                return isoFileSystem_->WriteFile(handle, pointer, size);
 
145
        }
 
146
        size_t WriteFile(u32 handle, const u8 *pointer, s64 size, int &usec) override {
 
147
                return isoFileSystem_->WriteFile(handle, pointer, size, usec);
 
148
        }
 
149
        bool GetHostPath(const std::string &inpath, std::string &outpath) override { return false; }
 
150
        bool MkDir(const std::string &dirname) override { return false; }
 
151
        bool RmDir(const std::string &dirname) override { return false; }
 
152
        int  RenameFile(const std::string &from, const std::string &to) override { return -1; }
 
153
        bool RemoveFile(const std::string &filename) override { return false; }
 
154
 
 
155
private:
 
156
        ISOFileSystem *isoFileSystem_;
 
157
};