Kernel: Add support for getdents() to DeviceFS

This commit is contained in:
apio 2022-10-23 14:05:55 +02:00
parent 78d72c2f0c
commit 14367f07b5
2 changed files with 10 additions and 0 deletions

View File

@ -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);
}

View File

@ -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];
}