yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

Service.FS: Do archive registration using IdCode instead of name

This commit is contained in:
Yuri Kunde Schlesner 2014-12-15 02:44:04 -02:00
parent ca67bb7945
commit f6153679b0
7 changed files with 32 additions and 42 deletions

View File

@ -162,25 +162,12 @@ private:
class Archive : NonCopyable { class Archive : NonCopyable {
public: public:
/// Supported archive types
enum class IdCode : u32 {
RomFS = 0x00000003,
SaveData = 0x00000004,
ExtSaveData = 0x00000006,
SharedExtSaveData = 0x00000007,
SystemSaveData = 0x00000008,
SDMC = 0x00000009,
SDMCWriteOnly = 0x0000000A,
};
Archive() { }
virtual ~Archive() { } virtual ~Archive() { }
/** /**
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
* @return IdCode of the archive
*/ */
virtual IdCode GetIdCode() const = 0; virtual std::string GetName() const = 0;
/** /**
* Open a file specified by its path, using the specified mode * Open a file specified by its path, using the specified mode

View File

@ -22,11 +22,7 @@ public:
Archive_RomFS(const Loader::AppLoader& app_loader); Archive_RomFS(const Loader::AppLoader& app_loader);
~Archive_RomFS() override; ~Archive_RomFS() override;
/** std::string GetName() const override { return "RomFS"; }
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
* @return IdCode of the archive
*/
IdCode GetIdCode() const override { return IdCode::RomFS; }
/** /**
* Open a file specified by its path, using the specified mode * Open a file specified by its path, using the specified mode

View File

@ -26,11 +26,7 @@ public:
*/ */
bool Initialize(); bool Initialize();
/** std::string GetName() const override { return "SDMC"; }
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
* @return IdCode of the archive
*/
IdCode GetIdCode() const override { return IdCode::SDMC; }
/** /**
* Open a file specified by its path, using the specified mode * Open a file specified by its path, using the specified mode

View File

@ -43,9 +43,9 @@ enum class DirectoryCommand : u32 {
class Archive : public Kernel::Session { class Archive : public Kernel::Session {
public: public:
std::string GetName() const override { return "Archive: " + name; } std::string GetName() const override { return "Archive: " + backend->GetName(); }
std::string name; ///< Name of archive (optional) ArchiveIdCode id_code; ///< Id code of the archive
FileSys::Archive* backend; ///< Archive backend interface FileSys::Archive* backend; ///< Archive backend interface
ResultVal<bool> SyncRequest() override { ResultVal<bool> SyncRequest() override {
@ -91,7 +91,7 @@ public:
case FileCommand::Close: case FileCommand::Close:
{ {
LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str()); LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
CloseArchive(backend->GetIdCode()); CloseArchive(id_code);
break; break;
} }
// Unknown command... // Unknown command...
@ -228,9 +228,9 @@ public:
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode std::map<ArchiveIdCode, Handle> g_archive_map; ///< Map of file archives by IdCode
ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code) { ResultVal<Handle> OpenArchive(ArchiveIdCode id_code) {
auto itr = g_archive_map.find(id_code); auto itr = g_archive_map.find(id_code);
if (itr == g_archive_map.end()) { if (itr == g_archive_map.end()) {
return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
@ -240,7 +240,7 @@ ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code) {
return MakeResult<Handle>(itr->second); return MakeResult<Handle>(itr->second);
} }
ResultCode CloseArchive(FileSys::Archive::IdCode id_code) { ResultCode CloseArchive(ArchiveIdCode id_code) {
auto itr = g_archive_map.find(id_code); auto itr = g_archive_map.find(id_code);
if (itr == g_archive_map.end()) { if (itr == g_archive_map.end()) {
LOG_ERROR(Service_FS, "Cannot close archive %d, does not exist!", (int)id_code); LOG_ERROR(Service_FS, "Cannot close archive %d, does not exist!", (int)id_code);
@ -256,7 +256,7 @@ ResultCode CloseArchive(FileSys::Archive::IdCode id_code) {
* @param archive Pointer to the archive to mount * @param archive Pointer to the archive to mount
*/ */
ResultCode MountArchive(Archive* archive) { ResultCode MountArchive(Archive* archive) {
FileSys::Archive::IdCode id_code = archive->backend->GetIdCode(); ArchiveIdCode id_code = archive->id_code;
ResultVal<Handle> archive_handle = OpenArchive(id_code); ResultVal<Handle> archive_handle = OpenArchive(id_code);
if (archive_handle.Succeeded()) { if (archive_handle.Succeeded()) {
LOG_ERROR(Service_FS, "Cannot mount two archives with the same ID code! (%d)", (int) id_code); LOG_ERROR(Service_FS, "Cannot mount two archives with the same ID code! (%d)", (int) id_code);
@ -267,10 +267,10 @@ ResultCode MountArchive(Archive* archive) {
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
ResultCode CreateArchive(FileSys::Archive* backend, const std::string& name) { ResultCode CreateArchive(FileSys::Archive* backend, ArchiveIdCode id_code) {
Archive* archive = new Archive; Archive* archive = new Archive;
Handle handle = Kernel::g_object_pool.Create(archive); Handle handle = Kernel::g_object_pool.Create(archive);
archive->name = name; archive->id_code = id_code;
archive->backend = backend; archive->backend = backend;
ResultCode result = MountArchive(archive); ResultCode result = MountArchive(archive);
@ -411,7 +411,7 @@ void ArchiveInit() {
std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX); std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
auto archive = new FileSys::Archive_SDMC(sdmc_directory); auto archive = new FileSys::Archive_SDMC(sdmc_directory);
if (archive->Initialize()) if (archive->Initialize())
CreateArchive(archive, "SDMC"); CreateArchive(archive, ArchiveIdCode::SDMC);
else else
LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
} }

View File

@ -13,25 +13,36 @@
namespace Service { namespace Service {
namespace FS { namespace FS {
/// Supported archive types
enum class ArchiveIdCode : u32 {
RomFS = 0x00000003,
SaveData = 0x00000004,
ExtSaveData = 0x00000006,
SharedExtSaveData = 0x00000007,
SystemSaveData = 0x00000008,
SDMC = 0x00000009,
SDMCWriteOnly = 0x0000000A,
};
/** /**
* Opens an archive * Opens an archive
* @param id_code IdCode of the archive to open * @param id_code IdCode of the archive to open
* @return Handle to the opened archive * @return Handle to the opened archive
*/ */
ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code); ResultVal<Handle> OpenArchive(ArchiveIdCode id_code);
/** /**
* Closes an archive * Closes an archive
* @param id_code IdCode of the archive to open * @param id_code IdCode of the archive to open
*/ */
ResultCode CloseArchive(FileSys::Archive::IdCode id_code); ResultCode CloseArchive(ArchiveIdCode id_code);
/** /**
* Creates an Archive * Creates an Archive
* @param backend File system backend interface to the archive * @param backend File system backend interface to the archive
* @param name Name of Archive * @param id_code Id code used to access this type of archive
*/ */
ResultCode CreateArchive(FileSys::Archive* backend, const std::string& name); ResultCode CreateArchive(FileSys::Archive* backend, ArchiveIdCode id_code);
/** /**
* Open a File from an Archive * Open a File from an Archive

View File

@ -88,7 +88,7 @@ static void OpenFile(Service::Interface* self) {
static void OpenFileDirectly(Service::Interface* self) { static void OpenFileDirectly(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[2]);
auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]); auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
u32 archivename_size = cmd_buff[4]; u32 archivename_size = cmd_buff[4];
auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]); auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]);
@ -334,7 +334,7 @@ static void OpenDirectory(Service::Interface* self) {
static void OpenArchive(Service::Interface* self) { static void OpenArchive(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
u32 archivename_size = cmd_buff[3]; u32 archivename_size = cmd_buff[3];
u32 archivename_ptr = cmd_buff[5]; u32 archivename_ptr = cmd_buff[5];

View File

@ -74,7 +74,7 @@ ResultStatus LoadFile(const std::string& filename) {
// Load application and RomFS // Load application and RomFS
if (ResultStatus::Success == app_loader.Load()) { if (ResultStatus::Success == app_loader.Load()) {
Service::FS::CreateArchive(new FileSys::Archive_RomFS(app_loader), "RomFS"); Service::FS::CreateArchive(new FileSys::Archive_RomFS(app_loader), Service::FS::ArchiveIdCode::RomFS);
return ResultStatus::Success; return ResultStatus::Success;
} }
break; break;