summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar bunnei2014-12-21 01:45:00 -0500
committerGravatar bunnei2014-12-21 01:45:00 -0500
commit572ce043c291f46f50d97f68f4df4f6f93e72035 (patch)
tree79a59fa757424e053b029b6162937551a03d1e25 /src/core/file_sys
parentMerge pull request #323 from lioncash/saddsub (diff)
parentAdded CreateFile to the FS_USER service (diff)
downloadyuzu-572ce043c291f46f50d97f68f4df4f6f93e72035.tar.gz
yuzu-572ce043c291f46f50d97f68f4df4f6f93e72035.tar.xz
yuzu-572ce043c291f46f50d97f68f4df4f6f93e72035.zip
Merge pull request #271 from archshift/createf
Added CreateFile to the FS_USER service
Diffstat (limited to 'src/core/file_sys')
-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
5 files changed, 44 insertions, 0 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;