Merge pull request #379 from wheremyfoodat/scheduler

Implement SDMC Write-Only archive
This commit is contained in:
wheremyfoodat 2024-01-23 20:13:36 +00:00 committed by GitHub
commit 62cbe4d031
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 7 deletions

View file

@ -5,8 +5,10 @@
using Result::HorizonResult;
class SDMCArchive : public ArchiveBase {
public:
SDMCArchive(Memory& mem) : ArchiveBase(mem) {}
bool isWriteOnly = false; // There's 2 variants of the SDMC archive: Regular one (Read/Write) and write-only
public:
SDMCArchive(Memory& mem, bool writeOnly = false) : ArchiveBase(mem), isWriteOnly(writeOnly) {}
u64 getFreeBytes() override { return 1_GB; }
std::string name() override { return "SDMC"; }

View file

@ -26,6 +26,7 @@ class FSService {
SelfNCCHArchive selfNcch;
SaveDataArchive saveData;
SDMCArchive sdmc;
SDMCArchive sdmcWriteOnly;
NCCHArchive ncch;
// UserSaveData archives
@ -82,9 +83,9 @@ class FSService {
public:
FSService(Memory& mem, Kernel& kernel, const EmulatorConfig& config)
: mem(mem), saveData(mem), sharedExtSaveData_nand(mem, "../SharedFiles/NAND", true), extSaveData_sdmc(mem, "SDMC"), sdmc(mem), selfNcch(mem),
ncch(mem), userSaveData1(mem, ArchiveID::UserSaveData1), userSaveData2(mem, ArchiveID::UserSaveData2), kernel(kernel), config(config),
systemSaveData(mem) {}
: mem(mem), saveData(mem), sharedExtSaveData_nand(mem, "../SharedFiles/NAND", true), extSaveData_sdmc(mem, "SDMC"), sdmc(mem),
sdmcWriteOnly(mem, true), selfNcch(mem), ncch(mem), userSaveData1(mem, ArchiveID::UserSaveData1),
userSaveData2(mem, ArchiveID::UserSaveData2), kernel(kernel), config(config), systemSaveData(mem) {}
void reset();
void handleSyncRequest(u32 messagePointer);

View file

@ -45,8 +45,16 @@ HorizonResult SDMCArchive::deleteFile(const FSPath& path) {
FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) {
FilePerms realPerms = perms;
// SD card always has read permission
realPerms.raw |= (1 << 0);
if (isWriteOnly) {
if (perms.read()) {
Helpers::warn("SDMC: Read flag is not allowed in SDMC Write-Only archive");
return FileError;
}
} else {
// Regular SDMC archive always has read permission
realPerms.raw |= (1 << 0);
}
if ((realPerms.create() && !realPerms.write())) {
Helpers::panic("[SDMC] Unsupported flags for OpenFile");
@ -130,6 +138,11 @@ HorizonResult SDMCArchive::createDirectory(const FSPath& path) {
}
Rust::Result<DirectorySession, HorizonResult> SDMCArchive::openDirectory(const FSPath& path) {
if (isWriteOnly) {
Helpers::warn("SDMC: OpenDirectory is not allowed in SDMC Write-Only archive");
return Err(Result::FS::UnexpectedFileOrDir);
}
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path)) {
Helpers::panic("Unsafe path in SaveData::OpenDirectory");

View file

@ -97,6 +97,7 @@ ArchiveBase* FSService::getArchiveFromID(u32 id, const FSPath& archivePath) {
case ArchiveID::SystemSaveData: return &systemSaveData;
case ArchiveID::SDMC: return &sdmc;
case ArchiveID::SDMCWriteOnly: return &sdmcWriteOnly;
case ArchiveID::SavedataAndNcch: return &ncch; // This can only access NCCH outside of FSPXI
default:
Helpers::panic("Unknown archive. ID: %d\n", id);