summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar FearlessTobi2024-02-10 20:58:43 +0100
committerGravatar FearlessTobi2024-02-19 19:20:46 +0100
commit934e420e36e817c673a839e2a417785906bfe91c (patch)
tree13777628e911468f88ed928d0bfa6f4a3d416f10 /src
parentfs: Add FileSystemAccessor classes (diff)
downloadyuzu-934e420e36e817c673a839e2a417785906bfe91c.tar.gz
yuzu-934e420e36e817c673a839e2a417785906bfe91c.tar.xz
yuzu-934e420e36e817c673a839e2a417785906bfe91c.zip
fs: Refactor to use cmif serialization
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/fssrv/fssrv_sf_path.h36
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_directory.cpp32
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_directory.h6
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_file.cpp78
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_file.h16
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp292
-rw-r--r--src/core/hle/service/filesystem/fsp/fs_i_filesystem.h80
7 files changed, 245 insertions, 295 deletions
diff --git a/src/core/file_sys/fssrv/fssrv_sf_path.h b/src/core/file_sys/fssrv/fssrv_sf_path.h
new file mode 100644
index 000000000..1752a413d
--- /dev/null
+++ b/src/core/file_sys/fssrv/fssrv_sf_path.h
@@ -0,0 +1,36 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "core/file_sys/fs_directory.h"
7
8namespace FileSys::Sf {
9
10struct Path {
11 char str[EntryNameLengthMax + 1];
12
13 static constexpr Path Encode(const char* p) {
14 Path path = {};
15 for (size_t i = 0; i < sizeof(path) - 1; i++) {
16 path.str[i] = p[i];
17 if (p[i] == '\x00') {
18 break;
19 }
20 }
21 return path;
22 }
23
24 static constexpr size_t GetPathLength(const Path& path) {
25 size_t len = 0;
26 for (size_t i = 0; i < sizeof(path) - 1 && path.str[i] != '\x00'; i++) {
27 len++;
28 }
29 return len;
30 }
31};
32static_assert(std::is_trivially_copyable_v<Path>, "Path must be trivially copyable.");
33
34using FspPath = Path;
35
36} // namespace FileSys::Sf \ No newline at end of file
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp
index 661da5326..8483394d0 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp
+++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp
@@ -3,8 +3,8 @@
3 3
4#include "core/file_sys/fs_filesystem.h" 4#include "core/file_sys/fs_filesystem.h"
5#include "core/file_sys/savedata_factory.h" 5#include "core/file_sys/savedata_factory.h"
6#include "core/hle/service/cmif_serialization.h"
6#include "core/hle/service/filesystem/fsp/fs_i_directory.h" 7#include "core/hle/service/filesystem/fsp/fs_i_directory.h"
7#include "core/hle/service/ipc_helpers.h"
8 8
9namespace Service::FileSystem { 9namespace Service::FileSystem {
10 10
@@ -13,38 +13,24 @@ IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir directory_,
13 : ServiceFramework{system_, "IDirectory"}, 13 : ServiceFramework{system_, "IDirectory"},
14 backend(std::make_unique<FileSys::Fsa::IDirectory>(directory_, mode)) { 14 backend(std::make_unique<FileSys::Fsa::IDirectory>(directory_, mode)) {
15 static const FunctionInfo functions[] = { 15 static const FunctionInfo functions[] = {
16 {0, &IDirectory::Read, "Read"}, 16 {0, D<&IDirectory::Read>, "Read"},
17 {1, &IDirectory::GetEntryCount, "GetEntryCount"}, 17 {1, D<&IDirectory::GetEntryCount>, "GetEntryCount"},
18 }; 18 };
19 RegisterHandlers(functions); 19 RegisterHandlers(functions);
20} 20}
21 21
22void IDirectory::Read(HLERequestContext& ctx) { 22Result IDirectory::Read(
23 Out<s64> out_count,
24 const OutArray<FileSys::DirectoryEntry, BufferAttr_HipcMapAlias> out_entries) {
23 LOG_DEBUG(Service_FS, "called."); 25 LOG_DEBUG(Service_FS, "called.");
24 26
25 // Calculate how many entries we can fit in the output buffer 27 R_RETURN(backend->Read(out_count, out_entries.data(), out_entries.size()));
26 const u64 count_entries = ctx.GetWriteBufferNumElements<FileSys::DirectoryEntry>();
27
28 s64 out_count{};
29 FileSys::DirectoryEntry* out_entries = nullptr;
30 const auto result = backend->Read(&out_count, out_entries, count_entries);
31
32 // Write the data to memory
33 ctx.WriteBuffer(out_entries, out_count);
34
35 IPC::ResponseBuilder rb{ctx, 4};
36 rb.Push(result);
37 rb.Push(out_count);
38} 28}
39 29
40void IDirectory::GetEntryCount(HLERequestContext& ctx) { 30Result IDirectory::GetEntryCount(Out<s64> out_count) {
41 LOG_DEBUG(Service_FS, "called"); 31 LOG_DEBUG(Service_FS, "called");
42 32
43 s64 out_count{}; 33 R_RETURN(backend->GetEntryCount(out_count));
44
45 IPC::ResponseBuilder rb{ctx, 4};
46 rb.Push(backend->GetEntryCount(&out_count));
47 rb.Push(out_count);
48} 34}
49 35
50} // namespace Service::FileSystem 36} // namespace Service::FileSystem
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.h b/src/core/hle/service/filesystem/fsp/fs_i_directory.h
index 0dec4367b..b6251f7fd 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_directory.h
+++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.h
@@ -5,6 +5,7 @@
5 5
6#include "core/file_sys/fsa/fs_i_directory.h" 6#include "core/file_sys/fsa/fs_i_directory.h"
7#include "core/file_sys/vfs/vfs.h" 7#include "core/file_sys/vfs/vfs.h"
8#include "core/hle/service/cmif_types.h"
8#include "core/hle/service/filesystem/filesystem.h" 9#include "core/hle/service/filesystem/filesystem.h"
9#include "core/hle/service/service.h" 10#include "core/hle/service/service.h"
10 11
@@ -22,8 +23,9 @@ public:
22private: 23private:
23 std::unique_ptr<FileSys::Fsa::IDirectory> backend; 24 std::unique_ptr<FileSys::Fsa::IDirectory> backend;
24 25
25 void Read(HLERequestContext& ctx); 26 Result Read(Out<s64> out_count,
26 void GetEntryCount(HLERequestContext& ctx); 27 const OutArray<FileSys::DirectoryEntry, BufferAttr_HipcMapAlias> out_entries);
28 Result GetEntryCount(Out<s64> out_count);
27}; 29};
28 30
29} // namespace Service::FileSystem 31} // namespace Service::FileSystem
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp
index 8fb8620de..a355d46ae 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp
+++ b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp
@@ -2,86 +2,64 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/file_sys/errors.h" 4#include "core/file_sys/errors.h"
5#include "core/hle/service/cmif_serialization.h"
5#include "core/hle/service/filesystem/fsp/fs_i_file.h" 6#include "core/hle/service/filesystem/fsp/fs_i_file.h"
6#include "core/hle/service/ipc_helpers.h"
7 7
8namespace Service::FileSystem { 8namespace Service::FileSystem {
9 9
10IFile::IFile(Core::System& system_, FileSys::VirtualFile file_) 10IFile::IFile(Core::System& system_, FileSys::VirtualFile file_)
11 : ServiceFramework{system_, "IFile"}, backend{std::make_unique<FileSys::Fsa::IFile>(file_)} { 11 : ServiceFramework{system_, "IFile"}, backend{std::make_unique<FileSys::Fsa::IFile>(file_)} {
12 // clang-format off
12 static const FunctionInfo functions[] = { 13 static const FunctionInfo functions[] = {
13 {0, &IFile::Read, "Read"}, 14 {0, D<&IFile::Read>, "Read"},
14 {1, &IFile::Write, "Write"}, 15 {1, D<&IFile::Write>, "Write"},
15 {2, &IFile::Flush, "Flush"}, 16 {2, D<&IFile::Flush>, "Flush"},
16 {3, &IFile::SetSize, "SetSize"}, 17 {3, D<&IFile::SetSize>, "SetSize"},
17 {4, &IFile::GetSize, "GetSize"}, 18 {4, D<&IFile::GetSize>, "GetSize"},
18 {5, nullptr, "OperateRange"}, 19 {5, nullptr, "OperateRange"},
19 {6, nullptr, "OperateRangeWithBuffer"}, 20 {6, nullptr, "OperateRangeWithBuffer"},
20 }; 21 };
22 // clang-format on
21 RegisterHandlers(functions); 23 RegisterHandlers(functions);
22} 24}
23 25
24void IFile::Read(HLERequestContext& ctx) { 26Result IFile::Read(
25 IPC::RequestParser rp{ctx}; 27 FileSys::ReadOption option, Out<s64> out_size, s64 offset,
26 const u64 option = rp.Pop<u64>(); 28 const OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> out_buffer,
27 const s64 offset = rp.Pop<s64>(); 29 s64 size) {
28 const s64 length = rp.Pop<s64>(); 30 LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset,
29 31 size);
30 LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, offset, length);
31 32
32 // Read the data from the Storage backend 33 // Read the data from the Storage backend
33 std::vector<u8> output(length); 34 R_RETURN(
34 std::size_t bytes_read; 35 backend->Read(reinterpret_cast<size_t*>(out_size.Get()), offset, out_buffer.data(), size));
35 const auto result = backend->Read(&bytes_read, offset, output.data(), length);
36
37 // Write the data to memory
38 ctx.WriteBuffer(output);
39
40 IPC::ResponseBuilder rb{ctx, 4};
41 rb.Push(result);
42 rb.Push(static_cast<u64>(bytes_read));
43} 36}
44 37
45void IFile::Write(HLERequestContext& ctx) { 38Result IFile::Write(
46 IPC::RequestParser rp{ctx}; 39 const InBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> buffer,
47 const auto option = rp.PopRaw<FileSys::WriteOption>(); 40 FileSys::WriteOption option, s64 offset, s64 size) {
48 [[maybe_unused]] const u32 unused = rp.Pop<u32>();
49 const s64 offset = rp.Pop<s64>();
50 const s64 length = rp.Pop<s64>();
51
52 LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, 41 LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset,
53 length); 42 size);
54
55 const auto data = ctx.ReadBuffer();
56 43
57 IPC::ResponseBuilder rb{ctx, 2}; 44 R_RETURN(backend->Write(offset, buffer.data(), size, option));
58 rb.Push(backend->Write(offset, data.data(), length, option));
59} 45}
60 46
61void IFile::Flush(HLERequestContext& ctx) { 47Result IFile::Flush() {
62 LOG_DEBUG(Service_FS, "called"); 48 LOG_DEBUG(Service_FS, "called");
63 49
64 IPC::ResponseBuilder rb{ctx, 2}; 50 R_RETURN(backend->Flush());
65 rb.Push(backend->Flush());
66} 51}
67 52
68void IFile::SetSize(HLERequestContext& ctx) { 53Result IFile::SetSize(s64 size) {
69 IPC::RequestParser rp{ctx};
70 const u64 size = rp.Pop<u64>();
71 LOG_DEBUG(Service_FS, "called, size={}", size); 54 LOG_DEBUG(Service_FS, "called, size={}", size);
72 55
73 IPC::ResponseBuilder rb{ctx, 2}; 56 R_RETURN(backend->SetSize(size));
74 rb.Push(backend->SetSize(size));
75} 57}
76 58
77void IFile::GetSize(HLERequestContext& ctx) { 59Result IFile::GetSize(Out<s64> out_size) {
78 s64 size; 60 LOG_DEBUG(Service_FS, "called");
79 const auto result = backend->GetSize(&size);
80 LOG_DEBUG(Service_FS, "called, size={}", size);
81 61
82 IPC::ResponseBuilder rb{ctx, 4}; 62 R_RETURN(backend->GetSize(out_size));
83 rb.Push(result);
84 rb.Push<u64>(size);
85} 63}
86 64
87} // namespace Service::FileSystem 65} // namespace Service::FileSystem
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.h b/src/core/hle/service/filesystem/fsp/fs_i_file.h
index 887fd3ba2..e8599ee2f 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_file.h
+++ b/src/core/hle/service/filesystem/fsp/fs_i_file.h
@@ -4,6 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/fsa/fs_i_file.h" 6#include "core/file_sys/fsa/fs_i_file.h"
7#include "core/hle/service/cmif_types.h"
7#include "core/hle/service/filesystem/filesystem.h" 8#include "core/hle/service/filesystem/filesystem.h"
8#include "core/hle/service/service.h" 9#include "core/hle/service/service.h"
9 10
@@ -16,11 +17,16 @@ public:
16private: 17private:
17 std::unique_ptr<FileSys::Fsa::IFile> backend; 18 std::unique_ptr<FileSys::Fsa::IFile> backend;
18 19
19 void Read(HLERequestContext& ctx); 20 Result Read(FileSys::ReadOption option, Out<s64> out_size, s64 offset,
20 void Write(HLERequestContext& ctx); 21 const OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure>
21 void Flush(HLERequestContext& ctx); 22 out_buffer,
22 void SetSize(HLERequestContext& ctx); 23 s64 size);
23 void GetSize(HLERequestContext& ctx); 24 Result Write(
25 const InBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> buffer,
26 FileSys::WriteOption option, s64 offset, s64 size);
27 Result Flush();
28 Result SetSize(s64 size);
29 Result GetSize(Out<s64> out_size);
24}; 30};
25 31
26} // namespace Service::FileSystem 32} // namespace Service::FileSystem
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp
index 1e69d22b8..7fc62cb3e 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp
+++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp
@@ -2,274 +2,172 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/string_util.h" 4#include "common/string_util.h"
5#include "core/file_sys/fssrv/fssrv_sf_path.h"
6#include "core/hle/service/cmif_serialization.h"
5#include "core/hle/service/filesystem/fsp/fs_i_directory.h" 7#include "core/hle/service/filesystem/fsp/fs_i_directory.h"
6#include "core/hle/service/filesystem/fsp/fs_i_file.h" 8#include "core/hle/service/filesystem/fsp/fs_i_file.h"
7#include "core/hle/service/filesystem/fsp/fs_i_filesystem.h" 9#include "core/hle/service/filesystem/fsp/fs_i_filesystem.h"
8#include "core/hle/service/ipc_helpers.h"
9 10
10namespace Service::FileSystem { 11namespace Service::FileSystem {
11 12
12IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_) 13IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_)
13 : ServiceFramework{system_, "IFileSystem"}, 14 : ServiceFramework{system_, "IFileSystem"},
14 backend{std::make_unique<FileSys::Fsa::IFileSystem>(dir_)}, size{std::move(size_)} { 15 backend{std::make_unique<FileSys::Fsa::IFileSystem>(dir_)},
16 size_getter{std::move(size_getter_)} {
15 static const FunctionInfo functions[] = { 17 static const FunctionInfo functions[] = {
16 {0, &IFileSystem::CreateFile, "CreateFile"}, 18 {0, D<&IFileSystem::CreateFile>, "CreateFile"},
17 {1, &IFileSystem::DeleteFile, "DeleteFile"}, 19 {1, D<&IFileSystem::DeleteFile>, "DeleteFile"},
18 {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, 20 {2, D<&IFileSystem::CreateDirectory>, "CreateDirectory"},
19 {3, &IFileSystem::DeleteDirectory, "DeleteDirectory"}, 21 {3, D<&IFileSystem::DeleteDirectory>, "DeleteDirectory"},
20 {4, &IFileSystem::DeleteDirectoryRecursively, "DeleteDirectoryRecursively"}, 22 {4, D<&IFileSystem::DeleteDirectoryRecursively>, "DeleteDirectoryRecursively"},
21 {5, &IFileSystem::RenameFile, "RenameFile"}, 23 {5, D<&IFileSystem::RenameFile>, "RenameFile"},
22 {6, nullptr, "RenameDirectory"}, 24 {6, nullptr, "RenameDirectory"},
23 {7, &IFileSystem::GetEntryType, "GetEntryType"}, 25 {7, D<&IFileSystem::GetEntryType>, "GetEntryType"},
24 {8, &IFileSystem::OpenFile, "OpenFile"}, 26 {8, D<&IFileSystem::OpenFile>, "OpenFile"},
25 {9, &IFileSystem::OpenDirectory, "OpenDirectory"}, 27 {9, D<&IFileSystem::OpenDirectory>, "OpenDirectory"},
26 {10, &IFileSystem::Commit, "Commit"}, 28 {10, D<&IFileSystem::Commit>, "Commit"},
27 {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"}, 29 {11, D<&IFileSystem::GetFreeSpaceSize>, "GetFreeSpaceSize"},
28 {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"}, 30 {12, D<&IFileSystem::GetTotalSpaceSize>, "GetTotalSpaceSize"},
29 {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, 31 {13, D<&IFileSystem::CleanDirectoryRecursively>, "CleanDirectoryRecursively"},
30 {14, &IFileSystem::GetFileTimeStampRaw, "GetFileTimeStampRaw"}, 32 {14, D<&IFileSystem::GetFileTimeStampRaw>, "GetFileTimeStampRaw"},
31 {15, nullptr, "QueryEntry"}, 33 {15, nullptr, "QueryEntry"},
32 {16, &IFileSystem::GetFileSystemAttribute, "GetFileSystemAttribute"}, 34 {16, D<&IFileSystem::GetFileSystemAttribute>, "GetFileSystemAttribute"},
33 }; 35 };
34 RegisterHandlers(functions); 36 RegisterHandlers(functions);
35} 37}
36 38
37void IFileSystem::CreateFile(HLERequestContext& ctx) { 39Result IFileSystem::CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path,
38 IPC::RequestParser rp{ctx}; 40 s32 option, s64 size) {
41 LOG_DEBUG(Service_FS, "called. file={}, option=0x{:X}, size=0x{:08X}", path->str, option, size);
39 42
40 const auto file_buffer = ctx.ReadBuffer(); 43 R_RETURN(backend->CreateFile(FileSys::Path(path->str), size));
41 const std::string name = Common::StringFromBuffer(file_buffer);
42 const auto path = FileSys::Path(name.c_str());
43
44 const u64 file_mode = rp.Pop<u64>();
45 const u32 file_size = rp.Pop<u32>();
46
47 LOG_DEBUG(Service_FS, "called. file={}, mode=0x{:X}, size=0x{:08X}", name, file_mode,
48 file_size);
49
50 IPC::ResponseBuilder rb{ctx, 2};
51 rb.Push(backend->CreateFile(path, file_size));
52} 44}
53 45
54void IFileSystem::DeleteFile(HLERequestContext& ctx) { 46Result IFileSystem::DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
55 const auto file_buffer = ctx.ReadBuffer(); 47 LOG_DEBUG(Service_FS, "called. file={}", path->str);
56 const std::string name = Common::StringFromBuffer(file_buffer);
57 const auto path = FileSys::Path(name.c_str());
58 48
59 LOG_DEBUG(Service_FS, "called. file={}", name); 49 R_RETURN(backend->DeleteFile(FileSys::Path(path->str)));
60
61 IPC::ResponseBuilder rb{ctx, 2};
62 rb.Push(backend->DeleteFile(path));
63} 50}
64 51
65void IFileSystem::CreateDirectory(HLERequestContext& ctx) { 52Result IFileSystem::CreateDirectory(
66 const auto file_buffer = ctx.ReadBuffer(); 53 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
67 const std::string name = Common::StringFromBuffer(file_buffer); 54 LOG_DEBUG(Service_FS, "called. directory={}", path->str);
68 const auto path = FileSys::Path(name.c_str());
69
70 LOG_DEBUG(Service_FS, "called. directory={}", name);
71 55
72 IPC::ResponseBuilder rb{ctx, 2}; 56 R_RETURN(backend->CreateDirectory(FileSys::Path(path->str)));
73 rb.Push(backend->CreateDirectory(path));
74} 57}
75 58
76void IFileSystem::DeleteDirectory(HLERequestContext& ctx) { 59Result IFileSystem::DeleteDirectory(
77 const auto file_buffer = ctx.ReadBuffer(); 60 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
78 const std::string name = Common::StringFromBuffer(file_buffer); 61 LOG_DEBUG(Service_FS, "called. directory={}", path->str);
79 const auto path = FileSys::Path(name.c_str());
80
81 LOG_DEBUG(Service_FS, "called. directory={}", name);
82 62
83 IPC::ResponseBuilder rb{ctx, 2}; 63 R_RETURN(backend->DeleteDirectory(FileSys::Path(path->str)));
84 rb.Push(backend->DeleteDirectory(path));
85} 64}
86 65
87void IFileSystem::DeleteDirectoryRecursively(HLERequestContext& ctx) { 66Result IFileSystem::DeleteDirectoryRecursively(
88 const auto file_buffer = ctx.ReadBuffer(); 67 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
89 const std::string name = Common::StringFromBuffer(file_buffer); 68 LOG_DEBUG(Service_FS, "called. directory={}", path->str);
90 const auto path = FileSys::Path(name.c_str());
91 69
92 LOG_DEBUG(Service_FS, "called. directory={}", name); 70 R_RETURN(backend->DeleteDirectoryRecursively(FileSys::Path(path->str)));
93
94 IPC::ResponseBuilder rb{ctx, 2};
95 rb.Push(backend->DeleteDirectoryRecursively(path));
96} 71}
97 72
98void IFileSystem::CleanDirectoryRecursively(HLERequestContext& ctx) { 73Result IFileSystem::CleanDirectoryRecursively(
99 const auto file_buffer = ctx.ReadBuffer(); 74 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
100 const std::string name = Common::StringFromBuffer(file_buffer); 75 LOG_DEBUG(Service_FS, "called. Directory: {}", path->str);
101 const auto path = FileSys::Path(name.c_str());
102
103 LOG_DEBUG(Service_FS, "called. Directory: {}", name);
104 76
105 IPC::ResponseBuilder rb{ctx, 2}; 77 R_RETURN(backend->CleanDirectoryRecursively(FileSys::Path(path->str)));
106 rb.Push(backend->CleanDirectoryRecursively(path));
107} 78}
108 79
109void IFileSystem::RenameFile(HLERequestContext& ctx) { 80Result IFileSystem::RenameFile(
110 const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); 81 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> old_path,
111 const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); 82 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> new_path) {
112 83 LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", old_path->str, new_path->str);
113 const auto src_path = FileSys::Path(src_name.c_str());
114 const auto dst_path = FileSys::Path(dst_name.c_str());
115 84
116 LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); 85 R_RETURN(backend->RenameFile(FileSys::Path(old_path->str), FileSys::Path(new_path->str)));
117
118 IPC::ResponseBuilder rb{ctx, 2};
119 rb.Push(backend->RenameFile(src_path, dst_path));
120} 86}
121 87
122void IFileSystem::OpenFile(HLERequestContext& ctx) { 88Result IFileSystem::OpenFile(OutInterface<IFile> out_interface,
123 IPC::RequestParser rp{ctx}; 89 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path,
124 90 u32 mode) {
125 const auto file_buffer = ctx.ReadBuffer(); 91 LOG_DEBUG(Service_FS, "called. file={}, mode={}", path->str, mode);
126 const std::string name = Common::StringFromBuffer(file_buffer);
127 const auto path = FileSys::Path(name.c_str());
128
129 const auto mode = static_cast<FileSys::OpenMode>(rp.Pop<u32>());
130
131 LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode);
132 92
133 FileSys::VirtualFile vfs_file{}; 93 FileSys::VirtualFile vfs_file{};
134 auto result = backend->OpenFile(&vfs_file, path, mode); 94 R_TRY(backend->OpenFile(&vfs_file, FileSys::Path(path->str),
135 if (result != ResultSuccess) { 95 static_cast<FileSys::OpenMode>(mode)));
136 IPC::ResponseBuilder rb{ctx, 2};
137 rb.Push(result);
138 return;
139 }
140
141 auto file = std::make_shared<IFile>(system, vfs_file);
142
143 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
144 rb.Push(ResultSuccess);
145 rb.PushIpcInterface<IFile>(std::move(file));
146}
147
148void IFileSystem::OpenDirectory(HLERequestContext& ctx) {
149 IPC::RequestParser rp{ctx};
150 96
151 const auto file_buffer = ctx.ReadBuffer(); 97 *out_interface = std::make_shared<IFile>(system, vfs_file);
152 const std::string name = Common::StringFromBuffer(file_buffer); 98 R_SUCCEED();
153 const auto path = FileSys::Path(name.c_str()); 99}
154 const auto mode = rp.PopRaw<FileSys::OpenDirectoryMode>();
155 100
156 LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); 101Result IFileSystem::OpenDirectory(OutInterface<IDirectory> out_interface,
102 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path,
103 u32 mode) {
104 LOG_DEBUG(Service_FS, "called. directory={}, mode={}", path->str, mode);
157 105
158 FileSys::VirtualDir vfs_dir{}; 106 FileSys::VirtualDir vfs_dir{};
159 auto result = backend->OpenDirectory(&vfs_dir, path, mode); 107 R_TRY(backend->OpenDirectory(&vfs_dir, FileSys::Path(path->str),
160 if (result != ResultSuccess) { 108 static_cast<FileSys::OpenDirectoryMode>(mode)));
161 IPC::ResponseBuilder rb{ctx, 2};
162 rb.Push(result);
163 return;
164 }
165
166 auto directory = std::make_shared<IDirectory>(system, vfs_dir, mode);
167
168 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
169 rb.Push(ResultSuccess);
170 rb.PushIpcInterface<IDirectory>(std::move(directory));
171}
172 109
173void IFileSystem::GetEntryType(HLERequestContext& ctx) { 110 *out_interface = std::make_shared<IDirectory>(system, vfs_dir,
174 const auto file_buffer = ctx.ReadBuffer(); 111 static_cast<FileSys::OpenDirectoryMode>(mode));
175 const std::string name = Common::StringFromBuffer(file_buffer); 112 R_SUCCEED();
176 const auto path = FileSys::Path(name.c_str()); 113}
177 114
178 LOG_DEBUG(Service_FS, "called. file={}", name); 115Result IFileSystem::GetEntryType(
116 Out<u32> out_type, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
117 LOG_DEBUG(Service_FS, "called. file={}", path->str);
179 118
180 FileSys::DirectoryEntryType vfs_entry_type{}; 119 FileSys::DirectoryEntryType vfs_entry_type{};
181 auto result = backend->GetEntryType(&vfs_entry_type, path); 120 R_TRY(backend->GetEntryType(&vfs_entry_type, FileSys::Path(path->str)));
182 if (result != ResultSuccess) { 121
183 IPC::ResponseBuilder rb{ctx, 2}; 122 *out_type = static_cast<u32>(vfs_entry_type);
184 rb.Push(result); 123 R_SUCCEED();
185 return;
186 }
187
188 IPC::ResponseBuilder rb{ctx, 3};
189 rb.Push(ResultSuccess);
190 rb.Push<u32>(static_cast<u32>(vfs_entry_type));
191} 124}
192 125
193void IFileSystem::Commit(HLERequestContext& ctx) { 126Result IFileSystem::Commit() {
194 LOG_WARNING(Service_FS, "(STUBBED) called"); 127 LOG_WARNING(Service_FS, "(STUBBED) called");
195 128
196 IPC::ResponseBuilder rb{ctx, 2}; 129 R_SUCCEED();
197 rb.Push(ResultSuccess);
198} 130}
199 131
200void IFileSystem::GetFreeSpaceSize(HLERequestContext& ctx) { 132Result IFileSystem::GetFreeSpaceSize(
133 Out<s64> out_size, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
201 LOG_DEBUG(Service_FS, "called"); 134 LOG_DEBUG(Service_FS, "called");
202 135
203 IPC::ResponseBuilder rb{ctx, 4}; 136 *out_size = size_getter.get_free_size();
204 rb.Push(ResultSuccess); 137 R_SUCCEED();
205 rb.Push(size.get_free_size());
206} 138}
207 139
208void IFileSystem::GetTotalSpaceSize(HLERequestContext& ctx) { 140Result IFileSystem::GetTotalSpaceSize(
141 Out<s64> out_size, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
209 LOG_DEBUG(Service_FS, "called"); 142 LOG_DEBUG(Service_FS, "called");
210 143
211 IPC::ResponseBuilder rb{ctx, 4}; 144 *out_size = size_getter.get_total_size();
212 rb.Push(ResultSuccess); 145 R_SUCCEED();
213 rb.Push(size.get_total_size());
214} 146}
215 147
216void IFileSystem::GetFileTimeStampRaw(HLERequestContext& ctx) { 148Result IFileSystem::GetFileTimeStampRaw(
217 const auto file_buffer = ctx.ReadBuffer(); 149 Out<FileSys::FileTimeStampRaw> out_timestamp,
218 const std::string name = Common::StringFromBuffer(file_buffer); 150 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) {
219 const auto path = FileSys::Path(name.c_str()); 151 LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", path->str);
220
221 LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name);
222 152
223 FileSys::FileTimeStampRaw vfs_timestamp{}; 153 FileSys::FileTimeStampRaw vfs_timestamp{};
224 auto result = backend->GetFileTimeStampRaw(&vfs_timestamp, path); 154 R_TRY(backend->GetFileTimeStampRaw(&vfs_timestamp, FileSys::Path(path->str)));
225 if (result != ResultSuccess) { 155
226 IPC::ResponseBuilder rb{ctx, 2}; 156 *out_timestamp = vfs_timestamp;
227 rb.Push(result); 157 R_SUCCEED();
228 return;
229 }
230
231 IPC::ResponseBuilder rb{ctx, 10};
232 rb.Push(ResultSuccess);
233 rb.PushRaw(vfs_timestamp);
234} 158}
235 159
236void IFileSystem::GetFileSystemAttribute(HLERequestContext& ctx) { 160Result IFileSystem::GetFileSystemAttribute(Out<FileSystemAttribute> out_attribute) {
237 LOG_WARNING(Service_FS, "(STUBBED) called"); 161 LOG_WARNING(Service_FS, "(STUBBED) called");
238 162
239 struct FileSystemAttribute {
240 u8 dir_entry_name_length_max_defined;
241 u8 file_entry_name_length_max_defined;
242 u8 dir_path_name_length_max_defined;
243 u8 file_path_name_length_max_defined;
244 INSERT_PADDING_BYTES_NOINIT(0x5);
245 u8 utf16_dir_entry_name_length_max_defined;
246 u8 utf16_file_entry_name_length_max_defined;
247 u8 utf16_dir_path_name_length_max_defined;
248 u8 utf16_file_path_name_length_max_defined;
249 INSERT_PADDING_BYTES_NOINIT(0x18);
250 s32 dir_entry_name_length_max;
251 s32 file_entry_name_length_max;
252 s32 dir_path_name_length_max;
253 s32 file_path_name_length_max;
254 INSERT_PADDING_WORDS_NOINIT(0x5);
255 s32 utf16_dir_entry_name_length_max;
256 s32 utf16_file_entry_name_length_max;
257 s32 utf16_dir_path_name_length_max;
258 s32 utf16_file_path_name_length_max;
259 INSERT_PADDING_WORDS_NOINIT(0x18);
260 INSERT_PADDING_WORDS_NOINIT(0x1);
261 };
262 static_assert(sizeof(FileSystemAttribute) == 0xc0, "FileSystemAttribute has incorrect size");
263
264 FileSystemAttribute savedata_attribute{}; 163 FileSystemAttribute savedata_attribute{};
265 savedata_attribute.dir_entry_name_length_max_defined = true; 164 savedata_attribute.dir_entry_name_length_max_defined = true;
266 savedata_attribute.file_entry_name_length_max_defined = true; 165 savedata_attribute.file_entry_name_length_max_defined = true;
267 savedata_attribute.dir_entry_name_length_max = 0x40; 166 savedata_attribute.dir_entry_name_length_max = 0x40;
268 savedata_attribute.file_entry_name_length_max = 0x40; 167 savedata_attribute.file_entry_name_length_max = 0x40;
269 168
270 IPC::ResponseBuilder rb{ctx, 50}; 169 *out_attribute = savedata_attribute;
271 rb.Push(ResultSuccess); 170 R_SUCCEED();
272 rb.PushRaw(savedata_attribute);
273} 171}
274 172
275} // namespace Service::FileSystem 173} // namespace Service::FileSystem
diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h
index d500be725..d07b74938 100644
--- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h
+++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h
@@ -5,35 +5,79 @@
5 5
6#include "core/file_sys/fsa/fs_i_filesystem.h" 6#include "core/file_sys/fsa/fs_i_filesystem.h"
7#include "core/file_sys/vfs/vfs.h" 7#include "core/file_sys/vfs/vfs.h"
8#include "core/hle/service/cmif_types.h"
8#include "core/hle/service/filesystem/filesystem.h" 9#include "core/hle/service/filesystem/filesystem.h"
9#include "core/hle/service/filesystem/fsp/fsp_util.h" 10#include "core/hle/service/filesystem/fsp/fsp_util.h"
10#include "core/hle/service/service.h" 11#include "core/hle/service/service.h"
11 12
13namespace FileSys::Sf {
14struct Path;
15}
16
12namespace Service::FileSystem { 17namespace Service::FileSystem {
13 18
19class IFile;
20class IDirectory;
21
14class IFileSystem final : public ServiceFramework<IFileSystem> { 22class IFileSystem final : public ServiceFramework<IFileSystem> {
15public: 23public:
16 explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_); 24 explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_);
17 25
18 void CreateFile(HLERequestContext& ctx); 26 struct FileSystemAttribute {
19 void DeleteFile(HLERequestContext& ctx); 27 u8 dir_entry_name_length_max_defined;
20 void CreateDirectory(HLERequestContext& ctx); 28 u8 file_entry_name_length_max_defined;
21 void DeleteDirectory(HLERequestContext& ctx); 29 u8 dir_path_name_length_max_defined;
22 void DeleteDirectoryRecursively(HLERequestContext& ctx); 30 u8 file_path_name_length_max_defined;
23 void CleanDirectoryRecursively(HLERequestContext& ctx); 31 INSERT_PADDING_BYTES_NOINIT(0x5);
24 void RenameFile(HLERequestContext& ctx); 32 u8 utf16_dir_entry_name_length_max_defined;
25 void OpenFile(HLERequestContext& ctx); 33 u8 utf16_file_entry_name_length_max_defined;
26 void OpenDirectory(HLERequestContext& ctx); 34 u8 utf16_dir_path_name_length_max_defined;
27 void GetEntryType(HLERequestContext& ctx); 35 u8 utf16_file_path_name_length_max_defined;
28 void Commit(HLERequestContext& ctx); 36 INSERT_PADDING_BYTES_NOINIT(0x18);
29 void GetFreeSpaceSize(HLERequestContext& ctx); 37 s32 dir_entry_name_length_max;
30 void GetTotalSpaceSize(HLERequestContext& ctx); 38 s32 file_entry_name_length_max;
31 void GetFileTimeStampRaw(HLERequestContext& ctx); 39 s32 dir_path_name_length_max;
32 void GetFileSystemAttribute(HLERequestContext& ctx); 40 s32 file_path_name_length_max;
41 INSERT_PADDING_WORDS_NOINIT(0x5);
42 s32 utf16_dir_entry_name_length_max;
43 s32 utf16_file_entry_name_length_max;
44 s32 utf16_dir_path_name_length_max;
45 s32 utf16_file_path_name_length_max;
46 INSERT_PADDING_WORDS_NOINIT(0x18);
47 INSERT_PADDING_WORDS_NOINIT(0x1);
48 };
49 static_assert(sizeof(FileSystemAttribute) == 0xC0, "FileSystemAttribute has incorrect size");
50
51 Result CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path,
52 s32 option, s64 size);
53 Result DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
54 Result CreateDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
55 Result DeleteDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
56 Result DeleteDirectoryRecursively(
57 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
58 Result CleanDirectoryRecursively(
59 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
60 Result RenameFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> old_path,
61 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> new_path);
62 Result OpenFile(OutInterface<IFile> out_interface,
63 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, u32 mode);
64 Result OpenDirectory(OutInterface<IDirectory> out_interface,
65 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path,
66 u32 mode);
67 Result GetEntryType(Out<u32> out_type,
68 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
69 Result Commit();
70 Result GetFreeSpaceSize(Out<s64> out_size,
71 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
72 Result GetTotalSpaceSize(Out<s64> out_size,
73 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
74 Result GetFileTimeStampRaw(Out<FileSys::FileTimeStampRaw> out_timestamp,
75 const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path);
76 Result GetFileSystemAttribute(Out<FileSystemAttribute> out_attribute);
33 77
34private: 78private:
35 std::unique_ptr<FileSys::Fsa::IFileSystem> backend; 79 std::unique_ptr<FileSys::Fsa::IFileSystem> backend;
36 SizeGetter size; 80 SizeGetter size_getter;
37}; 81};
38 82
39} // namespace Service::FileSystem 83} // namespace Service::FileSystem