views:

58

answers:

2

Hello, I am trying to create a debugfs file using the debugfs_create_file(...). I have written a sample code for this.

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

When i ran insmod i could get the Hello, World message but no the error message. So i think the debugfs_create_file worked fine. However i couldn't find any file in /sys/kernel/debug. The folder is there but it is empty. Can anyone help me with this? Thank you...

Thanks, Bala

A: 

You might consider printk(KERN_ALERT "Something else happened\n") in the case that file1 is not equal to NULL or -ENODEV. That may provide some interesting results. Maybe:

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

I'm not familiar with kernel programming libraries as much, but if there is a similar va_args interface to printk(), you could probably print the value of file1.

Now looking at this though, is there some kind of kernel errno? Or is that what debugfs_create_file() returns?

UPDATE:

The only help I can give now is to somehow discover what file1's value is and investigate what that means. You may want to do some poking around for an errno equivalent and see if its set. Equivalent to the perror() call in the kernel basically.

xyld
I did that and got something else occured...
+1  A: 

For debugfs to work, you actually have to have a debugfs mountpoint:

mount -t debugfs none /sys/kernel/debug

Not sure if that's what the problem is here, but may be you can check if you have a mounted debugfs on /sys/kernel/debug

Bandan
wow.. that worked...