IOS/FS: Implement GetMetadata properly and remove GID hack

Now that all FS functions that create new inodes are properly
implemented, we can make GetMetadata actually return correct file
metadata rather than giving fixed information. The hack for the DQX
installer can also be removed now since our ES and FS keep track of
caller UID/GIDs now.
This commit is contained in:
Léo Lam 2019-12-29 13:56:48 +01:00
parent 396429d582
commit e4dd582d1d
1 changed files with 21 additions and 25 deletions

View File

@ -580,36 +580,32 @@ Result<std::vector<std::string>> HostFileSystem::ReadDirectory(Uid uid, Gid gid,
return output; return output;
} }
Result<Metadata> HostFileSystem::GetMetadata(Uid, Gid, const std::string& path) Result<Metadata> HostFileSystem::GetMetadata(Uid uid, Gid gid, const std::string& path)
{ {
Metadata metadata; const FstEntry* entry = nullptr;
metadata.uid = 0; if (path == "/")
metadata.gid = 0x3031; // this is also known as makercd, 01 (0x3031) for nintendo and 08 {
// (0x3038) for MH3 etc entry = &m_root_entry;
}
if (!IsValidPath(path)) else
{
if (!IsValidNonRootPath(path))
return ResultCode::Invalid; return ResultCode::Invalid;
std::string file_name = BuildFilename(path); const auto split_path = SplitPathAndBasename(path);
metadata.modes = {Mode::ReadWrite, Mode::ReadWrite, Mode::ReadWrite}; const FstEntry* parent = GetFstEntryForPath(split_path.parent);
metadata.attribute = 0x00; // no attributes if (!parent)
return ResultCode::NotFound;
// Hack: if the path that is being accessed is within an installed title directory, get the if (!parent->CheckPermission(uid, gid, Mode::Read))
// UID/GID from the installed title TMD. return ResultCode::AccessDenied;
Kernel* ios = GetIOS(); entry = GetFstEntryForPath(path);
u64 title_id;
if (ios && IsTitlePath(file_name, Common::FROM_SESSION_ROOT, &title_id))
{
IOS::ES::TMDReader tmd = ios->GetES()->FindInstalledTMD(title_id);
if (tmd.IsValid())
metadata.gid = tmd.GetGroupId();
} }
const File::FileInfo info{file_name}; if (!entry)
metadata.is_file = info.IsFile();
metadata.size = info.GetSize();
if (!info.Exists())
return ResultCode::NotFound; return ResultCode::NotFound;
Metadata metadata = entry->data;
metadata.size = File::GetSize(BuildFilename(path));
return metadata; return metadata;
} }