Skip to content

Commit

Permalink
Merge pull request #379 from wheremyfoodat/scheduler
Browse files Browse the repository at this point in the history
Implement SDMC Write-Only archive
  • Loading branch information
wheremyfoodat authored Jan 23, 2024
2 parents b6a054c + 313620c commit 62cbe4d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions include/fs/archive_sdmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }
Expand Down
7 changes: 4 additions & 3 deletions include/services/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FSService {
SelfNCCHArchive selfNcch;
SaveDataArchive saveData;
SDMCArchive sdmc;
SDMCArchive sdmcWriteOnly;
NCCHArchive ncch;

// UserSaveData archives
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 15 additions & 2 deletions src/core/fs/archive_sdmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/core/services/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 62cbe4d

Please sign in to comment.