I’m trying to write a kernel module, which prints some information about the objects in the VFS subsystem. That way I want to learn how the VFS works and what structures it uses.
However, I can’t manage to iterate the super_blocks list, because of this compiler warning:
WARNING: "super_blocks" [/path/to/module/vfsinfo.ko] undefined!
If I still try to insert the module, insmod fails and returns a similar message.
Here is the relevant part of my code:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/list.h>
#include <linux/fs.h>
#define PRINT(...) printk(KERN_ALERT __VA_ARGS__)
/*
* Print all super blocks
*/
static void vfsinfo_print_super_blocks(void) {
struct super_block *s;
list_for_each_entry(s, &super_blocks, s_list) {
PRINT("%s\n", s->s_type->name);
}
}
What am I doing wrong?
Even after some research I couldn’t find any helpful
list_heador function that is exported for kernel modules. Since this project should just help me to learn the VFS data structures, I decided to create a pointer to astruct list_headand assign it the address to the “real”list_head super_blocks.For this purpose I first looked up the address in the
System.mapfile.Then I set up my
list_headand started working with it:Now I am able to access all my super blocks 🙂
Bye