aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/file_sys/disk_archive.cpp
diff options
context:
space:
mode:
authorGravatar archshift <admin@archshift.com>2014-12-20 12:43:50 -0300
committerGravatar archshift <admin@archshift.com>2014-12-21 02:21:49 -0300
commit0625dd09eaf9158696a9255cb6c6b2bd73122301 (patch)
tree752f0e9bd60403c1cbb0c3a1ba25f60c9a6925f2 /src/core/file_sys/disk_archive.cpp
parentc2753d37a743e48548a6c792a0ec2278591f79a0 (diff)
Added CreateFile to the FS_USER service
Tested with hwtests.
Diffstat (limited to 'src/core/file_sys/disk_archive.cpp')
-rw-r--r--src/core/file_sys/disk_archive.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index eabf5805..f8096ebc 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 {
return FileUtil::DeleteDir(GetMountPoint() + path.AsString());
}
+ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u32 size) const {
+ std::string full_path = GetMountPoint() + path.AsString();
+
+ if (FileUtil::Exists(full_path))
+ return ResultCode(ErrorDescription::AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Info);
+
+ if (size == 0) {
+ FileUtil::CreateEmptyFile(full_path);
+ return RESULT_SUCCESS;
+ }
+
+ FileUtil::IOFile file(full_path, "wb");
+ // Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
+ // We do this by seeking to the right size, then writing a single null byte.
+ if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1)
+ return RESULT_SUCCESS;
+
+ return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, ErrorLevel::Info);
+}
+
+
bool DiskArchive::CreateDirectory(const Path& path) const {
return FileUtil::CreateDir(GetMountPoint() + path.AsString());
}