I'm trying to understand the use of debugfs with the use of this sample program.<br><br>#include <linux/init.h><br>#include <linux/debugfs.h><br>#include <linux/module.h><br>#include <linux/fs.h><br>
<br>#define len 200<br>u64 intvalue,hexvalue;<br>struct dentry *dirret,*fileret,*u64int,*u64hex;<br>char ker_buf[len];<br>int filevalue;<br>/* read file operation */<br>static ssize_t myreader(struct file *fp, char __user *user_buffer,<br>
size_t count, loff_t *position){<br> return simple_read_from_buffer(user_buffer, count, position, ker_buf, len);<br>}<br> <br>/* write file operation */<br>static ssize_t mywriter(struct file *fp, const char __user *user_buffer,<br>
size_t count, loff_t *position){<br> if(count > len )<br> return -EINVAL;<br> <br> return simple_write_to_buffer(ker_buf, len, position, user_buffer, count);<br>
}<br> <br>static const struct file_operations fops_debug = {<br> .read = myreader,<br> .write = mywriter,<br>};<br> <br>static int __init init_debug(void)<br>{<br> /* create a directory by the name dell in /sys/kernel/debugfs */<br>
dirret = debugfs_create_dir("dell", NULL);<br> <br> /* create a file in the above directory<br> This requires read and write file operations */<br> fileret = debugfs_create_file("text", 0644, dirret, &filevalue, &fops_debug);<br>
<br> /* create a file which takes in a int(64) value */<br> u64int = debugfs_create_u64("number", 0644, dirret, &intvalue);<br> if (!u64int) {<br> printk("error creating int file");<br>
return (-ENODEV);<br> }<br> /* takes a hex decimal value */<br> u64hex = debugfs_create_x64("hexnum", 0644, dirret, &hexvalue );<br> if (!u64hex) {<br> printk("error creating hex file");<br>
return (-ENODEV);<br> }<br> <br> return (0);<br>}<br>module_init(init_debug);<br> <br>static void __exit exit_debug(void){<br> debugfs_remove_recursive(dirret);<br>}<br>module_exit(exit_debug);<br><br>Shouldn't it create a dir named 'dell' in sys/kernel/debug ?. (debugfs is mounted.)<br>
Can someone explain the use of debugfs or may be point to some good resources?<br><br>thanks!<br>swair<br>