summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/file_sys/archive_backend.h8
-rw-r--r--src/core/file_sys/archive_romfs.cpp6
-rw-r--r--src/core/file_sys/archive_romfs.h8
-rw-r--r--src/core/file_sys/disk_archive.cpp21
-rw-r--r--src/core/file_sys/disk_archive.h1
-rw-r--r--src/core/hle/service/fs/archive.cpp8
-rw-r--r--src/core/hle/service/fs/archive.h9
-rw-r--r--src/core/hle/service/fs/fs_user.cpp31
8 files changed, 91 insertions, 1 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index d7959b2ca..43583d206 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -209,6 +209,14 @@ public:
209 virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; 209 virtual bool DeleteDirectory(const FileSys::Path& path) const = 0;
210 210
211 /** 211 /**
212 * Create a file specified by its path
213 * @param path Path relative to the Archive
214 * @param size The size of the new file, filled with zeroes
215 * @return File creation result code
216 */
217 virtual ResultCode CreateFile(const Path& path, u32 size) const = 0;
218
219 /**
212 * Create a directory specified by its path 220 * Create a directory specified by its path
213 * @param path Path relative to the archive 221 * @param path Path relative to the archive
214 * @return Whether the directory could be created 222 * @return Whether the directory could be created
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 1e3e9dc60..32d0777a0 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -58,6 +58,12 @@ bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const {
58 return false; 58 return false;
59} 59}
60 60
61ResultCode Archive_RomFS::CreateFile(const Path& path, u32 size) const {
62 LOG_WARNING(Service_FS, "Attempted to create a file in ROMFS.");
63 // TODO: Verify error code
64 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent);
65}
66
61/** 67/**
62 * Create a directory specified by its path 68 * Create a directory specified by its path
63 * @param path Path relative to the archive 69 * @param path Path relative to the archive
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 5b1ee6332..3f5cdebed 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -54,6 +54,14 @@ public:
54 bool DeleteDirectory(const FileSys::Path& path) const override; 54 bool DeleteDirectory(const FileSys::Path& path) const override;
55 55
56 /** 56 /**
57 * Create a file specified by its path
58 * @param path Path relative to the Archive
59 * @param size The size of the new file, filled with zeroes
60 * @return File creation result code
61 */
62 ResultCode CreateFile(const Path& path, u32 size) const override;
63
64 /**
57 * Create a directory specified by its path 65 * Create a directory specified by its path
58 * @param path Path relative to the archive 66 * @param path Path relative to the archive
59 * @return Whether the directory could be created 67 * @return Whether the directory could be created
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index eabf58057..f8096ebcf 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -35,6 +35,27 @@ bool DiskArchive::DeleteDirectory(const FileSys::Path& path) const {
35 return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); 35 return FileUtil::DeleteDir(GetMountPoint() + path.AsString());
36} 36}
37 37
38ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u32 size) const {
39 std::string full_path = GetMountPoint() + path.AsString();
40
41 if (FileUtil::Exists(full_path))
42 return ResultCode(ErrorDescription::AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Info);
43
44 if (size == 0) {
45 FileUtil::CreateEmptyFile(full_path);
46 return RESULT_SUCCESS;
47 }
48
49 FileUtil::IOFile file(full_path, "wb");
50 // Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
51 // We do this by seeking to the right size, then writing a single null byte.
52 if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1)
53 return RESULT_SUCCESS;
54
55 return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, ErrorLevel::Info);
56}
57
58
38bool DiskArchive::CreateDirectory(const Path& path) const { 59bool DiskArchive::CreateDirectory(const Path& path) const {
39 return FileUtil::CreateDir(GetMountPoint() + path.AsString()); 60 return FileUtil::CreateDir(GetMountPoint() + path.AsString());
40} 61}
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 778c83953..eaec435d2 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -28,6 +28,7 @@ public:
28 bool DeleteFile(const FileSys::Path& path) const override; 28 bool DeleteFile(const FileSys::Path& path) const override;
29 bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; 29 bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
30 bool DeleteDirectory(const FileSys::Path& path) const override; 30 bool DeleteDirectory(const FileSys::Path& path) const override;
31 ResultCode CreateFile(const Path& path, u32 size) const override;
31 bool CreateDirectory(const Path& path) const override; 32 bool CreateDirectory(const Path& path) const override;
32 bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; 33 bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override;
33 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; 34 std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 510d7320c..b7f97495c 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -330,6 +330,14 @@ ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy
330 ErrorSummary::Canceled, ErrorLevel::Status); 330 ErrorSummary::Canceled, ErrorLevel::Status);
331} 331}
332 332
333ResultCode CreateFileInArchive(Handle archive_handle, const FileSys::Path& path, u32 file_size) {
334 Archive* archive = GetArchive(archive_handle);
335 if (archive == nullptr)
336 return InvalidHandle(ErrorModule::FS);
337
338 return archive->backend->CreateFile(path, file_size);
339}
340
333ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { 341ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
334 Archive* archive = GetArchive(archive_handle); 342 Archive* archive = GetArchive(archive_handle);
335 if (archive == nullptr) 343 if (archive == nullptr)
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index a128276b6..0fd3aaa0c 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -83,6 +83,15 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const Fil
83ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path); 83ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
84 84
85/** 85/**
86 * Create a File in an Archive
87 * @param archive_handle Handle to an open Archive object
88 * @param path Path to the File inside of the Archive
89 * @param file_size The size of the new file, filled with zeroes
90 * @return File creation result code
91 */
92ResultCode CreateFileInArchive(Handle archive_handle, const FileSys::Path& path, u32 file_size);
93
94/**
86 * Create a Directory from an Archive 95 * Create a Directory from an Archive
87 * @param archive_handle Handle to an open Archive object 96 * @param archive_handle Handle to an open Archive object
88 * @param path Path to the Directory inside of the Archive 97 * @param path Path to the Directory inside of the Archive
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index 8b908d691..1402abe83 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -226,6 +226,35 @@ static void DeleteDirectory(Service::Interface* self) {
226} 226}
227 227
228/* 228/*
229 * FS_User::CreateFile service function
230 * Inputs:
231 * 0 : Command header 0x08080202
232 * 2 : Archive handle lower word
233 * 3 : Archive handle upper word
234 * 4 : File path string type
235 * 5 : File path string size
236 * 7 : File size (filled with zeroes)
237 * 10: File path string data
238 * Outputs:
239 * 1 : Result of function, 0 on success, otherwise error code
240 */
241static void CreateFile(Service::Interface* self) {
242 u32* cmd_buff = Kernel::GetCommandBuffer();
243
244 ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
245 auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
246 u32 filename_size = cmd_buff[5];
247 u32 file_size = cmd_buff[7];
248 u32 filename_ptr = cmd_buff[10];
249
250 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
251
252 LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", filename_type, filename_size, file_path.DebugStr().c_str());
253
254 cmd_buff[1] = CreateFileInArchive(archive_handle, file_path, file_size).raw;
255}
256
257/*
229 * FS_User::CreateDirectory service function 258 * FS_User::CreateDirectory service function
230 * Inputs: 259 * Inputs:
231 * 2 : Archive handle lower word 260 * 2 : Archive handle lower word
@@ -465,7 +494,7 @@ const FSUserInterface::FunctionInfo FunctionTable[] = {
465 {0x08050244, RenameFile, "RenameFile"}, 494 {0x08050244, RenameFile, "RenameFile"},
466 {0x08060142, DeleteDirectory, "DeleteDirectory"}, 495 {0x08060142, DeleteDirectory, "DeleteDirectory"},
467 {0x08070142, nullptr, "DeleteDirectoryRecursively"}, 496 {0x08070142, nullptr, "DeleteDirectoryRecursively"},
468 {0x08080202, nullptr, "CreateFile"}, 497 {0x08080202, CreateFile, "CreateFile"},
469 {0x08090182, CreateDirectory, "CreateDirectory"}, 498 {0x08090182, CreateDirectory, "CreateDirectory"},
470 {0x080A0244, RenameDirectory, "RenameDirectory"}, 499 {0x080A0244, RenameDirectory, "RenameDirectory"},
471 {0x080B0102, OpenDirectory, "OpenDirectory"}, 500 {0x080B0102, OpenDirectory, "OpenDirectory"},