1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 18:28:10 +00:00

Kernel: Replace "folder" => "directory" everywhere

Folders are a GUI concept. File systems have directories.
This commit is contained in:
Andreas Kling 2021-07-17 23:15:52 +02:00
parent 22611ca136
commit 2da0581fd2
15 changed files with 246 additions and 246 deletions

View file

@ -61,12 +61,12 @@ UNMAP_AFTER_INIT ACPISysFSComponent::ACPISysFSComponent(String name, PhysicalAdd
UNMAP_AFTER_INIT void ACPISysFSDirectory::initialize() UNMAP_AFTER_INIT void ACPISysFSDirectory::initialize()
{ {
auto acpi_folder = adopt_ref(*new (nothrow) ACPISysFSDirectory()); auto acpi_directory = adopt_ref(*new (nothrow) ACPISysFSDirectory());
SysFSComponentRegistry::the().register_new_component(acpi_folder); SysFSComponentRegistry::the().register_new_component(acpi_directory);
} }
UNMAP_AFTER_INIT ACPISysFSDirectory::ACPISysFSDirectory() UNMAP_AFTER_INIT ACPISysFSDirectory::ACPISysFSDirectory()
: SysFSDirectory("acpi", SysFSComponentRegistry::the().root_folder()) : SysFSDirectory("acpi", SysFSComponentRegistry::the().root_directory())
{ {
NonnullRefPtrVector<SysFSComponent> components; NonnullRefPtrVector<SysFSComponent> components;
size_t ssdt_count = 0; size_t ssdt_count = 0;

View file

@ -95,9 +95,9 @@ UNMAP_AFTER_INIT void BIOSSysFSDirectory::set_dmi_32_bit_entry_initialization_va
UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize() UNMAP_AFTER_INIT void BIOSSysFSDirectory::initialize()
{ {
auto bios_folder = adopt_ref(*new (nothrow) BIOSSysFSDirectory()); auto bios_directory = adopt_ref(*new (nothrow) BIOSSysFSDirectory());
SysFSComponentRegistry::the().register_new_component(bios_folder); SysFSComponentRegistry::the().register_new_component(bios_directory);
bios_folder->create_components(); bios_directory->create_components();
} }
void BIOSSysFSDirectory::create_components() void BIOSSysFSDirectory::create_components()
@ -135,7 +135,7 @@ OwnPtr<KBuffer> BIOSSysFSDirectory::smbios_structure_table() const
} }
UNMAP_AFTER_INIT BIOSSysFSDirectory::BIOSSysFSDirectory() UNMAP_AFTER_INIT BIOSSysFSDirectory::BIOSSysFSDirectory()
: SysFSDirectory("bios", SysFSComponentRegistry::the().root_folder()) : SysFSDirectory("bios", SysFSComponentRegistry::the().root_directory())
{ {
auto entry_32bit = find_dmi_entry32bit_point(); auto entry_32bit = find_dmi_entry32bit_point();
m_dmi_entry_point = entry_32bit.value(); m_dmi_entry_point = entry_32bit.value();

View file

@ -368,13 +368,13 @@ void Capability::write32(u32 field, u32 value)
PCI::write32(m_address, m_ptr + field, value); PCI::write32(m_address, m_ptr + field, value);
} }
UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(const SysFSDirectory& parent_folder, Address address) UNMAP_AFTER_INIT NonnullRefPtr<PCIDeviceSysFSDirectory> PCIDeviceSysFSDirectory::create(const SysFSDirectory& parent_directory, Address address)
{ {
return adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(parent_folder, address)); return adopt_ref(*new (nothrow) PCIDeviceSysFSDirectory(parent_directory, address));
} }
UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(const SysFSDirectory& parent_folder, Address address) UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(const SysFSDirectory& parent_directory, Address address)
: SysFSDirectory(String::formatted("{:04x}:{:04x}:{:02x}.{}", address.seg(), address.bus(), address.device(), address.function()), parent_folder) : SysFSDirectory(String::formatted("{:04x}:{:04x}:{:02x}.{}", address.seg(), address.bus(), address.device(), address.function()), parent_directory)
{ {
m_components.append(PCIDeviceAttributeSysFSComponent::create("vendor", *this, PCI_VENDOR_ID, 2)); m_components.append(PCIDeviceAttributeSysFSComponent::create("vendor", *this, PCI_VENDOR_ID, 2));
m_components.append(PCIDeviceAttributeSysFSComponent::create("device_id", *this, PCI_DEVICE_ID, 2)); m_components.append(PCIDeviceAttributeSysFSComponent::create("device_id", *this, PCI_DEVICE_ID, 2));
@ -388,12 +388,12 @@ UNMAP_AFTER_INIT PCIDeviceSysFSDirectory::PCIDeviceSysFSDirectory(const SysFSDir
UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize() UNMAP_AFTER_INIT void PCIBusSysFSDirectory::initialize()
{ {
auto pci_folder = adopt_ref(*new (nothrow) PCIBusSysFSDirectory()); auto pci_directory = adopt_ref(*new (nothrow) PCIBusSysFSDirectory());
SysFSComponentRegistry::the().register_new_component(pci_folder); SysFSComponentRegistry::the().register_new_component(pci_directory);
} }
UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory() UNMAP_AFTER_INIT PCIBusSysFSDirectory::PCIBusSysFSDirectory()
: SysFSDirectory("pci", SysFSComponentRegistry::the().root_folder()) : SysFSDirectory("pci", SysFSComponentRegistry::the().root_directory())
{ {
PCI::enumerate([&](const Address& address, ID) { PCI::enumerate([&](const Address& address, ID) {
auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, address); auto pci_device = PCI::PCIDeviceSysFSDirectory::create(*this, address);

View file

@ -70,7 +70,7 @@ static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128;
static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024; static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024;
class ProcFSUSBBusDirectory; class ProcFSUSBBusDirectory;
static ProcFSUSBBusDirectory* s_procfs_usb_bus_folder; static ProcFSUSBBusDirectory* s_procfs_usb_bus_directory;
class ProcFSUSBDeviceInformation : public ProcFSGlobalInformation { class ProcFSUSBDeviceInformation : public ProcFSGlobalInformation {
friend class ProcFSUSBBusDirectory; friend class ProcFSUSBBusDirectory;
@ -144,11 +144,11 @@ KResultOr<size_t> ProcFSUSBBusDirectory::entries_count() const
KResult ProcFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult ProcFSUSBBusDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{ {
ScopedSpinLock lock(m_lock); ScopedSpinLock lock(m_lock);
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
// Note: if the parent folder is null, it means something bad happened as this should not happen for the USB folder. // Note: if the parent directory is null, it means something bad happened as this should not happen for the USB directory.
VERIFY(parent_folder); VERIFY(parent_directory);
callback({ ".", { fsid, component_index() }, 0 }); callback({ ".", { fsid, component_index() }, 0 });
callback({ "..", { fsid, parent_folder->component_index() }, 0 }); callback({ "..", { fsid, parent_directory->component_index() }, 0 });
for (auto& device_node : m_device_nodes) { for (auto& device_node : m_device_nodes) {
InodeIdentifier identifier = { fsid, device_node.component_index() }; InodeIdentifier identifier = { fsid, device_node.component_index() };
@ -192,16 +192,16 @@ void ProcFSUSBBusDirectory::unplug(USB::Device& deleted_device)
device_node->m_list_node.remove(); device_node->m_list_node.remove();
} }
UNMAP_AFTER_INIT ProcFSUSBBusDirectory::ProcFSUSBBusDirectory(const ProcFSBusDirectory& buses_folder) UNMAP_AFTER_INIT ProcFSUSBBusDirectory::ProcFSUSBBusDirectory(const ProcFSBusDirectory& buses_directory)
: ProcFSExposedDirectory("usb"sv, buses_folder) : ProcFSExposedDirectory("usb"sv, buses_directory)
{ {
} }
UNMAP_AFTER_INIT void ProcFSUSBBusDirectory::initialize() UNMAP_AFTER_INIT void ProcFSUSBBusDirectory::initialize()
{ {
auto folder = adopt_ref(*new ProcFSUSBBusDirectory(ProcFSComponentRegistry::the().buses_folder())); auto directory = adopt_ref(*new ProcFSUSBBusDirectory(ProcFSComponentRegistry::the().buses_directory()));
ProcFSComponentRegistry::the().register_new_bus_folder(folder); ProcFSComponentRegistry::the().register_new_bus_directory(directory);
s_procfs_usb_bus_folder = folder; s_procfs_usb_bus_directory = directory;
} }
NonnullRefPtr<ProcFSUSBDeviceInformation> ProcFSUSBDeviceInformation::create(USB::Device& device) NonnullRefPtr<ProcFSUSBDeviceInformation> ProcFSUSBDeviceInformation::create(USB::Device& device)
@ -717,14 +717,14 @@ void UHCIController::spawn_port_proc()
dmesgln("UHCI: Device creation failed on port 1 ({})", device.error()); dmesgln("UHCI: Device creation failed on port 1 ({})", device.error());
m_devices.at(0) = device.value(); m_devices.at(0) = device.value();
VERIFY(s_procfs_usb_bus_folder); VERIFY(s_procfs_usb_bus_directory);
s_procfs_usb_bus_folder->plug(device.value()); s_procfs_usb_bus_directory->plug(device.value());
} else { } else {
// FIXME: Clean up (and properly) the RefPtr to the device in m_devices // FIXME: Clean up (and properly) the RefPtr to the device in m_devices
VERIFY(s_procfs_usb_bus_folder); VERIFY(s_procfs_usb_bus_directory);
VERIFY(m_devices.at(0)); VERIFY(m_devices.at(0));
dmesgln("UHCI: Device detach detected on Root Port 1"); dmesgln("UHCI: Device detach detected on Root Port 1");
s_procfs_usb_bus_folder->unplug(*m_devices.at(0)); s_procfs_usb_bus_directory->unplug(*m_devices.at(0));
} }
} }
} else { } else {
@ -755,14 +755,14 @@ void UHCIController::spawn_port_proc()
dmesgln("UHCI: Device creation failed on port 2 ({})", device.error()); dmesgln("UHCI: Device creation failed on port 2 ({})", device.error());
m_devices.at(1) = device.value(); m_devices.at(1) = device.value();
VERIFY(s_procfs_usb_bus_folder); VERIFY(s_procfs_usb_bus_directory);
s_procfs_usb_bus_folder->plug(device.value()); s_procfs_usb_bus_directory->plug(device.value());
} else { } else {
// FIXME: Clean up (and properly) the RefPtr to the device in m_devices // FIXME: Clean up (and properly) the RefPtr to the device in m_devices
VERIFY(s_procfs_usb_bus_folder); VERIFY(s_procfs_usb_bus_directory);
VERIFY(m_devices.at(1)); VERIFY(m_devices.at(1));
dmesgln("UHCI: Device detach detected on Root Port 2"); dmesgln("UHCI: Device detach detected on Root Port 2");
s_procfs_usb_bus_folder->unplug(*m_devices.at(1)); s_procfs_usb_bus_directory->unplug(*m_devices.at(1));
} }
} }
} }

View file

@ -227,9 +227,9 @@ KResult DevFSRootDirectoryInode::traverse_as_directory(Function<bool(FileSystem:
callback({ ".", identifier(), 0 }); callback({ ".", identifier(), 0 });
callback({ "..", identifier(), 0 }); callback({ "..", identifier(), 0 });
for (auto& folder : m_subfolders) { for (auto& directory : m_subdirectories) {
InodeIdentifier identifier = { fsid(), folder.index() }; InodeIdentifier identifier = { fsid(), directory.index() };
callback({ folder.name(), identifier, 0 }); callback({ directory.name(), identifier, 0 });
} }
for (auto& link : m_links) { for (auto& link : m_links) {
InodeIdentifier identifier = { fsid(), link.index() }; InodeIdentifier identifier = { fsid(), link.index() };
@ -245,9 +245,9 @@ KResult DevFSRootDirectoryInode::traverse_as_directory(Function<bool(FileSystem:
RefPtr<Inode> DevFSRootDirectoryInode::lookup(StringView name) RefPtr<Inode> DevFSRootDirectoryInode::lookup(StringView name)
{ {
Locker locker(m_parent_fs.m_lock); Locker locker(m_parent_fs.m_lock);
for (auto& subfolder : m_subfolders) { for (auto& subdirectory : m_subdirectories) {
if (subfolder.name() == name) if (subdirectory.name() == name)
return subfolder; return subdirectory;
} }
for (auto& link : m_links) { for (auto& link : m_links) {
if (link.name() == name) if (link.name() == name)
@ -268,8 +268,8 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView
InodeMetadata metadata; InodeMetadata metadata;
metadata.mode = mode; metadata.mode = mode;
if (metadata.is_directory()) { if (metadata.is_directory()) {
for (auto& folder : m_subfolders) { for (auto& directory : m_subdirectories) {
if (folder.name() == name) if (directory.name() == name)
return EEXIST; return EEXIST;
} }
if (name != "pts") if (name != "pts")
@ -277,11 +277,11 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView
auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs)); auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs));
if (!new_directory_inode) if (!new_directory_inode)
return ENOMEM; return ENOMEM;
if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1)) if (!m_subdirectories.try_ensure_capacity(m_subdirectories.size() + 1))
return ENOMEM; return ENOMEM;
if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1)) if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1))
return ENOMEM; return ENOMEM;
m_subfolders.append(*new_directory_inode); m_subdirectories.append(*new_directory_inode);
m_parent_fs.m_nodes.append(*new_directory_inode); m_parent_fs.m_nodes.append(*new_directory_inode);
return KResult(KSuccess); return KResult(KSuccess);
} }

View file

@ -151,7 +151,7 @@ private:
virtual RefPtr<Inode> lookup(StringView name) override; virtual RefPtr<Inode> lookup(StringView name) override;
virtual InodeMetadata metadata() const override; virtual InodeMetadata metadata() const override;
NonnullRefPtrVector<DevFSDirectoryInode> m_subfolders; NonnullRefPtrVector<DevFSDirectoryInode> m_subdirectories;
NonnullRefPtrVector<DevFSLinkInode> m_links; NonnullRefPtrVector<DevFSLinkInode> m_links;
DevFS& m_parent_fs; DevFS& m_parent_fs;
}; };

View file

@ -32,33 +32,33 @@ UNMAP_AFTER_INIT void ProcFSComponentRegistry::initialize()
} }
UNMAP_AFTER_INIT ProcFSComponentRegistry::ProcFSComponentRegistry() UNMAP_AFTER_INIT ProcFSComponentRegistry::ProcFSComponentRegistry()
: m_root_folder(ProcFSRootDirectory::must_create()) : m_root_directory(ProcFSRootDirectory::must_create())
{ {
} }
const ProcFSBusDirectory& ProcFSComponentRegistry::buses_folder() const const ProcFSBusDirectory& ProcFSComponentRegistry::buses_directory() const
{ {
return *m_root_folder->m_buses_folder; return *m_root_directory->m_buses_directory;
} }
void ProcFSComponentRegistry::register_new_bus_folder(ProcFSExposedDirectory& new_bus_folder) void ProcFSComponentRegistry::register_new_bus_directory(ProcFSExposedDirectory& new_bus_directory)
{ {
VERIFY(!m_root_folder->m_buses_folder.is_null()); VERIFY(!m_root_directory->m_buses_directory.is_null());
m_root_folder->m_buses_folder->m_components.append(new_bus_folder); m_root_directory->m_buses_directory->m_components.append(new_bus_directory);
} }
void ProcFSComponentRegistry::register_new_process(Process& new_process) void ProcFSComponentRegistry::register_new_process(Process& new_process)
{ {
Locker locker(m_lock); Locker locker(m_lock);
m_root_folder->m_process_folders.append(ProcFSProcessDirectory::create(new_process)); m_root_directory->m_process_directories.append(ProcFSProcessDirectory::create(new_process));
} }
void ProcFSComponentRegistry::unregister_process(Process& deleted_process) void ProcFSComponentRegistry::unregister_process(Process& deleted_process)
{ {
auto process_folder = m_root_folder->process_folder_for(deleted_process).release_nonnull(); auto process_directory = m_root_directory->process_directory_for(deleted_process).release_nonnull();
process_folder->prepare_for_deletion(); process_directory->prepare_for_deletion();
process_folder->m_list_node.remove(); process_directory->m_list_node.remove();
dbgln_if(PROCFS_DEBUG, "ProcFSExposedDirectory ref_count now: {}", process_folder->ref_count()); dbgln_if(PROCFS_DEBUG, "ProcFSExposedDirectory ref_count now: {}", process_directory->ref_count());
} }
RefPtr<ProcFS> ProcFS::create() RefPtr<ProcFS> ProcFS::create()
@ -112,7 +112,7 @@ ProcFSInode::~ProcFSInode()
} }
ProcFS::ProcFS() ProcFS::ProcFS()
: m_root_inode(ProcFSComponentRegistry::the().root_folder().to_inode(*this)) : m_root_inode(ProcFSComponentRegistry::the().root_directory().to_inode(*this))
{ {
} }

