From 606d25213b8cbb849929d4cd9fdf19984f335b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 6 May 2018 17:29:50 +0200 Subject: [PATCH] ES: Create system directories with correct metadata --- Source/Core/Core/IOS/ES/ES.cpp | 52 +++++++++++++++-------------- Source/Core/Core/IOS/ES/Formats.cpp | 2 +- Source/Core/Core/IOS/ES/Formats.h | 2 ++ 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index c27a24995c..4619516c76 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -23,6 +23,7 @@ #include "Core/ConfigManager.h" #include "Core/HW/Memmap.h" #include "Core/IOS/ES/Formats.h" +#include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/IOSC.h" #include "Core/IOS/VersionInfo.h" @@ -38,41 +39,42 @@ static u64 s_title_to_launch; struct DirectoryToCreate { const char* path; - u32 attributes; - OpenMode owner_perm; - OpenMode group_perm; - OpenMode other_perm; + FS::FileAttribute attribute; + FS::Mode owner_mode; + FS::Mode group_mode; + FS::Mode other_mode; + FS::Uid uid = PID_KERNEL; + FS::Gid gid = PID_KERNEL; }; constexpr std::array s_directories_to_create = {{ - {"/sys", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_NONE}, - {"/ticket", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_NONE}, - {"/title", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_READ}, - {"/shared1", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_NONE}, - {"/shared2", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW}, - {"/tmp", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW}, - {"/import", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_NONE}, - {"/meta", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_RW}, - {"/wfs", 0, OpenMode::IOS_OPEN_RW, OpenMode::IOS_OPEN_NONE, OpenMode::IOS_OPEN_NONE}, + {"/sys", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::None}, + {"/ticket", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::None}, + {"/title", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::Read}, + {"/shared1", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::None}, + {"/shared2", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite}, + {"/tmp", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite}, + {"/import", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::None}, + {"/meta", 0, FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite, + IOS::ES::FIRST_PPC_UID, 0x1}, + {"/wfs", 0, FS::Mode::ReadWrite, FS::Mode::None, FS::Mode::None, PID_UNKNOWN, PID_UNKNOWN}, }}; ES::ES(Kernel& ios, const std::string& device_name) : Device(ios, device_name) { for (const auto& directory : s_directories_to_create) { - const std::string path = Common::RootUserPath(Common::FROM_SESSION_ROOT) + directory.path; + // Note: ES sets its own UID and GID to 0/0 at boot, so all filesystem accesses in ES are done + // as UID 0 even though its PID is 1. + const auto result = m_ios.GetFS()->CreateDirectory(PID_KERNEL, PID_KERNEL, directory.path, + directory.attribute, directory.owner_mode, + directory.group_mode, directory.other_mode); + if (result != FS::ResultCode::Success && result != FS::ResultCode::AlreadyExists) + ERROR_LOG(IOS_ES, "Failed to create %s: error %d", directory.path, FS::ConvertResult(result)); - // Create the directory if it does not exist. - if (File::IsDirectory(path)) - continue; - - File::CreateFullPath(path); - if (File::CreateDir(path)) - INFO_LOG(IOS_ES, "Created %s (at %s)", directory.path, path.c_str()); - else - ERROR_LOG(IOS_ES, "Failed to create %s (at %s)", directory.path, path.c_str()); - - // TODO: Set permissions. + // Now update the UID/GID and other attributes. + m_ios.GetFS()->SetMetadata(0, directory.path, directory.uid, directory.gid, directory.attribute, + directory.owner_mode, directory.group_mode, directory.other_mode); } FinishAllStaleImports(); diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index ec69c3e1fd..6a50d95047 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -617,7 +617,7 @@ u32 UIDSys::GetUIDFromTitle(u64 title_id) const u32 UIDSys::GetNextUID() const { if (m_entries.empty()) - return 0x00001000; + return FIRST_PPC_UID; return m_entries.rbegin()->first + 1; } diff --git a/Source/Core/Core/IOS/ES/Formats.h b/Source/Core/Core/IOS/ES/Formats.h index 1b1c1bbcb0..8dae59d1c6 100644 --- a/Source/Core/Core/IOS/ES/Formats.h +++ b/Source/Core/Core/IOS/ES/Formats.h @@ -271,6 +271,8 @@ private: std::shared_ptr m_fs; }; +constexpr u32 FIRST_PPC_UID = 0x1000; + class UIDSys final { public: