无法访问内核模块中的super_blocks列表:未定义! [英] Can't access super_blocks list from kernel module: undefined!

查看:116
本文介绍了无法访问内核模块中的super_blocks列表:未定义!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个内核模块,该模块打印有关VFS子系统中对象的一些信息.这样,我想学习VFS的工作原理和使用的结构.

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.

但是,由于以下编译器警告,我无法迭代super_blocks列表:

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!

如果我仍然尝试插入模块,则insmod失败并返回类似消息.

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

我在做什么错了?

推荐答案

即使进行了一些研究,我仍然找不到为内核模块导出的任何有用的list_head或函数.由于该项目仅应帮助我学习VFS数据结构,因此我决定创建一个指向struct list_head的指针,并将其地址分配给真实" list_head super_blocks.

Even after some research I couldn't find any helpful list_head or 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 a struct list_head and assign it the address to the "real" list_head super_blocks.

为此,我首先在System.map文件中查找了地址.

For this purpose I first looked up the address in the System.map file.

$ grep super_blocks /boot/System.map-2.6.36
ffffffff81a22650 D super_blocks

然后我设置我的list_head并开始使用它:

Then I set up my list_head and started working with it:

#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 list_head *super_blocks = 0xffffffff81a22650;
        struct super_block *s;

        list_for_each_entry(s, super_blocks, s_list) {
                PRINT("%s\n", s->s_type->name);
        }
}

现在我可以访问我的所有超级块了:)

Now I am able to access all my super blocks :)

[ 1218.356475] sysfs
[ 1218.357066] rootfs
[ 1218.358450] bdev
[ 1218.359600] proc
[ 1218.360368] tmpfs
[ 1218.361612] sockfs
[ 1218.362388] debugfs
[ 1218.363090] pipefs
[ 1218.363752] anon_inodefs
[ 1218.364076] devpts
[ 1218.365077] hugetlbfs
[ 1218.365654] mqueue
[ 1218.366459] selinuxfs
[ 1218.367060] usbfs
[ 1218.367489] ext2
[ 1218.368065] sysfs
[ 1218.369076] tmpfs

再见

这篇关于无法访问内核模块中的super_blocks列表:未定义!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