2010-05-04 102 views
0

我正尝试使用debugfs_create_file(...)创建debugfs文件。我已经为此写了一个示例代码。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我可以得到你好,世界的消息,但没有错误消息。所以我认为debugfs_create_file工作正常。但是我在/ sys/kernel/debug中找不到任何文件。该文件夹在那里,但它是空的。谁能帮我这个?谢谢...

感谢, 巴拉

回答

3

对于debugfs工作,你实际上必须有一个debugfs挂载点:

mount -t debugfs none /sys/kernel/debug 

不知道如果是这样的问题是在这里的,但可能是你可以检查你有安装debugfs /sys /内核/调试

+0

哇..那工作... – bala1486 2010-05-07 01:12:35

0

你可能会考虑在printk(KERN_ALERT "Something else happened\n")的情况下文件1不等于NULL-ENODEV。这可能会提供一些有趣的结果。也许:

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

我不熟悉内核编程库为多,但如果有一个类似的va_args接口使用printk(),你也许可以打印文件1的值。

现在看这个虽然,有没有某种内核errno?或者是debugfs_create_file()返回的是什么?

UPDATE

唯一的帮助,我现在就可以给是以某种方式发现文件1的价值是什么,研究什么意思。你可能想要做一些errno等价的东西,看看它的设置。基本上相当于内核调用perror()

+0

我做到了,并得到了一些其他的东西... – bala1486 2010-05-05 16:19:31