diff options
author | 0xwille | 2011-07-08 18:46:53 +0200 |
---|---|---|
committer | 0xwille | 2011-07-08 18:46:53 +0200 |
commit | c8f116e17b471704abbb3b1508733aa1bddda7da (patch) | |
tree | fa78154afe30d58ea047abaeb105c9995a9a6969 /handlers/chardev.c | |
parent | f1e9e18f1ad00ec9d78cd76105b3934980d2e09b (diff) | |
download | lkm-c8f116e17b471704abbb3b1508733aa1bddda7da.tar.gz |
AƱadidas cosicas y gitignore
Diffstat (limited to 'handlers/chardev.c')
-rw-r--r-- | handlers/chardev.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/handlers/chardev.c b/handlers/chardev.c index 3594bce..1c1f923 100644 --- a/handlers/chardev.c +++ b/handlers/chardev.c @@ -1,6 +1,7 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> +#include <linux/sched.h> #include <asm/uaccess.h> #include "chardev.h" @@ -11,9 +12,15 @@ static int Major; static int opened = 0; -static char msg[BUF_LEN]; +static char chardev_buffer[BUF_LEN]; static char* msg_ptr; +void dumb(void) +{ + printk(KERN_INFO "DUMB EXECUTED\n"); +} +EXPORT_SYMBOL(dumb); + static struct file_operations fops = { .read = device_read, .write = device_write, @@ -23,6 +30,7 @@ static struct file_operations fops = { int init_module(void) { + Major = register_chrdev(0, DEVICE_NAME, &fops); if (Major < 0) { @@ -53,9 +61,9 @@ static int device_open(struct inode* inode, struct file* filp) opened++; if (counter++ == 0) - sprintf(msg, "Come on, write something here :D\n"); + sprintf(chardev_buffer, "Come on, write something here :D\n"); - msg_ptr = msg; + msg_ptr = chardev_buffer; try_module_get(THIS_MODULE); return SUCCESS; @@ -70,18 +78,27 @@ static int device_release(struct inode* inode, struct file* filp) return 0; } -static ssize_t device_read(struct file* filp, char* buffer, size_t len, loff_t* off) +static ssize_t device_read(struct file* filp, char* buff, size_t len, loff_t* off) { int bytes = 0; + char strpid[14]; + snprintf(strpid, 14, "PID: %d", (current->pid)); if (*msg_ptr == 0) return 0; while (len-- && *msg_ptr) { - put_user(*msg_ptr++, buffer++); + put_user(*msg_ptr++, buff++); bytes++; } + copy_to_user(buff, strpid, 14); + bytes += 14; + buff += 14; + + put_user('\n', buff++); + bytes++; + return bytes; } @@ -95,11 +112,11 @@ static ssize_t device_write(struct file* filp, const char* buff, size_t len, lof } while (len--) { - get_user(msg[bytes], buff++); + get_user(chardev_buffer[bytes], buff++); bytes++; } - msg[bytes] = '\0'; + chardev_buffer[bytes] = '\0'; - msg_ptr = msg; + msg_ptr = chardev_buffer; return bytes; } |