View file

@ -25,14 +25,14 @@ UNMAP_AFTER_INIT void SysFSComponentRegistry::initialize()
} }
UNMAP_AFTER_INIT SysFSComponentRegistry::SysFSComponentRegistry() UNMAP_AFTER_INIT SysFSComponentRegistry::SysFSComponentRegistry()
: m_root_folder(SysFSRootDirectory::create()) : m_root_directory(SysFSRootDirectory::create())
{ {
} }
UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component) UNMAP_AFTER_INIT void SysFSComponentRegistry::register_new_component(SysFSComponent& component)
{ {
Locker locker(m_lock); Locker locker(m_lock);
m_root_folder->m_components.append(component); m_root_directory->m_components.append(component);
} }
NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create() NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create()
@ -64,7 +64,7 @@ NonnullRefPtr<SysFS> SysFS::create()
} }
SysFS::SysFS() SysFS::SysFS()
: m_root_inode(SysFSComponentRegistry::the().root_folder().to_inode(*this)) : m_root_inode(SysFSComponentRegistry::the().root_directory().to_inode(*this))
{ {
} }

View file

@ -32,12 +32,12 @@ public:
SysFSComponentRegistry(); SysFSComponentRegistry();
void register_new_component(SysFSComponent&); void register_new_component(SysFSComponent&);
SysFSDirectory& root_folder() { return m_root_folder; } SysFSDirectory& root_directory() { return m_root_directory; }
Mutex& get_lock() { return m_lock; } Mutex& get_lock() { return m_lock; }
private: private:
Mutex m_lock; Mutex m_lock;
NonnullRefPtr<SysFSRootDirectory> m_root_folder; NonnullRefPtr<SysFSRootDirectory> m_root_directory;
}; };
class SysFS final : public FileSystem { class SysFS final : public FileSystem {

View file

@ -29,9 +29,9 @@ SysFSComponent::SysFSComponent(StringView name)
KResult SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult SysFSDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{ {
Locker locker(SysFSComponentRegistry::the().get_lock()); Locker locker(SysFSComponentRegistry::the().get_lock());
VERIFY(m_parent_folder); VERIFY(m_parent_directory);
callback({ ".", { fsid, component_index() }, 0 }); callback({ ".", { fsid, component_index() }, 0 });
callback({ "..", { fsid, m_parent_folder->component_index() }, 0 }); callback({ "..", { fsid, m_parent_directory->component_index() }, 0 });
for (auto& component : m_components) { for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() }; InodeIdentifier identifier = { fsid, component.component_index() };
@ -55,9 +55,9 @@ SysFSDirectory::SysFSDirectory(StringView name)
{ {
} }
SysFSDirectory::SysFSDirectory(StringView name, SysFSDirectory const& parent_folder) SysFSDirectory::SysFSDirectory(StringView name, SysFSDirectory const& parent_directory)
: SysFSComponent(name) : SysFSComponent(name)
, m_parent_folder(parent_folder) , m_parent_directory(parent_directory)
{ {
} }

View file

@ -52,9 +52,9 @@ public:
protected: protected:
explicit SysFSDirectory(StringView name); explicit SysFSDirectory(StringView name);
SysFSDirectory(StringView name, SysFSDirectory const& parent_folder); SysFSDirectory(StringView name, SysFSDirectory const& parent_directory);
NonnullRefPtrVector<SysFSComponent> m_components; NonnullRefPtrVector<SysFSComponent> m_components;
RefPtr<SysFSDirectory> m_parent_folder; RefPtr<SysFSDirectory> m_parent_directory;
}; };
} }

View file

