1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

kernel-explorer: devirtualize lv2_fs_object and print more information (#10487)

* Make lv2_fs_object an "abstract" structure with protected constructor.
* Improve kernel-explorer information for filesystem objects.
This commit is contained in:
Eladash 2021-06-24 16:47:14 +03:00 committed by GitHub
parent 3c614d95b8
commit 50be3bd2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 23 deletions

View File

@ -23,6 +23,55 @@ lv2_fs_mount_point g_mp_sys_dev_flash{"", 512, 8192, lv2_mp_flag::read_only + lv
lv2_fs_mount_point g_mp_sys_dev_flash2{ "", 512, 8192, lv2_mp_flag::no_uid_gid }; // TODO confirm
lv2_fs_mount_point g_mp_sys_dev_flash3{ "", 512, 8192, lv2_mp_flag::read_only + lv2_mp_flag::no_uid_gid }; // TODO confirm
template<>
void fmt_class_string<lv2_file>::format(std::string& out, u64 arg)
{
const auto& file = get_object(arg);
std::string_view type_s;
switch (file.type)
{
case lv2_file_type::regular: type_s = "Regular file"; break;
case lv2_file_type::sdata: type_s = "SDATA"; break;
case lv2_file_type::edata: type_s = "EDATA"; break;
}
auto get_size = [](u64 size) -> std::string
{
if (size == umax)
{
return "N/A";
}
std::string size_str = fmt::format("0x%05x ", size);
switch (std::bit_width(size) / 10 * 10)
{
case 64: size_str = "0"s; break;
case 0: fmt::append(size_str, "(%u)", size); break;
case 10: fmt::append(size_str, "(%gKB)", size / 1024.); break;
case 20: fmt::append(size_str, "(%gMB)", size / (1024. * 1024)); break;
default:
case 30: fmt::append(size_str, "(%gGB)", size / (1024. * 1024 * 1024)); break;
}
return size_str;
};
const usz pos = file.file ? file.file.pos() : umax;
const usz size = file.file ? file.file.size() : umax;
fmt::append(out, u8"%s, “%s”, Mode: 0x%x, Flags: 0x%x, Pos: %s, Size: %s", type_s, file.name.data(), file.mode, file.flags, get_size(pos), get_size(size));
}
template<>
void fmt_class_string<lv2_dir>::format(std::string& out, u64 arg)
{
const auto& dir = get_object(arg);
fmt::append(out, u8"Directory, “%s”, Entries: %u/%u", dir.name.data(), std::min<u64>(dir.pos, dir.entries.size()), dir.entries.size());
}
bool verify_mself(const fs::file& mself_file)
{
FsMselfHeader mself_header;

View File

@ -166,18 +166,18 @@ struct lv2_fs_object
// File Name (max 1055)
const std::array<char, 0x420> name;
protected:
lv2_fs_object(lv2_fs_mount_point* mp, std::string_view filename)
: mp(mp)
, name(get_name(filename))
{
}
public:
lv2_fs_object(const lv2_fs_object&) = delete;
lv2_fs_object& operator=(const lv2_fs_object&) = delete;
virtual ~lv2_fs_object() = default;
static lv2_fs_mount_point* get_mp(std::string_view filename);
static std::array<char, 0x420> get_name(std::string_view filename)
@ -193,8 +193,6 @@ struct lv2_fs_object
name[filename.size()] = 0;
return name;
}
virtual std::string to_string() const { return {}; }
};
struct lv2_file final : lv2_fs_object
@ -276,19 +274,6 @@ struct lv2_file final : lv2_fs_object
// Make file view from lv2_file object (for MSELF support)
static fs::file make_view(const std::shared_ptr<lv2_file>& _file, u64 offset);
virtual std::string to_string() const override
{
std::string_view type_s;
switch (type)
{
case lv2_file_type::regular: type_s = "Regular file"; break;
case lv2_file_type::sdata: type_s = "SDATA"; break;
case lv2_file_type::edata: type_s = "EDATA"; break;
}
return fmt::format(u8"%s, “%s”, Mode: 0x%x, Flags: 0x%x", type_s, name.data(), mode, flags);
}
};
struct lv2_dir final : lv2_fs_object
@ -314,11 +299,6 @@ struct lv2_dir final : lv2_fs_object
return nullptr;
}
virtual std::string to_string() const override
{
return fmt::format(u8"Directory, “%s”, Entries: %u/%u", name.data(), std::min<u64>(pos, entries.size()), entries.size());
}
};
// sys_fs_fcntl arg base class (left empty for PODness)

View File

@ -813,7 +813,22 @@ void kernel_explorer::Update()
idm::select<lv2_fs_object>([&](u32 id, lv2_fs_object& fo)
{
add_leaf(find_node(root, additional_nodes::file_descriptors), qstr(fmt::format("FD %u: %s", id, fo.to_string())));
const std::string str = fmt::format("FD %u: %s", id, [&]() -> std::string
{
if (idm::check_unlocked<lv2_fs_object, lv2_file>(id))
{
return fmt::format("%s", static_cast<lv2_file&>(fo));
}
if (idm::check_unlocked<lv2_fs_object, lv2_dir>(id))
{
return fmt::format("%s", static_cast<lv2_dir&>(fo));
}
return "Unknown object!";
}());
add_leaf(find_node(root, additional_nodes::file_descriptors), qstr(str));
});
std::function<int(QTreeWidgetItem*)> final_touches;