X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fkernel%2Fsamples%2Fchar2%2F.git;a=blobdiff_plain;f=hellochar.c;fp=hellochar.c;h=c95100ea72f022cf4aa4241e653bd5175d2afa11;hp=e49565c25182c5a4add644a172b666be8937c39f;hb=d99e8889b3f62defbf49d6a3d407abcc9d2a6d6f;hpb=37ece574b686c8c3631c49bc4068520984a6d949 diff --git a/hellochar.c b/hellochar.c index e49565c..c95100e 100644 --- a/hellochar.c +++ b/hellochar.c @@ -25,10 +25,19 @@ MODULE_LICENSE("GPL"); static dev_t devnum; static struct cdev *dev; +static const char default_greeting[] = "Hello, World!\n"; + +struct hello_buffer { + size_t len; + char buffer[0]; +}; static int hello_open(struct inode *ino, struct file *fp) { - printk(KERN_DEBUG "Hello, World!\n"); + struct hello_buffer *hello = kmalloc(sizeof(*hello) + 4000, GFP_KERNEL); + if (!hello) + return -ENOMEM; + hello->private_data = hello; return 0; } @@ -38,9 +47,16 @@ static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz, return 0; } +static int hello_release(struct inode *ino, struct file *fp) +{ + kfree(fp->private_data); + return 0; +} + static const struct file_operations hello_fops = { .owner = THIS_MODULE, .open = hello_open, + .release = hello_release, .read = hello_read, };