2010-05-04 64 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