VERY experimental Nintendo Switch 2 emulator
C++
filesystem: Pass Size Getter functions to IFileSystem for sizes
Zach Hilman94ddc2ebdbe5
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cppindex adc1917aa8..d8debf6126 100644--- a/src/core/hle/service/filesystem/filesystem.cpp+++ b/src/core/hle/service/filesystem/filesystem.cpp@@ -29,11 +29,6 @@namespace Service::FileSystem {-// Size of emulated sd card free space, reported in bytes.-// Just using 32GB because thats reasonable-// TODO(DarkLordZach): Eventually make this configurable in settings.-constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000;-// A default size for normal/journal save data size if application control metadata cannot be found.// This should be large enough to satisfy even the most extreme requirements (~4.2GB)constexpr u64 SUFFICIENT_SAVE_DATA_SIZE = 0xF0000000;@@ -227,13 +222,6 @@ ResultVal<FileSys::VirtualDir> VfsDirectoryServiceWrapper::OpenDirectory(const sreturn MakeResult(dir);}-u64 VfsDirectoryServiceWrapper::GetFreeSpaceSize() const {- if (backing->IsWritable())- return EMULATED_SD_REPORTED_SIZE;-- return 0;-}-ResultVal<FileSys::EntryType> VfsDirectoryServiceWrapper::GetEntryType(const std::string& path_) const {std::string path(FileUtil::SanitizePath(path_));diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.hindex aa4e437ace..2eb3a641d7 100644--- a/src/core/hle/service/filesystem/filesystem.h+++ b/src/core/hle/service/filesystem/filesystem.h@@ -215,12 +215,6 @@ public:*/ResultVal<FileSys::VirtualDir> OpenDirectory(const std::string& path);- /**- * Get the free space- * @return The number of free bytes in the archive- */- u64 GetFreeSpaceSize() const;-/*** Get the type of the specified path* @return The type of the specified path or error codediff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cppindex d3cd46a9b8..85f8e4a633 100644--- a/src/core/hle/service/filesystem/fsp_srv.cpp+++ b/src/core/hle/service/filesystem/fsp_srv.cpp@@ -30,6 +30,18 @@namespace Service::FileSystem {+struct SizeGetter {+ std::function<u64()> free;+ std::function<u64()> total;++ static SizeGetter FromStorageId(const FileSystemController& fsc, FileSys::StorageId id) {+ return {+ [&fsc, id] { return fsc.GetFreeSpaceSize(id); },+ [&fsc, id] { return fsc.GetTotalSpaceSize(id); },+ };+ }+};+enum class FileSystemType : u8 {Invalid0 = 0,Invalid1 = 1,@@ -289,8 +301,8 @@ private:class IFileSystem final : public ServiceFramework<IFileSystem> {public:- explicit IFileSystem(FileSys::VirtualDir backend)- : ServiceFramework("IFileSystem"), backend(std::move(backend)) {+ explicit IFileSystem(FileSys::VirtualDir backend, SizeGetter size)+ : ServiceFramework("IFileSystem"), backend(std::move(backend)), size(std::move(size)) {static const FunctionInfo functions[] = {{0, &IFileSystem::CreateFile, "CreateFile"},{1, &IFileSystem::DeleteFile, "DeleteFile"},@@ -467,8 +479,25 @@ public:rb.Push(RESULT_SUCCESS);}+ void GetFreeSpaceSize(Kernel::HLERequestContext& ctx) {+ LOG_DEBUG(Service_FS, "called");++ IPC::ResponseBuilder rb{ctx, 4};+ rb.Push(RESULT_SUCCESS);+ rb.Push(size.free());+ }++ void GetTotalSpaceSize(Kernel::HLERequestContext& ctx) {+ LOG_DEBUG(Service_FS, "called");++ IPC::ResponseBuilder rb{ctx, 4};+ rb.Push(RESULT_SUCCESS);+ rb.Push(size.total());+ }+private:VfsDirectoryServiceWrapper backend;+ SizeGetter size;};class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> {