From 0d9aff9bd305d18625c322a1a891aba278049862 Mon Sep 17 00:00:00 2001 From: Kyle K Date: Mon, 24 Dec 2012 12:53:20 -0600 Subject: spawn char device at /dev/, implement read --- debug.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'debug.c') diff --git a/debug.c b/debug.c index 40ee10c..5c746d1 100644 --- a/debug.c +++ b/debug.c @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -24,7 +26,7 @@ char kernel_buff[BUFF_LEN] = {'f','o','o','b','a','r','\0'}; int fileprv = 1; /* hmm */ /* struct file, an abstract open file, not on disk, which would be a an inode */ -static ssize_t debugfs_read(struct file *fp, char __user /* userspace */ *ubuff, size_t c, loff_t *pos) +static ssize_t hello_hello_debugfs_read(struct file *fp, char __user /* userspace */ *ubuff, size_t c, loff_t *pos) { /** * simple_read_from_buffer - copy data from the buffer to user space @@ -43,7 +45,7 @@ static ssize_t debugfs_read(struct file *fp, char __user /* userspace */ *ubuff, return simple_read_from_buffer(ubuff, c, pos, kernel_buff, BUFF_LEN); } -static ssize_t debugfs_write(struct file *fp, const char __user *ubuff, size_t c, loff_t *pos) +static ssize_t hello_debugfs_write(struct file *fp, const char __user *ubuff, size_t c, loff_t *pos) { /** * simple_write_to_buffer - copy data from user space to the buffer @@ -64,14 +66,20 @@ static ssize_t debugfs_write(struct file *fp, const char __user *ubuff, size_t c return (-EINVAL); return simple_write_to_buffer(kernel_buff, BUFF_LEN, pos, ubuff, c); + +#if 0 + printk(KERN_INFO "count %lu, offset %u", c, *pos); + copy_from_user(kernel_buff + *pos, ubuff, c); + return c; +#endif } -int debug_init(struct dentry **dir, struct dentry **file) +int hello_debugfs_init(struct dentry **dir, struct dentry **file) { /* func ptrs that perform various operations on the device, in this case char device, well not even */ struct file_operations fops = { - .read = debugfs_read, - .write = debugfs_write + .read = hello_hello_debugfs_read, + .write = hello_debugfs_write }; /* omitted fields are initialized to NULL */ @@ -82,12 +90,12 @@ int debug_init(struct dentry **dir, struct dentry **file) /* regular file, read by user/group/other, write by user */ *file = debugfs_create_file("magic", S_IFREG | S_IRUGO | S_IWUSR, *dir, &fileprv, &fops); if (!*file) - printk("debugfs: error creating file\n"); + printk(KERN_WARNING "[hello] debugfs: error creating file\n"); return 0; } -int debug_destroy(struct dentry *dir, struct dentry *file) +int hello_debugfs_destroy(struct dentry *dir, struct dentry *file) { if (file) debugfs_remove(file); -- cgit v1.2.3