summaryrefslogtreecommitdiff
path: root/src/core/file_sys/filesystem.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys/filesystem.h')
-rw-r--r--src/core/file_sys/filesystem.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h
new file mode 100644
index 000000000..02705506b
--- /dev/null
+++ b/src/core/file_sys/filesystem.h
@@ -0,0 +1,190 @@
1// Copyright 2018 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8#include <string>
9#include <utility>
10#include <vector>
11#include "common/bit_field.h"
12#include "common/common_types.h"
13#include "common/swap.h"
14#include "core/hle/result.h"
15
16namespace FileSys {
17
18class StorageBackend;
19class DirectoryBackend;
20
21// Path string type
22enum LowPathType : u32 {
23 Invalid = 0,
24 Empty = 1,
25 Binary = 2,
26 Char = 3,
27 Wchar = 4,
28};
29
30union Mode {
31 u32 hex;
32 BitField<0, 1, u32> read_flag;
33 BitField<1, 1, u32> write_flag;
34 BitField<2, 1, u32> create_flag;
35};
36
37class Path {
38public:
39 Path() : type(Invalid) {}
40 Path(const char* path) : type(Char), string(path) {}
41 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {}
42 Path(LowPathType type, u32 size, u32 pointer);
43
44 LowPathType GetType() const {
45 return type;
46 }
47
48 /**
49 * Gets the string representation of the path for debugging
50 * @return String representation of the path for debugging
51 */
52 std::string DebugStr() const;
53
54 std::string AsString() const;
55 std::u16string AsU16Str() const;
56 std::vector<u8> AsBinary() const;
57
58private:
59 LowPathType type;
60 std::vector<u8> binary;
61 std::string string;
62 std::u16string u16str;
63};
64
65/// Parameters of the archive, as specified in the Create or Format call.
66struct ArchiveFormatInfo {
67 u32_le total_size; ///< The pre-defined size of the archive.
68 u32_le number_directories; ///< The pre-defined number of directories in the archive.
69 u32_le number_files; ///< The pre-defined number of files in the archive.
70 u8 duplicate_data; ///< Whether the archive should duplicate the data.
71};
72static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD");
73
74class FileSystemBackend : NonCopyable {
75public:
76 virtual ~FileSystemBackend() {}
77
78 /**
79 * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
80 */
81 virtual std::string GetName() const = 0;
82
83 /**
84 * Create a file specified by its path
85 * @param path Path relative to the Archive
86 * @param size The size of the new file, filled with zeroes
87 * @return Result of the operation
88 */
89 virtual ResultCode CreateFile(const Path& path, u64 size) const = 0;
90
91 /**
92 * Delete a file specified by its path
93 * @param path Path relative to the archive
94 * @return Result of the operation
95 */
96 virtual ResultCode DeleteFile(const Path& path) const = 0;
97
98 /**
99 * Create a directory specified by its path
100 * @param path Path relative to the archive
101 * @return Result of the operation
102 */
103 virtual ResultCode CreateDirectory(const Path& path) const = 0;
104
105 /**
106 * Delete a directory specified by its path
107 * @param path Path relative to the archive
108 * @return Result of the operation
109 */
110 virtual ResultCode DeleteDirectory(const Path& path) const = 0;
111
112 /**
113 * Delete a directory specified by its path and anything under it
114 * @param path Path relative to the archive
115 * @return Result of the operation
116 */
117 virtual ResultCode DeleteDirectoryRecursively(const Path& path) const = 0;
118
119 /**
120 * Rename a File specified by its path
121 * @param src_path Source path relative to the archive
122 * @param dest_path Destination path relative to the archive
123 * @return Result of the operation
124 */
125 virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0;
126
127 /**
128 * Rename a Directory specified by its path
129 * @param src_path Source path relative to the archive
130 * @param dest_path Destination path relative to the archive
131 * @return Result of the operation
132 */
133 virtual ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
134
135 /**
136 * Open a file specified by its path, using the specified mode
137 * @param path Path relative to the archive
138 * @param mode Mode to open the file with
139 * @return Opened file, or error code
140 */
141 virtual ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const Path& path,
142 const Mode& mode) const = 0;
143
144 /**
145 * Open a directory specified by its path
146 * @param path Path relative to the archive
147 * @return Opened directory, or error code
148 */
149 virtual ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const = 0;
150
151 /**
152 * Get the free space
153 * @return The number of free bytes in the archive
154 */
155 virtual u64 GetFreeSpaceSize() const = 0;
156};
157
158class FileSystemFactory : NonCopyable {
159public:
160 virtual ~FileSystemFactory() {}
161
162 /**
163 * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
164 */
165 virtual std::string GetName() const = 0;
166
167 /**
168 * Tries to open the archive of this type with the specified path
169 * @param path Path to the archive
170 * @return An ArchiveBackend corresponding operating specified archive path.
171 */
172 virtual ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) = 0;
173
174 /**
175 * Deletes the archive contents and then re-creates the base folder
176 * @param path Path to the archive
177 * @param format_info Format information for the new archive
178 * @return ResultCode of the operation, 0 on success
179 */
180 virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) = 0;
181
182 /**
183 * Retrieves the format info about the archive with the specified path
184 * @param path Path to the archive
185 * @return Format information about the archive or error code
186 */
187 virtual ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const = 0;
188};
189
190} // namespace FileSys