@ -160,18 +160,18 @@ private:
class ProcFSNetworkDirectory : public ProcFSExposedDirectory { class ProcFSNetworkDirectory : public ProcFSExposedDirectory {
public: public:
static NonnullRefPtr<ProcFSNetworkDirectory> must_create(const ProcFSRootDirectory& parent_folder); static NonnullRefPtr<ProcFSNetworkDirectory> must_create(const ProcFSRootDirectory& parent_directory);
private: private:
ProcFSNetworkDirectory(const ProcFSRootDirectory& parent_folder); ProcFSNetworkDirectory(const ProcFSRootDirectory& parent_directory);
}; };
class ProcFSSystemDirectory : public ProcFSExposedDirectory { class ProcFSSystemDirectory : public ProcFSExposedDirectory {
public: public:
static NonnullRefPtr<ProcFSSystemDirectory> must_create(const ProcFSRootDirectory& parent_folder); static NonnullRefPtr<ProcFSSystemDirectory> must_create(const ProcFSRootDirectory& parent_directory);
private: private:
ProcFSSystemDirectory(const ProcFSRootDirectory& parent_folder); ProcFSSystemDirectory(const ProcFSRootDirectory& parent_directory);
}; };
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSAdapters> ProcFSAdapters::must_create() UNMAP_AFTER_INIT NonnullRefPtr<ProcFSAdapters> ProcFSAdapters::must_create()
@ -195,15 +195,15 @@ UNMAP_AFTER_INIT NonnullRefPtr<ProcFSUDP> ProcFSUDP::must_create()
return adopt_ref_if_nonnull(new (nothrow) ProcFSUDP).release_nonnull(); return adopt_ref_if_nonnull(new (nothrow) ProcFSUDP).release_nonnull();
} }
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSNetworkDirectory> ProcFSNetworkDirectory::must_create(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT NonnullRefPtr<ProcFSNetworkDirectory> ProcFSNetworkDirectory::must_create(const ProcFSRootDirectory& parent_directory)
{ {
auto folder = adopt_ref(*new (nothrow) ProcFSNetworkDirectory(parent_folder)); auto directory = adopt_ref(*new (nothrow) ProcFSNetworkDirectory(parent_directory));
folder->m_components.append(ProcFSAdapters::must_create()); directory->m_components.append(ProcFSAdapters::must_create());
folder->m_components.append(ProcFSARP::must_create()); directory->m_components.append(ProcFSARP::must_create());
folder->m_components.append(ProcFSTCP::must_create()); directory->m_components.append(ProcFSTCP::must_create());
folder->m_components.append(ProcFSLocalNet::must_create()); directory->m_components.append(ProcFSLocalNet::must_create());
folder->m_components.append(ProcFSUDP::must_create()); directory->m_components.append(ProcFSUDP::must_create());
return folder; return directory;
} }
UNMAP_AFTER_INIT ProcFSAdapters::ProcFSAdapters() UNMAP_AFTER_INIT ProcFSAdapters::ProcFSAdapters()
@ -226,8 +226,8 @@ UNMAP_AFTER_INIT ProcFSUDP::ProcFSUDP()
: ProcFSGlobalInformation("udp"sv) : ProcFSGlobalInformation("udp"sv)
{ {
} }
UNMAP_AFTER_INIT ProcFSNetworkDirectory::ProcFSNetworkDirectory(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT ProcFSNetworkDirectory::ProcFSNetworkDirectory(const ProcFSRootDirectory& parent_directory)
: ProcFSExposedDirectory("net"sv, parent_folder) : ProcFSExposedDirectory("net"sv, parent_directory)
{ {
} }
@ -813,54 +813,54 @@ UNMAP_AFTER_INIT ProcFSProfile::ProcFSProfile()
{ {
} }
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSBusDirectory> ProcFSBusDirectory::must_create(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT NonnullRefPtr<ProcFSBusDirectory> ProcFSBusDirectory::must_create(const ProcFSRootDirectory& parent_directory)
{ {
auto folder = adopt_ref(*new (nothrow) ProcFSBusDirectory(parent_folder)); auto directory = adopt_ref(*new (nothrow) ProcFSBusDirectory(parent_directory));
return folder; return directory;
} }
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemDirectory> ProcFSSystemDirectory::must_create(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT NonnullRefPtr<ProcFSSystemDirectory> ProcFSSystemDirectory::must_create(const ProcFSRootDirectory& parent_directory)
{ {
auto folder = adopt_ref(*new (nothrow) ProcFSSystemDirectory(parent_folder)); auto directory = adopt_ref(*new (nothrow) ProcFSSystemDirectory(parent_directory));
folder->m_components.append(ProcFSDumpKmallocStacks::must_create(folder)); directory->m_components.append(ProcFSDumpKmallocStacks::must_create(directory));
folder->m_components.append(ProcFSUBSanDeadly::must_create(folder)); directory->m_components.append(ProcFSUBSanDeadly::must_create(directory));
folder->m_components.append(ProcFSCapsLockRemap::must_create(folder)); directory->m_components.append(ProcFSCapsLockRemap::must_create(directory));
return folder; return directory;
} }
UNMAP_AFTER_INIT ProcFSBusDirectory::ProcFSBusDirectory(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT ProcFSBusDirectory::ProcFSBusDirectory(const ProcFSRootDirectory& parent_directory)
: ProcFSExposedDirectory("bus"sv, parent_folder) : ProcFSExposedDirectory("bus"sv, parent_directory)
{ {
} }
UNMAP_AFTER_INIT ProcFSSystemDirectory::ProcFSSystemDirectory(const ProcFSRootDirectory& parent_folder) UNMAP_AFTER_INIT ProcFSSystemDirectory::ProcFSSystemDirectory(const ProcFSRootDirectory& parent_directory)
: ProcFSExposedDirectory("sys"sv, parent_folder) : ProcFSExposedDirectory("sys"sv, parent_directory)
{ {
} }
UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRootDirectory> ProcFSRootDirectory::must_create() UNMAP_AFTER_INIT NonnullRefPtr<ProcFSRootDirectory> ProcFSRootDirectory::must_create()
{ {
auto folder = adopt_ref(*new (nothrow) ProcFSRootDirectory); auto directory = adopt_ref(*new (nothrow) ProcFSRootDirectory);
folder->m_components.append(ProcFSSelfProcessDirectory::must_create()); directory->m_components.append(ProcFSSelfProcessDirectory::must_create());
folder->m_components.append(ProcFSDiskUsage::must_create()); directory->m_components.append(ProcFSDiskUsage::must_create());
folder->m_components.append(ProcFSMemoryStatus::must_create()); directory->m_components.append(ProcFSMemoryStatus::must_create());
folder->m_components.append(ProcFSOverallProcesses::must_create()); directory->m_components.append(ProcFSOverallProcesses::must_create());
folder->m_components.append(ProcFSCPUInformation::must_create()); directory->m_components.append(ProcFSCPUInformation::must_create());
folder->m_components.append(ProcFSDmesg::must_create()); directory->m_components.append(ProcFSDmesg::must_create());
folder->m_components.append(ProcFSInterrupts::must_create()); directory->m_components.append(ProcFSInterrupts::must_create());
folder->m_components.append(ProcFSKeymap::must_create()); directory->m_components.append(ProcFSKeymap::must_create());
folder->m_components.append(ProcFSPCI::must_create()); directory->m_components.append(ProcFSPCI::must_create());
folder->m_components.append(ProcFSDevices::must_create()); directory->m_components.append(ProcFSDevices::must_create());
folder->m_components.append(ProcFSUptime::must_create()); directory->m_components.append(ProcFSUptime::must_create());
folder->m_components.append(ProcFSCommandLine::must_create()); directory->m_components.append(ProcFSCommandLine::must_create());
folder->m_components.append(ProcFSModules::must_create()); directory->m_components.append(ProcFSModules::must_create());
folder->m_components.append(ProcFSProfile::must_create()); directory->m_components.append(ProcFSProfile::must_create());
folder->m_components.append(ProcFSNetworkDirectory::must_create(*folder)); directory->m_components.append(ProcFSNetworkDirectory::must_create(*directory));
auto buses_folder = ProcFSBusDirectory::must_create(*folder); auto buses_directory = ProcFSBusDirectory::must_create(*directory);
folder->m_components.append(buses_folder); directory->m_components.append(buses_directory);
folder->m_buses_folder = buses_folder; directory->m_buses_directory = buses_directory;
folder->m_components.append(ProcFSSystemDirectory::must_create(*folder)); directory->m_components.append(ProcFSSystemDirectory::must_create(*directory));
return folder; return directory;
} }
KResult ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
@ -873,7 +873,7 @@ KResult ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(
InodeIdentifier identifier = { fsid, component.component_index() }; InodeIdentifier identifier = { fsid, component.component_index() };
callback({ component.name(), identifier, 0 }); callback({ component.name(), identifier, 0 });
} }
for (auto& component : m_process_folders) { for (auto& component : m_process_directories) {
InodeIdentifier identifier = { fsid, component.component_index() }; InodeIdentifier identifier = { fsid, component.component_index() };
callback({ component.name(), identifier, 0 }); callback({ component.name(), identifier, 0 });
} }
@ -885,7 +885,7 @@ RefPtr<ProcFSExposedComponent> ProcFSRootDirectory::lookup(StringView name)
if (auto candidate = ProcFSExposedDirectory::lookup(name); !candidate.is_null()) if (auto candidate = ProcFSExposedDirectory::lookup(name); !candidate.is_null())
return candidate; return candidate;
for (auto& component : m_process_folders) { for (auto& component : m_process_directories) {
if (component.name() == name) { if (component.name() == name) {
return component; return component;
} }
@ -902,12 +902,12 @@ UNMAP_AFTER_INIT ProcFSRootDirectory::~ProcFSRootDirectory()
{ {
} }
RefPtr<ProcFSProcessDirectory> ProcFSRootDirectory::process_folder_for(Process& process) RefPtr<ProcFSProcessDirectory> ProcFSRootDirectory::process_directory_for(Process& process)
{ {
RefPtr<Process> checked_process = process; RefPtr<Process> checked_process = process;
for (auto& folder : m_process_folders) { for (auto& directory : m_process_directories) {
if (folder.associated_process().ptr() == checked_process.ptr()) if (directory.associated_process().ptr() == checked_process.ptr())
return folder; return directory;
} }
return {}; return {};
} }

View file

@ -52,9 +52,9 @@ ProcFSExposedDirectory::ProcFSExposedDirectory(StringView name)
{ {
} }
ProcFSExposedDirectory::ProcFSExposedDirectory(StringView name, const ProcFSExposedDirectory& parent_folder) ProcFSExposedDirectory::ProcFSExposedDirectory(StringView name, const ProcFSExposedDirectory& parent_directory)
: ProcFSExposedComponent(name) : ProcFSExposedComponent(name)
, m_parent_folder(parent_folder) , m_parent_directory(parent_directory)
{ {
} }
@ -157,10 +157,10 @@ KResult ProcFSProcessInformation::refresh_data(FileDescription& description) con
// For process-specific inodes, hold the process's ptrace lock across refresh // For process-specific inodes, hold the process's ptrace lock across refresh
// and refuse to load data if the process is not dumpable. // and refuse to load data if the process is not dumpable.
// Without this, files opened before a process went non-dumpable could still be used for dumping. // Without this, files opened before a process went non-dumpable could still be used for dumping.
auto parent_folder = const_cast<ProcFSProcessInformation&>(*this).m_parent_folder.strong_ref(); auto parent_directory = const_cast<ProcFSProcessInformation&>(*this).m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return KResult(EINVAL); return KResult(EINVAL);
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (!process) if (!process)
return KResult(ESRCH); return KResult(ESRCH);
process->ptrace_lock().lock(); process->ptrace_lock().lock();
@ -245,11 +245,11 @@ RefPtr<ProcFSExposedComponent> ProcFSExposedDirectory::lookup(StringView name)
KResult ProcFSExposedDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult ProcFSExposedDirectory::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{ {
Locker locker(ProcFSComponentRegistry::the().get_lock()); Locker locker(ProcFSComponentRegistry::the().get_lock());
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return KResult(EINVAL); return KResult(EINVAL);
callback({ ".", { fsid, component_index() }, 0 }); callback({ ".", { fsid, component_index() }, 0 });
callback({ "..", { fsid, parent_folder->component_index() }, 0 }); callback({ "..", { fsid, parent_directory->component_index() }, 0 });
for (auto& component : m_components) { for (auto& component : m_components) {
InodeIdentifier identifier = { fsid, component.component_index() }; InodeIdentifier identifier = { fsid, component.component_index() };

View file

@ -30,19 +30,19 @@ public:
InodeIndex allocate_inode_index() const; InodeIndex allocate_inode_index() const;
ProcFSComponentRegistry(); ProcFSComponentRegistry();
void register_new_bus_folder(ProcFSExposedDirectory&); void register_new_bus_directory(ProcFSExposedDirectory&);
const ProcFSBusDirectory& buses_folder() const; const ProcFSBusDirectory& buses_directory() const;
void register_new_process(Process&); void register_new_process(Process&);
void unregister_process(Process&); void unregister_process(Process&);
ProcFSRootDirectory& root_folder() { return *m_root_folder; } ProcFSRootDirectory& root_directory() { return *m_root_directory; }
Mutex& get_lock() { return m_lock; } Mutex& get_lock() { return m_lock; }
private: private:
Mutex m_lock; Mutex m_lock;
NonnullRefPtr<ProcFSRootDirectory> m_root_folder; NonnullRefPtr<ProcFSRootDirectory> m_root_directory;
}; };
class ProcFSExposedComponent : public RefCounted<ProcFSExposedComponent> { class ProcFSExposedComponent : public RefCounted<ProcFSExposedComponent> {
@ -105,9 +105,9 @@ public:
protected: protected:
explicit ProcFSExposedDirectory(StringView name); explicit ProcFSExposedDirectory(StringView name);
ProcFSExposedDirectory(StringView name, const ProcFSExposedDirectory& parent_folder); ProcFSExposedDirectory(StringView name, const ProcFSExposedDirectory& parent_directory);
NonnullRefPtrVector<ProcFSExposedComponent> m_components; NonnullRefPtrVector<ProcFSExposedComponent> m_components;
WeakPtr<ProcFSExposedDirectory> m_parent_folder; WeakPtr<ProcFSExposedDirectory> m_parent_directory;
}; };
class ProcFSExposedLink : public ProcFSExposedComponent { class ProcFSExposedLink : public ProcFSExposedComponent {
@ -163,10 +163,10 @@ class ProcFSBusDirectory : public ProcFSExposedDirectory {
friend class ProcFSComponentRegistry; friend class ProcFSComponentRegistry;
public: public:
static NonnullRefPtr<ProcFSBusDirectory> must_create(const ProcFSRootDirectory& parent_folder); static NonnullRefPtr<ProcFSBusDirectory> must_create(const ProcFSRootDirectory& parent_directory);
private: private:
ProcFSBusDirectory(const ProcFSRootDirectory& parent_folder); ProcFSBusDirectory(const ProcFSRootDirectory& parent_directory);
}; };
class ProcFSRootDirectory final : public ProcFSExposedDirectory { class ProcFSRootDirectory final : public ProcFSExposedDirectory {
@ -175,7 +175,7 @@ class ProcFSRootDirectory final : public ProcFSExposedDirectory {
public: public:
virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override; virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override;
RefPtr<ProcFSProcessDirectory> process_folder_for(Process&); RefPtr<ProcFSProcessDirectory> process_directory_for(Process&);
static NonnullRefPtr<ProcFSRootDirectory> must_create(); static NonnullRefPtr<ProcFSRootDirectory> must_create();
virtual ~ProcFSRootDirectory(); virtual ~ProcFSRootDirectory();
@ -183,8 +183,8 @@ private:
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
ProcFSRootDirectory(); ProcFSRootDirectory();
RefPtr<ProcFSBusDirectory> m_buses_folder; RefPtr<ProcFSBusDirectory> m_buses_directory;
IntrusiveList<ProcFSProcessDirectory, RefPtr<ProcFSProcessDirectory>, &ProcFSProcessDirectory::m_list_node> m_process_folders; IntrusiveList<ProcFSProcessDirectory, RefPtr<ProcFSProcessDirectory>, &ProcFSProcessDirectory::m_list_node> m_process_directories;
}; };
class ProcFSGlobalInformation : public ProcFSExposedComponent { class ProcFSGlobalInformation : public ProcFSExposedComponent {
@ -231,36 +231,36 @@ public:
virtual uid_t owner_user() const override virtual uid_t owner_user() const override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (!parent_folder) if (!parent_directory)
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (!process) if (!process)
return false; return false;
return process->uid(); return process->uid();
} }
virtual gid_t owner_group() const override virtual gid_t owner_group() const override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (!parent_folder) if (!parent_directory)
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (!process) if (!process)
return false; return false;
return process->gid(); return process->gid();
} }
protected: protected:
ProcFSProcessInformation(StringView name, const ProcFSProcessDirectory& process_folder) ProcFSProcessInformation(StringView name, const ProcFSProcessDirectory& process_directory)
: ProcFSExposedComponent(name) : ProcFSExposedComponent(name)
, m_parent_folder(process_folder) , m_parent_directory(process_directory)
{ {
} }
virtual KResult refresh_data(FileDescription&) const override; virtual KResult refresh_data(FileDescription&) const override;
virtual bool output(KBufferBuilder& builder) = 0; virtual bool output(KBufferBuilder& builder) = 0;
WeakPtr<ProcFSProcessDirectory> m_parent_folder; WeakPtr<ProcFSProcessDirectory> m_parent_directory;
mutable SpinLock<u8> m_refresh_lock; mutable SpinLock<u8> m_refresh_lock;
}; };

View file

@ -19,15 +19,15 @@ namespace Kernel {
class ProcFSProcessStacks; class ProcFSProcessStacks;
class ProcFSThreadStack final : public ProcFSProcessInformation { class ProcFSThreadStack final : public ProcFSProcessInformation {
public: public:
// Note: We pass const ProcFSProcessStacks& to enforce creation with this type of folder // Note: We pass const ProcFSProcessStacks& to enforce creation with this type of directory
static NonnullRefPtr<ProcFSThreadStack> create(const ProcFSProcessDirectory& process_folder, const ProcFSProcessStacks&, const Thread& thread) static NonnullRefPtr<ProcFSThreadStack> create(const ProcFSProcessDirectory& process_directory, const ProcFSProcessStacks&, const Thread& thread)
{ {
return adopt_ref(*new (nothrow) ProcFSThreadStack(process_folder, thread)); return adopt_ref(*new (nothrow) ProcFSThreadStack(process_directory, thread));
} }
private: private:
explicit ProcFSThreadStack(const ProcFSProcessDirectory& process_folder, const Thread& thread) explicit ProcFSThreadStack(const ProcFSProcessDirectory& process_directory, const Thread& thread)
: ProcFSProcessInformation(String::formatted("{}", thread.tid()), process_folder) : ProcFSProcessInformation(String::formatted("{}", thread.tid()), process_directory)
, m_associated_thread(thread) , m_associated_thread(thread)
{ {
} }
@ -54,7 +54,7 @@ private:
}; };
class ProcFSProcessStacks final : public ProcFSExposedDirectory { class ProcFSProcessStacks final : public ProcFSExposedDirectory {
// Note: This folder is special, because everything that is created here is dynamic! // Note: This directory is special, because everything that is created here is dynamic!
// This means we don't register anything in the m_components Vector, and every inode // This means we don't register anything in the m_components Vector, and every inode
// is created in runtime when called to get it // is created in runtime when called to get it
// Every ProcFSThreadStack (that represents a thread stack) is created only as a temporary object // Every ProcFSThreadStack (that represents a thread stack) is created only as a temporary object
@ -65,25 +65,25 @@ public:
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override; virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override;
static NonnullRefPtr<ProcFSProcessStacks> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessStacks> create(const ProcFSProcessDirectory& parent_directory)
{ {
auto folder = adopt_ref(*new (nothrow) ProcFSProcessStacks(parent_folder)); auto directory = adopt_ref(*new (nothrow) ProcFSProcessStacks(parent_directory));
return folder; return directory;
} }
virtual void prepare_for_deletion() override virtual void prepare_for_deletion() override
{ {
ProcFSExposedDirectory::prepare_for_deletion(); ProcFSExposedDirectory::prepare_for_deletion();
m_process_folder.clear(); m_process_directory.clear();
} }
private: private:
ProcFSProcessStacks(const ProcFSProcessDirectory& parent_folder) ProcFSProcessStacks(const ProcFSProcessDirectory& parent_directory)
: ProcFSExposedDirectory("stacks"sv, parent_folder) : ProcFSExposedDirectory("stacks"sv, parent_directory)
, m_process_folder(parent_folder) , m_process_directory(parent_directory)
{ {
} }
WeakPtr<ProcFSProcessDirectory> m_process_folder; WeakPtr<ProcFSProcessDirectory> m_process_directory;
mutable Mutex m_lock; mutable Mutex m_lock;
}; };
@ -102,13 +102,13 @@ KResultOr<size_t> ProcFSProcessStacks::entries_count() const
KResult ProcFSProcessStacks::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult ProcFSProcessStacks::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{ {
Locker locker(m_lock); Locker locker(m_lock);
auto parent_folder = m_process_folder.strong_ref(); auto parent_directory = m_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return KResult(EINVAL); return KResult(EINVAL);
callback({ ".", { fsid, component_index() }, 0 }); callback({ ".", { fsid, component_index() }, 0 });
callback({ "..", { fsid, parent_folder->component_index() }, 0 }); callback({ "..", { fsid, parent_directory->component_index() }, 0 });
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return KResult(ESRCH); return KResult(ESRCH);
process->for_each_thread([&](const Thread& thread) { process->for_each_thread([&](const Thread& thread) {
@ -122,10 +122,10 @@ KResult ProcFSProcessStacks::traverse_as_directory(unsigned fsid, Function<bool(
RefPtr<ProcFSExposedComponent> ProcFSProcessStacks::lookup(StringView name) RefPtr<ProcFSExposedComponent> ProcFSProcessStacks::lookup(StringView name)
{ {
Locker locker(m_lock); Locker locker(m_lock);
auto parent_folder = m_process_folder.strong_ref(); auto parent_directory = m_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return nullptr; return nullptr;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return nullptr; return nullptr;
RefPtr<ProcFSThreadStack> procfd_stack; RefPtr<ProcFSThreadStack> procfd_stack;
@ -133,7 +133,7 @@ RefPtr<ProcFSExposedComponent> ProcFSProcessStacks::lookup(StringView name)
process->for_each_thread([&](const Thread& thread) { process->for_each_thread([&](const Thread& thread) {
int tid = thread.tid().value(); int tid = thread.tid().value();
if (name == String::number(tid)) { if (name == String::number(tid)) {
procfd_stack = ProcFSThreadStack::create(*parent_folder, *this, thread); procfd_stack = ProcFSThreadStack::create(*parent_directory, *this, thread);
} }
}); });
return procfd_stack; return procfd_stack;
@ -142,7 +142,7 @@ RefPtr<ProcFSExposedComponent> ProcFSProcessStacks::lookup(StringView name)
class ProcFSProcessFileDescriptions; class ProcFSProcessFileDescriptions;
class ProcFSProcessFileDescription final : public ProcFSExposedLink { class ProcFSProcessFileDescription final : public ProcFSExposedLink {
public: public:
// Note: we pass const ProcFSProcessFileDescriptions& just to enforce creation of this in the correct folder. // Note: we pass const ProcFSProcessFileDescriptions& just to enforce creation of this in the correct directory.
static NonnullRefPtr<ProcFSProcessFileDescription> create(unsigned fd_number, const FileDescription& fd, InodeIndex preallocated_index, const ProcFSProcessFileDescriptions&) static NonnullRefPtr<ProcFSProcessFileDescription> create(unsigned fd_number, const FileDescription& fd, InodeIndex preallocated_index, const ProcFSProcessFileDescriptions&)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessFileDescription(fd_number, fd, preallocated_index)); return adopt_ref(*new (nothrow) ProcFSProcessFileDescription(fd_number, fd, preallocated_index));
@ -164,7 +164,7 @@ private:
}; };
class ProcFSProcessFileDescriptions final : public ProcFSExposedDirectory { class ProcFSProcessFileDescriptions final : public ProcFSExposedDirectory {
// Note: This folder is special, because everything that is created here is dynamic! // Note: This directory is special, because everything that is created here is dynamic!
// This means we don't register anything in the m_components Vector, and every inode // This means we don't register anything in the m_components Vector, and every inode
// is created in runtime when called to get it // is created in runtime when called to get it
// Every ProcFSProcessFileDescription (that represents a file descriptor) is created only as a temporary object // Every ProcFSProcessFileDescription (that represents a file descriptor) is created only as a temporary object
@ -175,24 +175,24 @@ public:
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override; virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override; virtual RefPtr<ProcFSExposedComponent> lookup(StringView name) override;
static NonnullRefPtr<ProcFSProcessFileDescriptions> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessFileDescriptions> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessFileDescriptions(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessFileDescriptions(parent_directory));
} }
virtual void prepare_for_deletion() override virtual void prepare_for_deletion() override
{ {
ProcFSExposedDirectory::prepare_for_deletion(); ProcFSExposedDirectory::prepare_for_deletion();
m_process_folder.clear(); m_process_directory.clear();
} }
private: private:
explicit ProcFSProcessFileDescriptions(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessFileDescriptions(const ProcFSProcessDirectory& parent_directory)
: ProcFSExposedDirectory("fd"sv, parent_folder) : ProcFSExposedDirectory("fd"sv, parent_directory)
, m_process_folder(parent_folder) , m_process_directory(parent_directory)
{ {
} }
WeakPtr<ProcFSProcessDirectory> m_process_folder; WeakPtr<ProcFSProcessDirectory> m_process_directory;
mutable Mutex m_lock; mutable Mutex m_lock;
}; };
@ -210,13 +210,13 @@ KResultOr<size_t> ProcFSProcessFileDescriptions::entries_count() const
KResult ProcFSProcessFileDescriptions::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const KResult ProcFSProcessFileDescriptions::traverse_as_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
{ {
Locker locker(m_lock); Locker locker(m_lock);
auto parent_folder = m_process_folder.strong_ref(); auto parent_directory = m_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return KResult(EINVAL); return KResult(EINVAL);
callback({ ".", { fsid, component_index() }, 0 }); callback({ ".", { fsid, component_index() }, 0 });
callback({ "..", { fsid, parent_folder->component_index() }, 0 }); callback({ "..", { fsid, parent_directory->component_index() }, 0 });
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return KResult(ESRCH); return KResult(ESRCH);
size_t count = 0; size_t count = 0;
@ -234,10 +234,10 @@ KResult ProcFSProcessFileDescriptions::traverse_as_directory(unsigned fsid, Func
RefPtr<ProcFSExposedComponent> ProcFSProcessFileDescriptions::lookup(StringView name) RefPtr<ProcFSExposedComponent> ProcFSProcessFileDescriptions::lookup(StringView name)
{ {
Locker locker(m_lock); Locker locker(m_lock);
auto parent_folder = m_process_folder.strong_ref(); auto parent_directory = m_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return nullptr; return nullptr;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return nullptr; return nullptr;
RefPtr<ProcFSProcessFileDescription> procfd_fd; RefPtr<ProcFSProcessFileDescription> procfd_fd;
@ -258,22 +258,22 @@ RefPtr<ProcFSExposedComponent> ProcFSProcessFileDescriptions::lookup(StringView
class ProcFSProcessPledge final : public ProcFSProcessInformation { class ProcFSProcessPledge final : public ProcFSProcessInformation {
public: public:
static NonnullRefPtr<ProcFSProcessPledge> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessPledge> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessPledge(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessPledge(parent_directory));
} }
private: private:
explicit ProcFSProcessPledge(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessPledge(const ProcFSProcessDirectory& parent_directory)
: ProcFSProcessInformation("pledge"sv, parent_folder) : ProcFSProcessInformation("pledge"sv, parent_directory)
{ {
} }
virtual bool output(KBufferBuilder& builder) override virtual bool output(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
JsonObjectSerializer obj { builder }; JsonObjectSerializer obj { builder };
@ -296,22 +296,22 @@ private:
class ProcFSProcessUnveil final : public ProcFSProcessInformation { class ProcFSProcessUnveil final : public ProcFSProcessInformation {
public: public:
static NonnullRefPtr<ProcFSProcessUnveil> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessUnveil> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessUnveil(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessUnveil(parent_directory));
} }
private: private:
explicit ProcFSProcessUnveil(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessUnveil(const ProcFSProcessDirectory& parent_directory)
: ProcFSProcessInformation("unveil"sv, parent_folder) : ProcFSProcessInformation("unveil"sv, parent_directory)
{ {
} }
virtual bool output(KBufferBuilder& builder) override virtual bool output(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
JsonArraySerializer array { builder }; JsonArraySerializer array { builder };
@ -340,23 +340,23 @@ private:
class ProcFSProcessPerformanceEvents final : public ProcFSProcessInformation { class ProcFSProcessPerformanceEvents final : public ProcFSProcessInformation {
public: public:
static NonnullRefPtr<ProcFSProcessPerformanceEvents> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessPerformanceEvents> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessPerformanceEvents(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessPerformanceEvents(parent_directory));
} }
private: private:
explicit ProcFSProcessPerformanceEvents(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessPerformanceEvents(const ProcFSProcessDirectory& parent_directory)
: ProcFSProcessInformation("perf_events"sv, parent_folder) : ProcFSProcessInformation("perf_events"sv, parent_directory)
{ {
} }
virtual bool output(KBufferBuilder& builder) override virtual bool output(KBufferBuilder& builder) override
{ {
InterruptDisabler disabler; InterruptDisabler disabler;
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
if (!process->perf_events()) { if (!process->perf_events()) {
@ -369,23 +369,23 @@ private:
class ProcFSProcessOverallFileDescriptions final : public ProcFSProcessInformation { class ProcFSProcessOverallFileDescriptions final : public ProcFSProcessInformation {
public: public:
static NonnullRefPtr<ProcFSProcessOverallFileDescriptions> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessOverallFileDescriptions> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessOverallFileDescriptions(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessOverallFileDescriptions(parent_directory));
} }
private: private:
explicit ProcFSProcessOverallFileDescriptions(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessOverallFileDescriptions(const ProcFSProcessDirectory& parent_directory)
: ProcFSProcessInformation("fds"sv, parent_folder) : ProcFSProcessInformation("fds"sv, parent_directory)
{ {
} }
virtual bool output(KBufferBuilder& builder) override virtual bool output(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
JsonArraySerializer array { builder }; JsonArraySerializer array { builder };
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
if (process->fds().open_count() == 0) { if (process->fds().open_count() == 0) {
@ -421,23 +421,23 @@ private:
class ProcFSProcessRoot final : public ProcFSExposedLink { class ProcFSProcessRoot final : public ProcFSExposedLink {
public: public:
static NonnullRefPtr<ProcFSProcessRoot> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessRoot> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessRoot(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessRoot(parent_directory));
} }
private: private:
explicit ProcFSProcessRoot(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessRoot(const ProcFSProcessDirectory& parent_directory)
: ProcFSExposedLink("root"sv) : ProcFSExposedLink("root"sv)
, m_parent_process_directory(parent_folder) , m_parent_process_directory(parent_directory)
{ {
} }
virtual bool acquire_link(KBufferBuilder& builder) override virtual bool acquire_link(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_process_directory.strong_ref(); auto parent_directory = m_parent_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
builder.append_bytes(process->root_directory_relative_to_global_root().absolute_path().to_byte_buffer()); builder.append_bytes(process->root_directory_relative_to_global_root().absolute_path().to_byte_buffer());
@ -448,22 +448,22 @@ private:
class ProcFSProcessVirtualMemory final : public ProcFSProcessInformation { class ProcFSProcessVirtualMemory final : public ProcFSProcessInformation {
public: public:
static NonnullRefPtr<ProcFSProcessRoot> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessRoot> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessVirtualMemory(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessVirtualMemory(parent_directory));
} }
private: private:
explicit ProcFSProcessVirtualMemory(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessVirtualMemory(const ProcFSProcessDirectory& parent_directory)
: ProcFSProcessInformation("vm"sv, parent_folder) : ProcFSProcessInformation("vm"sv, parent_directory)
{ {
} }
virtual bool output(KBufferBuilder& builder) override virtual bool output(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_folder.strong_ref(); auto parent_directory = m_parent_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
JsonArraySerializer array { builder }; JsonArraySerializer array { builder };
@ -512,23 +512,23 @@ private:
class ProcFSProcessCurrentWorkDirectory final : public ProcFSExposedLink { class ProcFSProcessCurrentWorkDirectory final : public ProcFSExposedLink {
public: public:
static NonnullRefPtr<ProcFSProcessCurrentWorkDirectory> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessCurrentWorkDirectory> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessCurrentWorkDirectory(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessCurrentWorkDirectory(parent_directory));
} }
private: private:
explicit ProcFSProcessCurrentWorkDirectory(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessCurrentWorkDirectory(const ProcFSProcessDirectory& parent_directory)
: ProcFSExposedLink("cwd"sv) : ProcFSExposedLink("cwd"sv)
, m_parent_process_directory(parent_folder) , m_parent_process_directory(parent_directory)
{ {
} }
virtual bool acquire_link(KBufferBuilder& builder) override virtual bool acquire_link(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_process_directory.strong_ref(); auto parent_directory = m_parent_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
builder.append_bytes(process->current_directory().absolute_path().bytes()); builder.append_bytes(process->current_directory().absolute_path().bytes());
@ -540,17 +540,17 @@ private:
class ProcFSProcessBinary final : public ProcFSExposedLink { class ProcFSProcessBinary final : public ProcFSExposedLink {
public: public:
static NonnullRefPtr<ProcFSProcessBinary> create(const ProcFSProcessDirectory& parent_folder) static NonnullRefPtr<ProcFSProcessBinary> create(const ProcFSProcessDirectory& parent_directory)
{ {
return adopt_ref(*new (nothrow) ProcFSProcessBinary(parent_folder)); return adopt_ref(*new (nothrow) ProcFSProcessBinary(parent_directory));
} }
virtual mode_t required_mode() const override virtual mode_t required_mode() const override
{ {
auto parent_folder = m_parent_process_directory.strong_ref(); auto parent_directory = m_parent_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
if (!process->executable()) if (!process->executable())
@ -559,17 +559,17 @@ public:
} }
private: private:
explicit ProcFSProcessBinary(const ProcFSProcessDirectory& parent_folder) explicit ProcFSProcessBinary(const ProcFSProcessDirectory& parent_directory)
: ProcFSExposedLink("exe"sv) : ProcFSExposedLink("exe"sv)
, m_parent_process_directory(parent_folder) , m_parent_process_directory(parent_directory)
{ {
} }
virtual bool acquire_link(KBufferBuilder& builder) override virtual bool acquire_link(KBufferBuilder& builder) override
{ {
auto parent_folder = m_parent_process_directory.strong_ref(); auto parent_directory = m_parent_process_directory.strong_ref();
if (parent_folder.is_null()) if (parent_directory.is_null())
return false; return false;
auto process = parent_folder->associated_process(); auto process = parent_directory->associated_process();
if (process.is_null()) if (process.is_null())
return false; return false;
auto* custody = process->executable(); auto* custody = process->executable();
@ -626,7 +626,7 @@ void ProcFSProcessDirectory::prepare_for_deletion()
} }
ProcFSProcessDirectory::ProcFSProcessDirectory(const Process& process) ProcFSProcessDirectory::ProcFSProcessDirectory(const Process& process)
: ProcFSExposedDirectory(String::formatted("{:d}", process.pid().value()), ProcFSComponentRegistry::the().root_folder()) : ProcFSExposedDirectory(String::formatted("{:d}", process.pid().value()), ProcFSComponentRegistry::the().root_directory())
, m_associated_process(process) , m_associated_process(process)
{ {
} }