Add a simple /proc/mounts that enumerates the current VFS mounts.

This commit is contained in:
Andreas Kling 2018-10-26 18:43:25 +02:00
parent a447359916
commit 81627cf7d5
Notes: sideshowbarker 2024-07-19 18:38:02 +09:00
6 changed files with 46 additions and 17 deletions

View file

@ -4,7 +4,7 @@
class Console final : public CharacterDevice {
public:
static Console& the();
static Console& the() PURE;
Console();
virtual ~Console() override;

View file

@ -37,7 +37,7 @@ bool copyToZone(Zone&, const void* data, size_t);
class MemoryManager {
public:
static MemoryManager& the();
static MemoryManager& the() PURE;
PhysicalAddress pageDirectoryBase() const { return PhysicalAddress(reinterpret_cast<dword>(m_pageDirectory)); }

View file

@ -1,5 +1,6 @@
#include "ProcFileSystem.h"
#include "Task.h"
#include <VirtualFileSystem/VirtualFileSystem.h>
static ProcFileSystem* s_the;
@ -64,6 +65,22 @@ bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
addFile(createGeneratedFile("mounts", [] {
InterruptDisabler disabler;
auto buffer = ByteBuffer::createUninitialized(VirtualFileSystem::the().mountCount() * 80);
char* ptr = (char*)buffer.pointer();
VirtualFileSystem::the().forEachMount([&ptr] (auto& mount) {
auto& fs = mount.fileSystem();
ptr += ksprintf(ptr, "%s @ ", fs.className());
if (!mount.host().isValid())
ptr += ksprintf(ptr, "/\n", fs.className());
else
ptr += ksprintf(ptr, "%u:%u\n", mount.host().fileSystemID(), mount.host().index());
});
buffer.trim(ptr - (char*)buffer.pointer());
return buffer;
}));
addFile(createGeneratedFile("kmalloc", [] {
InterruptDisabler disabler;
auto buffer = ByteBuffer::createUninitialized(128);

View file

@ -7,7 +7,7 @@ class Task;
class ProcFileSystem final : public SyntheticFileSystem {
public:
static ProcFileSystem& the();
static ProcFileSystem& the() PURE;
virtual ~ProcFileSystem() override;
static RetainPtr<ProcFileSystem> create();

View file

@ -501,3 +501,10 @@ void VirtualFileSystem::registerCharacterDevice(unsigned major, unsigned minor,
{
m_characterDevices.set(encodedDevice(major, minor), &device);
}
void VirtualFileSystem::forEachMount(Function<void(const Mount&)> callback) const
{
for (auto& mount : m_mounts) {
callback(*mount);
}
}

View file

@ -20,6 +20,21 @@ public:
static void initializeGlobals();
static SpinLock& lock();
class Mount {
public:
Mount(InodeIdentifier host, RetainPtr<FileSystem>&&);
InodeIdentifier host() const { return m_host; }
InodeIdentifier guest() const { return m_guest; }
const FileSystem& fileSystem() const { return *m_fileSystem; }
private:
InodeIdentifier m_host;
InodeIdentifier m_guest;
RetainPtr<FileSystem> m_fileSystem;
};
struct Node {
InodeIdentifier inode;
const InodeMetadata& metadata() const;
@ -46,7 +61,7 @@ public:
mutable InodeMetadata m_cachedMetadata;
};
static VirtualFileSystem& the();
static VirtualFileSystem& the() PURE;
VirtualFileSystem();
~VirtualFileSystem();
@ -74,6 +89,9 @@ public:
void registerCharacterDevice(unsigned major, unsigned minor, CharacterDevice&);
size_t mountCount() const { return m_mounts.size(); }
void forEachMount(Function<void(const Mount&)>) const;
private:
friend class FileHandle;
@ -88,19 +106,6 @@ private:
RetainPtr<Node> makeNode(InodeIdentifier);
RetainPtr<Node> getOrCreateNode(InodeIdentifier);
class Mount {
public:
Mount(InodeIdentifier host, RetainPtr<FileSystem>&&);
InodeIdentifier host() const { return m_host; }
InodeIdentifier guest() const { return m_guest; }
private:
InodeIdentifier m_host;
InodeIdentifier m_guest;
RetainPtr<FileSystem> m_fileSystem;
};
Mount* findMountForHost(InodeIdentifier);
Mount* findMountForGuest(InodeIdentifier);