mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-12 01:47:00 +02:00
There's no point in constructing an object just for the sake of keeping a state that can be touched by anything in the kernel code. Let's reduce everything to be in a C++ namespace called with the previous name "VirtualFileSystem" and keep a smaller textual-footprint struct called "VirtualFileSystemDetails". This change also cleans up old "friend class" statements that were no longer needed, and move methods from the VirtualFileSystem code to more appropriate places as well. Please note that the method of locking all filesystems during shutdown is removed, as in that place there's no meaning to actually locking all filesystems because of running in kernel mode entirely.
71 lines
2.7 KiB
C++
71 lines
2.7 KiB
C++
/*
|
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/JsonObjectSerializer.h>
|
|
#include <Kernel/API/POSIX/unistd.h>
|
|
#include <Kernel/Devices/Loop/LoopDevice.h>
|
|
#include <Kernel/FileSystem/FileBackedFileSystem.h>
|
|
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/DiskUsage.h>
|
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
|
#include <Kernel/Sections.h>
|
|
#include <Kernel/Tasks/Process.h>
|
|
|
|
namespace Kernel {
|
|
|
|
UNMAP_AFTER_INIT NonnullRefPtr<SysFSDiskUsage> SysFSDiskUsage::must_create(SysFSDirectory const& parent_directory)
|
|
{
|
|
return adopt_ref_if_nonnull(new (nothrow) SysFSDiskUsage(parent_directory)).release_nonnull();
|
|
}
|
|
|
|
UNMAP_AFTER_INIT SysFSDiskUsage::SysFSDiskUsage(SysFSDirectory const& parent_directory)
|
|
: SysFSGlobalInformation(parent_directory)
|
|
{
|
|
}
|
|
|
|
ErrorOr<void> SysFSDiskUsage::try_generate(KBufferBuilder& builder)
|
|
{
|
|
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
|
TRY(Process::current().vfs_root_context()->for_each_mount([&array](auto& mount) -> ErrorOr<void> {
|
|
auto& fs = mount.guest_fs();
|
|
auto fs_object = TRY(array.add_object());
|
|
TRY(fs_object.add("class_name"sv, fs.class_name()));
|
|
TRY(fs_object.add("total_block_count"sv, fs.total_block_count()));
|
|
TRY(fs_object.add("free_block_count"sv, fs.free_block_count()));
|
|
TRY(fs_object.add("total_inode_count"sv, fs.total_inode_count()));
|
|
TRY(fs_object.add("free_inode_count"sv, fs.free_inode_count()));
|
|
auto mount_point = TRY(mount.absolute_path());
|
|
TRY(fs_object.add("mount_point"sv, mount_point->view()));
|
|
TRY(fs_object.add("block_size"sv, static_cast<u64>(fs.logical_block_size())));
|
|
TRY(fs_object.add("readonly"sv, fs.is_readonly()));
|
|
TRY(fs_object.add("mount_flags"sv, mount.flags()));
|
|
|
|
if (mount.flags() & MS_SRCHIDDEN) {
|
|
TRY(fs_object.add("source"sv, "unknown"));
|
|
} else {
|
|
if (fs.is_file_backed()) {
|
|
auto& file = static_cast<FileBackedFileSystem const&>(fs).file();
|
|
if (file.is_loop_device()) {
|
|
auto& device = static_cast<LoopDevice const&>(file);
|
|
auto path = TRY(device.custody().try_serialize_absolute_path());
|
|
TRY(fs_object.add("source"sv, path->view()));
|
|
} else {
|
|
auto pseudo_path = TRY(static_cast<FileBackedFileSystem const&>(fs).file_description().pseudo_path());
|
|
TRY(fs_object.add("source"sv, pseudo_path->view()));
|
|
}
|
|
} else {
|
|
TRY(fs_object.add("source"sv, "none"));
|
|
}
|
|
}
|
|
|
|
TRY(fs_object.finish());
|
|
return {};
|
|
}));
|
|
TRY(array.finish());
|
|
return {};
|
|
}
|
|
|
|
}
|