From 14367f07b5d3e8a36b417988c5b79645ec98c4a2 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 23 Oct 2022 14:05:55 +0200 Subject: [PATCH] Kernel: Add support for getdents() to DeviceFS --- kernel/include/fs/devices/DeviceFS.h | 1 + kernel/src/fs/devices/DeviceFS.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/kernel/include/fs/devices/DeviceFS.h b/kernel/include/fs/devices/DeviceFS.h index 5c0ae2e4..d6a37998 100644 --- a/kernel/include/fs/devices/DeviceFS.h +++ b/kernel/include/fs/devices/DeviceFS.h @@ -6,4 +6,5 @@ namespace DeviceFS VFS::Node* get(); VFS::Node* finddir(VFS::Node* node, const char* filename); + VFS::Node* readdir(VFS::Node* node, long offset); } \ No newline at end of file diff --git a/kernel/src/fs/devices/DeviceFS.cpp b/kernel/src/fs/devices/DeviceFS.cpp index 80eb45fa..b507c4a6 100644 --- a/kernel/src/fs/devices/DeviceFS.cpp +++ b/kernel/src/fs/devices/DeviceFS.cpp @@ -23,6 +23,7 @@ VFS::Node* DeviceFS::get() devfs_root->inode = 0; devfs_root->type = VFS_DIRECTORY; devfs_root->find_func = DeviceFS::finddir; + devfs_root->readdir_func = DeviceFS::readdir; strncpy(devfs_root->name, "dev", sizeof(devfs_root->name)); devfs_files[devfs_file_count++] = VersionDevice::create_new("version"); @@ -31,6 +32,7 @@ VFS::Node* DeviceFS::get() devfs_files[devfs_file_count++] = RandomDevice::create_new("random"); devfs_files[devfs_file_count++] = KeyboardDevice::create_new("kbd"); devfs_files[devfs_file_count++] = UptimeDevice::create_new("uptime"); + devfs_root->length = devfs_file_count; return devfs_root; } @@ -42,4 +44,11 @@ VFS::Node* DeviceFS::finddir(VFS::Node* node, const char* filename) if (strncmp(devfs_files[i]->name, filename, sizeof(VFS::Node::name)) == 0) { return devfs_files[i]; } } return 0; +} + +VFS::Node* DeviceFS::readdir(VFS::Node* node, long offset) +{ + if (!node) return 0; + if (offset >= devfs_file_count) return 0; + return devfs_files[offset]; } \ No newline at end of file