[FS] Implement OpenDirectory

This commit is contained in:
wheremyfoodat 2023-03-24 14:07:44 +02:00
parent 1078253f6c
commit 494f3f1899
6 changed files with 89 additions and 5 deletions

View file

@ -2,6 +2,7 @@
#include <cassert>
#include <cstdio>
#include <cstring>
#include <filesystem>
#include <optional>
#include <string>
#include <type_traits>
@ -111,6 +112,17 @@ struct ArchiveSession {
ArchiveSession(ArchiveBase* archive, const FSPath& filePath, bool isOpen = true) : archive(archive), path(filePath), isOpen(isOpen) {}
};
struct DirectorySession {
ArchiveBase* archive = nullptr;
// For directories which are mirrored to a specific path on the disk, this contains that path
// Otherwise this is a nullopt
std::optional<std::filesystem::path> pathOnDisk;
bool isOpen;
DirectorySession(ArchiveBase* archive, std::filesystem::path path, bool isOpen = true) : archive(archive), pathOnDisk(path),
isOpen(isOpen) {}
};
// Represents a file descriptor obtained from OpenFile. If the optional is nullopt, opening the file failed.
// Otherwise the fd of the opened file is returned (or nullptr if the opened file doesn't require one)
using FileDescriptor = std::optional<FILE*>;
@ -201,6 +213,10 @@ public:
virtual FileDescriptor openFile(const FSPath& path, const FilePerms& perms) = 0;
virtual ArchiveBase* openArchive(const FSPath& path) = 0;
virtual std::optional<DirectorySession> openDirectory(const FSPath& path) {
Helpers::panic("Unimplemented OpenDirectory for %s archive", name().c_str());
return std::nullopt;
}
// Read size bytes from a file starting at offset "offset" into a certain buffer in memory
// Returns the number of bytes read, or nullopt if the read failed

View file

@ -13,6 +13,7 @@ public:
FormatInfo getFormatInfo(const FSPath& path) override;
ArchiveBase* openArchive(const FSPath& path) override;
std::optional<DirectorySession> openDirectory(const FSPath& path) override;
FileDescriptor openFile(const FSPath& path, const FilePerms& perms) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;

View file

@ -27,7 +27,7 @@ namespace SVCResult {
}
enum class KernelObjectType : u8 {
AddressArbiter, Archive, File, MemoryBlock, Process, ResourceLimit, Session, Dummy,
AddressArbiter, Archive, Directory, File, MemoryBlock, Process, ResourceLimit, Session, Dummy,
// Bundle waitable objects together in the enum to let the compiler optimize certain checks better
Event, Mutex, Port, Semaphore, Timer, Thread
};
@ -144,6 +144,7 @@ static const char* kernelObjectTypeToString(KernelObjectType t) {
switch (t) {
case KernelObjectType::AddressArbiter: return "address arbiter";
case KernelObjectType::Archive: return "archive";
case KernelObjectType::Directory: return "directory";
case KernelObjectType::Event: return "event";
case KernelObjectType::File: return "file";
case KernelObjectType::MemoryBlock: return "memory block";

View file

@ -29,6 +29,7 @@ class FSService {
ArchiveBase* getArchiveFromID(u32 id);
std::optional<Handle> openArchiveHandle(u32 archiveID, const FSPath& path);
std::optional<Handle> openDirectoryHandle(ArchiveBase* archive, const FSPath& path);
std::optional<Handle> openFileHandle(ArchiveBase* archive, const FSPath& path, const FSPath& archivePath, const FilePerms& perms);
FSPath readPath(u32 type, u32 pointer, u32 size);
@ -42,6 +43,7 @@ class FSService {
void initializeWithSdkVersion(u32 messagePointer);
void isSdmcDetected(u32 messagePointer);
void openArchive(u32 messagePointer);
void openDirectory(u32 messagePointer);
void openFile(u32 messagePointer);
void openFileDirectly(u32 messagePointer);
void setPriority(u32 messagePointer);