understanding Debugfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to understand the use of debugfs with the use of this sample program.

#include <linux/init.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/fs.h>

#define len 200
u64 intvalue,hexvalue;
struct dentry *dirret,*fileret,*u64int,*u64hex;
char ker_buf[len];
int filevalue;
/* read file operation */
static ssize_t myreader(struct file *fp, char __user *user_buffer,
                                size_t count, loff_t *position){
     return simple_read_from_buffer(user_buffer, count, position, ker_buf, len);
}
 
/* write file operation */
static ssize_t mywriter(struct file *fp, const char __user *user_buffer,
                                size_t count, loff_t *position){
        if(count > len )
                return -EINVAL;
 
        return simple_write_to_buffer(ker_buf, len, position, user_buffer, count);
}
 
static const struct file_operations fops_debug = {
        .read = myreader,
        .write = mywriter,
};
 
static int __init init_debug(void)
{
    /* create a directory by the name dell in /sys/kernel/debugfs */
    dirret = debugfs_create_dir("dell", NULL);
     
    /* create a file in the above directory
    This requires read and write file operations */
    fileret = debugfs_create_file("text", 0644, dirret, &filevalue, &fops_debug);
 
    /* create a file which takes in a int(64) value */
    u64int = debugfs_create_u64("number", 0644, dirret, &intvalue);
    if (!u64int) {
        printk("error creating int file");
        return (-ENODEV);
    }
    /* takes a hex decimal value */
    u64hex = debugfs_create_x64("hexnum", 0644, dirret, &hexvalue );
    if (!u64hex) {
        printk("error creating hex file");
        return (-ENODEV);
    }
 
    return (0);
}
module_init(init_debug);
 
static void __exit exit_debug(void){
    debugfs_remove_recursive(dirret);
}
module_exit(exit_debug);

Shouldn't it create a dir named 'dell' in sys/kernel/debug ?. (debugfs is mounted.)
Can someone explain the use of debugfs or may be point to some good resources?

thanks!
swair
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux