summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.h28
-rw-r--r--src/core/file_sys/disk_archive.cpp50
-rw-r--r--src/core/file_sys/disk_archive.h14
-rw-r--r--src/core/file_sys/ivfc_archive.cpp31
-rw-r--r--src/core/file_sys/ivfc_archive.h14
5 files changed, 82 insertions, 55 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 06b8f2ed7..58f6c150c 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -87,7 +87,7 @@ public:
87 * @return Opened file, or error code 87 * @return Opened file, or error code
88 */ 88 */
89 virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, 89 virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
90 const Mode mode) const = 0; 90 const Mode& mode) const = 0;
91 91
92 /** 92 /**
93 * Delete a file specified by its path 93 * Delete a file specified by its path
@@ -100,53 +100,53 @@ public:
100 * Rename a File specified by its path 100 * Rename a File specified by its path
101 * @param src_path Source path relative to the archive 101 * @param src_path Source path relative to the archive
102 * @param dest_path Destination path relative to the archive 102 * @param dest_path Destination path relative to the archive
103 * @return Whether rename succeeded 103 * @return Result of the operation
104 */ 104 */
105 virtual bool RenameFile(const Path& src_path, const Path& dest_path) const = 0; 105 virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0;
106 106
107 /** 107 /**
108 * Delete a directory specified by its path 108 * Delete a directory specified by its path
109 * @param path Path relative to the archive 109 * @param path Path relative to the archive
110 * @return Whether the directory could be deleted 110 * @return Result of the operation
111 */ 111 */
112 virtual bool DeleteDirectory(const Path& path) const = 0; 112 virtual ResultCode DeleteDirectory(const Path& path) const = 0;
113 113
114 /** 114 /**
115 * Delete a directory specified by its path and anything under it 115 * Delete a directory specified by its path and anything under it
116 * @param path Path relative to the archive 116 * @param path Path relative to the archive
117 * @return Whether the directory could be deleted 117 * @return Result of the operation
118 */ 118 */
119 virtual bool DeleteDirectoryRecursively(const Path& path) const = 0; 119 virtual ResultCode DeleteDirectoryRecursively(const Path& path) const = 0;
120 120
121 /** 121 /**
122 * Create a file specified by its path 122 * Create a file specified by its path
123 * @param path Path relative to the Archive 123 * @param path Path relative to the Archive
124 * @param size The size of the new file, filled with zeroes 124 * @param size The size of the new file, filled with zeroes
125 * @return File creation result code 125 * @return Result of the operation
126 */ 126 */
127 virtual ResultCode CreateFile(const Path& path, u64 size) const = 0; 127 virtual ResultCode CreateFile(const Path& path, u64 size) const = 0;
128 128
129 /** 129 /**
130 * Create a directory specified by its path 130 * Create a directory specified by its path
131 * @param path Path relative to the archive 131 * @param path Path relative to the archive
132 * @return Whether the directory could be created 132 * @return Result of the operation
133 */ 133 */
134 virtual bool CreateDirectory(const Path& path) const = 0; 134 virtual ResultCode CreateDirectory(const Path& path) const = 0;
135 135
136 /** 136 /**
137 * Rename a Directory specified by its path 137 * Rename a Directory specified by its path
138 * @param src_path Source path relative to the archive 138 * @param src_path Source path relative to the archive
139 * @param dest_path Destination path relative to the archive 139 * @param dest_path Destination path relative to the archive
140 * @return Whether rename succeeded 140 * @return Result of the operation
141 */ 141 */
142 virtual bool RenameDirectory(const Path& src_path, const Path& dest_path) const = 0; 142 virtual ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
143 143
144 /** 144 /**
145 * Open a directory specified by its path 145 * Open a directory specified by its path
146 * @param path Path relative to the archive 146 * @param path Path relative to the archive
147 * @return Opened directory, or nullptr 147 * @return Opened directory, or error code
148 */ 148 */
149 virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0; 149 virtual ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const = 0;
150 150
151 /** 151 /**
152 * Get the free space 152 * Get the free space
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 2f05af361..ce6b9360b 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -16,7 +16,7 @@
16namespace FileSys { 16namespace FileSys {
17 17
18ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path, 18ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path,
19 const Mode mode) const { 19 const Mode& mode) const {
20 LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); 20 LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex);
21 auto file = std::make_unique<DiskFile>(*this, path, mode); 21 auto file = std::make_unique<DiskFile>(*this, path, mode);
22 ResultCode result = file->Open(); 22 ResultCode result = file->Open();
@@ -43,16 +43,28 @@ ResultCode DiskArchive::DeleteFile(const Path& path) const {
43 ErrorLevel::Status); 43 ErrorLevel::Status);
44} 44}
45 45
46bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { 46ResultCode DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
47 return FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()); 47 if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()))
48 return RESULT_SUCCESS;
49
50 // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
51 // exist or similar. Verify.
52 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
53 ErrorSummary::NothingHappened, ErrorLevel::Status);
48} 54}
49 55
50bool DiskArchive::DeleteDirectory(const Path& path) const { 56ResultCode DiskArchive::DeleteDirectory(const Path& path) const {
51 return FileUtil::DeleteDir(mount_point + path.AsString()); 57 if (FileUtil::DeleteDir(mount_point + path.AsString()))
58 return RESULT_SUCCESS;
59 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
60 ErrorSummary::Canceled, ErrorLevel::Status);
52} 61}
53 62
54bool DiskArchive::DeleteDirectoryRecursively(const Path& path) const { 63ResultCode DiskArchive::DeleteDirectoryRecursively(const Path& path) const {
55 return FileUtil::DeleteDirRecursively(mount_point + path.AsString()); 64 if (FileUtil::DeleteDirRecursively(mount_point + path.AsString()))
65 return RESULT_SUCCESS;
66 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
67 ErrorSummary::Canceled, ErrorLevel::Status);
56} 68}
57 69
58ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { 70ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
@@ -81,20 +93,30 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
81 ErrorLevel::Info); 93 ErrorLevel::Info);
82} 94}
83 95
84bool DiskArchive::CreateDirectory(const Path& path) const { 96ResultCode DiskArchive::CreateDirectory(const Path& path) const {
85 return FileUtil::CreateDir(mount_point + path.AsString()); 97 if (FileUtil::CreateDir(mount_point + path.AsString()))
98 return RESULT_SUCCESS;
99 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
100 ErrorSummary::Canceled, ErrorLevel::Status);
86} 101}
87 102
88bool DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { 103ResultCode DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
89 return FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()); 104 if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()))
105 return RESULT_SUCCESS;
106
107 // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
108 // exist or similar. Verify.
109 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
110 ErrorSummary::NothingHappened, ErrorLevel::Status);
90} 111}
91 112
92std::unique_ptr<DirectoryBackend> DiskArchive::OpenDirectory(const Path& path) const { 113ResultVal<std::unique_ptr<DirectoryBackend>> DiskArchive::OpenDirectory(const Path& path) const {
93 LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str()); 114 LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str());
94 auto directory = std::make_unique<DiskDirectory>(*this, path); 115 auto directory = std::make_unique<DiskDirectory>(*this, path);
95 if (!directory->Open()) 116 if (!directory->Open())
96 return nullptr; 117 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
97 return std::move(directory); 118 ErrorLevel::Permanent);
119 return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
98} 120}
99 121
100u64 DiskArchive::GetFreeBytes() const { 122u64 DiskArchive::GetFreeBytes() const {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 59ebb2002..0edd87954 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -34,15 +34,15 @@ public:
34 } 34 }
35 35
36 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, 36 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
37 const Mode mode) const override; 37 const Mode& mode) const override;
38 ResultCode DeleteFile(const Path& path) const override; 38 ResultCode DeleteFile(const Path& path) const override;
39 bool RenameFile(const Path& src_path, const Path& dest_path) const override; 39 ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
40 bool DeleteDirectory(const Path& path) const override; 40 ResultCode DeleteDirectory(const Path& path) const override;
41 bool DeleteDirectoryRecursively(const Path& path) const override; 41 ResultCode DeleteDirectoryRecursively(const Path& path) const override;
42 ResultCode CreateFile(const Path& path, u64 size) const override; 42 ResultCode CreateFile(const Path& path, u64 size) const override;
43 bool CreateDirectory(const Path& path) const override; 43 ResultCode CreateDirectory(const Path& path) const override;
44 bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; 44 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
45 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; 45 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
46 u64 GetFreeBytes() const override; 46 u64 GetFreeBytes() const override;
47 47
48protected: 48protected:
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index af59d296d..2735d2e3c 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -18,7 +18,7 @@ std::string IVFCArchive::GetName() const {
18} 18}
19 19
20ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, 20ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
21 const Mode mode) const { 21 const Mode& mode) const {
22 return MakeResult<std::unique_ptr<FileBackend>>( 22 return MakeResult<std::unique_ptr<FileBackend>>(
23 std::make_unique<IVFCFile>(romfs_file, data_offset, data_size)); 23 std::make_unique<IVFCFile>(romfs_file, data_offset, data_size));
24} 24}
@@ -31,22 +31,25 @@ ResultCode IVFCArchive::DeleteFile(const Path& path) const {
31 ErrorLevel::Status); 31 ErrorLevel::Status);
32} 32}
33 33
34bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { 34ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
35 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", 35 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
36 GetName().c_str()); 36 GetName().c_str());
37 return false; 37 // TODO(wwylele): Use correct error code
38 return ResultCode(-1);
38} 39}
39 40
40bool IVFCArchive::DeleteDirectory(const Path& path) const { 41ResultCode IVFCArchive::DeleteDirectory(const Path& path) const {
41 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).", 42 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
42 GetName().c_str()); 43 GetName().c_str());
43 return false; 44 // TODO(wwylele): Use correct error code
45 return ResultCode(-1);
44} 46}
45 47
46bool IVFCArchive::DeleteDirectoryRecursively(const Path& path) const { 48ResultCode IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
47 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).", 49 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
48 GetName().c_str()); 50 GetName().c_str());
49 return false; 51 // TODO(wwylele): Use correct error code
52 return ResultCode(-1);
50} 53}
51 54
52ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { 55ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
@@ -57,20 +60,22 @@ ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
57 ErrorLevel::Permanent); 60 ErrorLevel::Permanent);
58} 61}
59 62
60bool IVFCArchive::CreateDirectory(const Path& path) const { 63ResultCode IVFCArchive::CreateDirectory(const Path& path) const {
61 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).", 64 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).",
62 GetName().c_str()); 65 GetName().c_str());
63 return false; 66 // TODO(wwylele): Use correct error code
67 return ResultCode(-1);
64} 68}
65 69
66bool IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { 70ResultCode IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
67 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", 71 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
68 GetName().c_str()); 72 GetName().c_str());
69 return false; 73 // TODO(wwylele): Use correct error code
74 return ResultCode(-1);
70} 75}
71 76
72std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) const { 77ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
73 return std::make_unique<IVFCDirectory>(); 78 return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<IVFCDirectory>());
74} 79}
75 80
76u64 IVFCArchive::GetFreeBytes() const { 81u64 IVFCArchive::GetFreeBytes() const {
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 2fbb3a568..af6297e1f 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -33,15 +33,15 @@ public:
33 std::string GetName() const override; 33 std::string GetName() const override;
34 34
35 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, 35 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
36 const Mode mode) const override; 36 const Mode& mode) const override;
37 ResultCode DeleteFile(const Path& path) const override; 37 ResultCode DeleteFile(const Path& path) const override;
38 bool RenameFile(const Path& src_path, const Path& dest_path) const override; 38 ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
39 bool DeleteDirectory(const Path& path) const override; 39 ResultCode DeleteDirectory(const Path& path) const override;
40 bool DeleteDirectoryRecursively(const Path& path) const override; 40 ResultCode DeleteDirectoryRecursively(const Path& path) const override;
41 ResultCode CreateFile(const Path& path, u64 size) const override; 41 ResultCode CreateFile(const Path& path, u64 size) const override;
42 bool CreateDirectory(const Path& path) const override; 42 ResultCode CreateDirectory(const Path& path) const override;
43 bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; 43 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
44 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; 44 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
45 u64 GetFreeBytes() const override; 45 u64 GetFreeBytes() const override;
46 46
47protected: 47protected: