From 252c5eaf2a4e11b12c0115b4df331d64ed857874 Mon Sep 17 00:00:00 2001 From: Yaakov Date: Sun, 11 Aug 2024 14:22:51 +1000 Subject: [PATCH] add a write fn --- scream.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scream.c b/scream.c index 598f411..c52d630 100644 --- a/scream.c +++ b/scream.c @@ -20,10 +20,12 @@ static struct cdev scream_cdev; static int scream_device_open(struct inode*, struct file*); static int scream_device_release(struct inode*, struct file*); static ssize_t scream_device_read(struct file*, char*, size_t, loff_t*); +static ssize_t scream_device_write(struct file*, const char*, size_t, loff_t*); static struct file_operations fops = { .open = scream_device_open, .read = scream_device_read, + .write = scream_device_write, .release = scream_device_release, }; @@ -50,7 +52,8 @@ static int __init scream_module_init(void) { return PTR_ERR(scream_device); } - // Initialize the cdev structure and add it to the kernel + printk(KERN_INFO "[scream] %s/%s device registered.", CLASS_NAME, DEVICE_NAME); + cdev_init(&scream_cdev, &fops); int add_result = cdev_add(&scream_cdev, MKDEV(major_number, 0), 1); if (add_result < 0) { @@ -94,5 +97,11 @@ static ssize_t scream_device_read(struct file* file, char* __user user_buffer, s return 0; } +static ssize_t scream_device_write(struct file* file, const char* __user user_buffer, size_t size, loff_t* offset) +{ + printk(KERN_INFO "[scream] writing to device.\n"); + return 0; +} + module_init(scream_module_init); module_exit(scream_module_exit); \ No newline at end of file