mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
e08d213830
This patch adds the FileSystemID type, which is a distinct u32. This prevents accidental conversion from arbitrary integers.
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Kernel/Bus/USB/USBDevice.h>
|
|
#include <Kernel/FileSystem/SysFS.h>
|
|
#include <Kernel/KBufferBuilder.h>
|
|
#include <Kernel/Locking/Mutex.h>
|
|
|
|
namespace Kernel::USB {
|
|
|
|
class SysFSUSBDeviceInformation : public SysFSComponent {
|
|
friend class SysFSUSBBusDirectory;
|
|
|
|
public:
|
|
virtual ~SysFSUSBDeviceInformation() override;
|
|
|
|
static NonnullRefPtr<SysFSUSBDeviceInformation> create(USB::Device&);
|
|
|
|
RefPtr<USB::Device> device() const { return m_device; }
|
|
|
|
protected:
|
|
explicit SysFSUSBDeviceInformation(USB::Device& device);
|
|
|
|
virtual ErrorOr<size_t> read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, OpenFileDescription*) const override;
|
|
|
|
IntrusiveListNode<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>> m_list_node;
|
|
|
|
NonnullRefPtr<USB::Device> m_device;
|
|
|
|
private:
|
|
ErrorOr<void> try_generate(KBufferBuilder&);
|
|
virtual ErrorOr<void> refresh_data(OpenFileDescription& description) const override;
|
|
mutable Mutex m_lock { "SysFSUSBDeviceInformation" };
|
|
};
|
|
|
|
class SysFSUSBBusDirectory final : public SysFSDirectory {
|
|
public:
|
|
static void initialize();
|
|
static SysFSUSBBusDirectory& the();
|
|
|
|
void plug(USB::Device&);
|
|
void unplug(USB::Device&);
|
|
|
|
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
|
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
|
|
|
private:
|
|
explicit SysFSUSBBusDirectory(SysFSBusDirectory&);
|
|
|
|
RefPtr<SysFSUSBDeviceInformation> device_node_for(USB::Device& device);
|
|
|
|
IntrusiveList<&SysFSUSBDeviceInformation::m_list_node> m_device_nodes;
|
|
mutable Spinlock m_lock;
|
|
};
|
|
|
|
}
|