mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
[FS] Start implementing CreateFile
This commit is contained in:
parent
ee11a9e7c6
commit
93d2d300b9
3 changed files with 33 additions and 2 deletions
|
@ -30,6 +30,7 @@ class FSService {
|
||||||
FSPath readPath(u32 type, u32 pointer, u32 size);
|
FSPath readPath(u32 type, u32 pointer, u32 size);
|
||||||
|
|
||||||
// Service commands
|
// Service commands
|
||||||
|
void createFile(u32 messagePointer);
|
||||||
void closeArchive(u32 messagePointer);
|
void closeArchive(u32 messagePointer);
|
||||||
void getPriority(u32 messagePointer);
|
void getPriority(u32 messagePointer);
|
||||||
void initialize(u32 messagePointer);
|
void initialize(u32 messagePointer);
|
||||||
|
|
|
@ -9,13 +9,13 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
|
||||||
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
|
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
|
||||||
|
|
||||||
if (perms.create())
|
if (perms.create())
|
||||||
Helpers::panic("[ExtSaveData] CAn't open file with create flag");
|
Helpers::panic("[ExtSaveData] Can't open file with create flag");
|
||||||
|
|
||||||
fs::path p = IOFile::getAppData() / "NAND";
|
fs::path p = IOFile::getAppData() / "NAND";
|
||||||
p += fs::path(path.utf16_string).make_preferred();
|
p += fs::path(path.utf16_string).make_preferred();
|
||||||
|
|
||||||
if (fs::exists(p)) { // Return file descriptor if the file exists
|
if (fs::exists(p)) { // Return file descriptor if the file exists
|
||||||
IOFile file(p.string().c_str(), "r+b"); // According to Citra, this ignores the OpenFile flags and always opens as r+b? TODO: Check
|
IOFile file(p.string().c_str(), "r+b"); // According to Citra, this ignores the OpenFlags field and always opens as r+b? TODO: Check
|
||||||
return file.isOpen() ? file.getHandle() : FileError;
|
return file.isOpen() ? file.getHandle() : FileError;
|
||||||
} else {
|
} else {
|
||||||
return FileError;
|
return FileError;
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
#include "services/fs.hpp"
|
#include "services/fs.hpp"
|
||||||
#include "kernel/kernel.hpp"
|
#include "kernel/kernel.hpp"
|
||||||
|
|
||||||
|
#ifdef CreateFile // windows.h defines this because of course it does.
|
||||||
|
#undef CreateFile
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace FSCommands {
|
namespace FSCommands {
|
||||||
enum : u32 {
|
enum : u32 {
|
||||||
Initialize = 0x08010002,
|
Initialize = 0x08010002,
|
||||||
OpenFile = 0x080201C2,
|
OpenFile = 0x080201C2,
|
||||||
OpenFileDirectly = 0x08030204,
|
OpenFileDirectly = 0x08030204,
|
||||||
|
CreateFile = 0x08080202,
|
||||||
OpenArchive = 0x080C00C2,
|
OpenArchive = 0x080C00C2,
|
||||||
CloseArchive = 0x080E0080,
|
CloseArchive = 0x080E0080,
|
||||||
IsSdmcDetected = 0x08170000,
|
IsSdmcDetected = 0x08170000,
|
||||||
|
@ -87,6 +92,7 @@ FSPath FSService::readPath(u32 type, u32 pointer, u32 size) {
|
||||||
void FSService::handleSyncRequest(u32 messagePointer) {
|
void FSService::handleSyncRequest(u32 messagePointer) {
|
||||||
const u32 command = mem.read32(messagePointer);
|
const u32 command = mem.read32(messagePointer);
|
||||||
switch (command) {
|
switch (command) {
|
||||||
|
case FSCommands::CreateFile: createFile(messagePointer); break;
|
||||||
case FSCommands::CloseArchive: closeArchive(messagePointer); break;
|
case FSCommands::CloseArchive: closeArchive(messagePointer); break;
|
||||||
case FSCommands::GetPriority: getPriority(messagePointer); break;
|
case FSCommands::GetPriority: getPriority(messagePointer); break;
|
||||||
case FSCommands::Initialize: initialize(messagePointer); break;
|
case FSCommands::Initialize: initialize(messagePointer); break;
|
||||||
|
@ -214,6 +220,30 @@ void FSService::openFileDirectly(u32 messagePointer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FSService::createFile(u32 messagePointer) {
|
||||||
|
const u32 archiveHandle = mem.read64(messagePointer + 8);
|
||||||
|
const u32 filePathType = mem.read32(messagePointer + 16);
|
||||||
|
const u32 filePathSize = mem.read32(messagePointer + 20);
|
||||||
|
const u32 attributes = mem.read32(messagePointer + 24);
|
||||||
|
const u64 bytesToZero = mem.read64(messagePointer + 28); // Bytes to fill with zeroes in the file
|
||||||
|
const u32 filePathPointer = mem.read32(messagePointer + 40);
|
||||||
|
|
||||||
|
log("FS::CreateFile\n");
|
||||||
|
|
||||||
|
auto archiveObject = kernel.getObject(archiveHandle, KernelObjectType::Archive);
|
||||||
|
if (archiveObject == nullptr) [[unlikely]] {
|
||||||
|
log("FS::OpenFile: Invalid archive handle %d\n", archiveHandle);
|
||||||
|
mem.write32(messagePointer + 4, Result::Failure);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArchiveBase* archive = archiveObject->getData<ArchiveSession>()->archive;
|
||||||
|
auto filePath = readPath(filePathType, filePathPointer, filePathSize);
|
||||||
|
|
||||||
|
for (auto c : filePath.utf16_string) std::cout << (char)c;
|
||||||
|
Helpers::panic("Tried to create file");
|
||||||
|
}
|
||||||
|
|
||||||
void FSService::getPriority(u32 messagePointer) {
|
void FSService::getPriority(u32 messagePointer) {
|
||||||
log("FS::GetPriority\n");
|
log("FS::GetPriority\n");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue