Add /proc/vnodes, listing basic info about all open vnodes.

This commit is contained in:
Andreas Kling 2018-11-09 17:46:55 +01:00
parent 4914f3b837
commit e0ca6bb97e
Notes: sideshowbarker 2024-07-19 16:11:53 +09:00
2 changed files with 27 additions and 0 deletions

View File

@ -319,6 +319,29 @@ ByteBuffer procfs$summary()
return buffer;
}
ByteBuffer procfs$vnodes()
{
auto& vfs = VirtualFileSystem::the();
auto buffer = ByteBuffer::createUninitialized(vfs.m_maxNodeCount * 256);
char* ptr = (char*)buffer.pointer();
for (size_t i = 0; i < vfs.m_maxNodeCount; ++i) {
auto& vnode = vfs.m_nodes[i];
if (!vnode.inUse())
continue;
auto path = vfs.absolutePath(vnode.inode);
if (path.isEmpty()) {
if (auto* dev = vnode.characterDevice()) {
if (dev->isTTY())
path = static_cast<const TTY*>(dev)->ttyName();
}
}
ptr += ksprintf(ptr, "vnode %03u: %02u:%08u (%u) %s\n", i, vnode.inode.fileSystemID(), vnode.inode.index(), vnode.retain_count(), path.characters());
}
*ptr = '\0';
buffer.trim(ptr - (char*)buffer.pointer());
return buffer;
}
bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
@ -328,6 +351,7 @@ bool ProcFileSystem::initialize()
addFile(createGeneratedFile("kmalloc", procfs$kmalloc));
addFile(createGeneratedFile("summary", procfs$summary));
addFile(createGeneratedFile("cpuinfo", procfs$cpuinfo));
addFile(createGeneratedFile("vnodes", procfs$vnodes));
return true;
}

View File

@ -28,6 +28,7 @@ inline constexpr dword encodedDevice(unsigned major, unsigned minor)
class VirtualFileSystem {
AK_MAKE_ETERNAL
friend ByteBuffer procfs$vnodes();
public:
static void initializeGlobals();
@ -68,6 +69,8 @@ public:
void* vmo() { return m_vmo; }
void set_vmo(void* vmo) { m_vmo = vmo; }
unsigned retain_count() const { return retainCount; }
private:
friend class VirtualFileSystem;
VirtualFileSystem* m_vfs { nullptr };