我正在尝试使用debugfs_create_file(...)创建一个调试文件。我已经为此编写了一个示例代码。
static int __init mmapexample_module_init(void)
{
file1 = debugfs_create_file("mmap_example", 0644, NULL, NULL, &my_fops)\
;
printk(KERN_ALERT "Hello, World\n");
if(file1==NULL)
{
printk(KERN_ALERT "Error occured\n");
}
if(file1==-ENODEV)
{
printk(KERN_ALERT "ENODEV occured\n");
}
return 0;
} 当我运行insmod时,我可以得到Hello,World消息,但没有得到错误消息。所以我认为debugfs_create_file运行得很好。但是,我在/sys/kernel/debug中找不到任何文件。文件夹在那里,但它是空的。有人能帮我吗?谢谢..。
谢谢,巴拉
发布于 2010-05-07 08:32:29
要让debugfs正常工作,您实际上必须有一个debugfs挂载点:
mount -t debugfs none /sys/kernel/debug不确定这是否是问题所在,但可能是因为您可以检查在/sys/kernel/debug上是否安装了debugfs
发布于 2010-05-05 07:40:56
在file1不等于NULL或-ENODEV的情况下,您可以考虑printk(KERN_ALERT "Something else happened\n")。这可能会提供一些有趣的结果。也许:
if (file1 == NULL)
printk(KERN_ALERT "Error occurred\n");
else if (file1 == -ENODEV)
printk(KERN_ALERT "ENODEV occurred\n");
else
printk(KERN_ALERT "Something else occurred\n");我对内核编程库不是很熟悉,但是如果有一个类似于printk()的va_args接口,您可能会输出file1的值。
现在看看这个,是不是有某种内核errno?或者这就是debugfs_create_file()返回的结果?
更新
现在我能提供的唯一帮助就是以某种方式发现file1的值是什么,并调查它的含义。您可能希望查找errno等效项,并查看是否设置了它。基本上等同于内核中的perror()调用。
https://stackoverflow.com/questions/2769627
复制相似问题