From 9b9f011f5b679be262172f0935da4c9151064505 Mon Sep 17 00:00:00 2001
From: wheremyfoodat <gponiris2004@gmail.com>
Date: Mon, 20 Mar 2023 17:33:00 +0200
Subject: [PATCH] [FS] Add non-shared ExtSaveData, stub SaveData::GetFormatInfo

---
 include/fs/archive_save_data.hpp      | 1 +
 include/services/fs.hpp               | 5 +++--
 src/core/fs/archive_ext_save_data.cpp | 2 +-
 src/core/fs/archive_save_data.cpp     | 6 ++++++
 src/core/services/fs.cpp              | 1 +
 5 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/fs/archive_save_data.hpp b/include/fs/archive_save_data.hpp
index 824924cd..b8b9b04e 100644
--- a/include/fs/archive_save_data.hpp
+++ b/include/fs/archive_save_data.hpp
@@ -10,6 +10,7 @@ public:
 
 	CreateFileResult createFile(const FSPath& path, u64 size) override;
 	DeleteFileResult deleteFile(const FSPath& path) override;
+	FormatInfo getFormatInfo(const FSPath& path) override;
 
 	ArchiveBase* openArchive(const FSPath& path) override;
 	FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
diff --git a/include/services/fs.hpp b/include/services/fs.hpp
index 3b670d0b..ce2dd699 100644
--- a/include/services/fs.hpp
+++ b/include/services/fs.hpp
@@ -22,6 +22,7 @@ class FSService {
 	// The different filesystem archives (Save data, SelfNCCH, SDMC, NCCH, ExtData, etc)
 	SelfNCCHArchive selfNcch;
 	SaveDataArchive saveData;
+	ExtSaveDataArchive extSaveData;
 	ExtSaveDataArchive sharedExtSaveData;
 	SDMCArchive sdmc;
 	NCCHArchive ncch;
@@ -49,8 +50,8 @@ class FSService {
 	u32 priority;
 
 public:
-	FSService(Memory& mem, Kernel& kernel) : mem(mem), saveData(mem), sharedExtSaveData(mem), sdmc(mem), selfNcch(mem), ncch(mem),
-		kernel(kernel)
+	FSService(Memory& mem, Kernel& kernel) : mem(mem), saveData(mem), extSaveData(mem), sharedExtSaveData(mem), sdmc(mem),
+		selfNcch(mem), ncch(mem), kernel(kernel)
 	{
 		sharedExtSaveData.isShared = true; // Need to do this here because templates and virtual classes do not mix well
 	}
diff --git a/src/core/fs/archive_ext_save_data.cpp b/src/core/fs/archive_ext_save_data.cpp
index 30717ff7..9b8a660e 100644
--- a/src/core/fs/archive_ext_save_data.cpp
+++ b/src/core/fs/archive_ext_save_data.cpp
@@ -74,7 +74,7 @@ ArchiveBase* ExtSaveDataArchive::openArchive(const FSPath& path) {
 		Helpers::panic("ExtSaveData accessed with an invalid path in OpenArchive");
 	}
 
-	if (path.binary[0] != 0) Helpers::panic("ExtSaveData: Tried to access something other than NAND");
+	if (path.binary[0] != 0) Helpers::panic("ExtSaveData: Tried to access something other than NAND. ID: %02X", path.binary[0]);
 
 	return this;
 }
diff --git a/src/core/fs/archive_save_data.cpp b/src/core/fs/archive_save_data.cpp
index 79227275..c9685750 100644
--- a/src/core/fs/archive_save_data.cpp
+++ b/src/core/fs/archive_save_data.cpp
@@ -53,6 +53,12 @@ FileDescriptor SaveDataArchive::openFile(const FSPath& path, const FilePerms& pe
 	return FileError;
 }
 
+
+ArchiveBase::FormatInfo SaveDataArchive::getFormatInfo(const FSPath& path) {
+	Helpers::panic("Unimplemented SaveData::GetFormatInfo");
+	return FormatInfo{ .size = 0, .numOfDirectories = 255, .numOfFiles = 255, .duplicateData = false };
+}
+
 ArchiveBase* SaveDataArchive::openArchive(const FSPath& path) {
 	if (path.type != PathType::Empty) {
 		Helpers::panic("Unimplemented path type for SaveData archive: %d\n", path.type);
diff --git a/src/core/services/fs.cpp b/src/core/services/fs.cpp
index 0d33eb43..4af67e15 100644
--- a/src/core/services/fs.cpp
+++ b/src/core/services/fs.cpp
@@ -56,6 +56,7 @@ ArchiveBase* FSService::getArchiveFromID(u32 id) {
 	switch (id) {
 		case ArchiveID::SelfNCCH: return &selfNcch;
 		case ArchiveID::SaveData: return &saveData;
+		case ArchiveID::ExtSaveData: return &extSaveData;
 		case ArchiveID::SharedExtSaveData: return &sharedExtSaveData;
 		case ArchiveID::SDMC: return &sdmc;
 		case ArchiveID::SavedataAndNcch: return &ncch; // This can only access NCCH outside of FSPXI