diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-12 13:23:03 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-12 13:23:03 +0200 |
commit | 480640799470b4465d62348aaf73154423ddb896 (patch) | |
tree | aa2a54f304277ff976781f93abed1a407ef0ac19 /1/fopdrv.c | |
parent | 11181adc990dd71f7c7c27b0486bd05744654a33 (diff) |
implement simple printf "0" or "1" > /dev/lork input + add some registers to config.h
Diffstat (limited to '1/fopdrv.c')
-rw-r--r-- | 1/fopdrv.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -2,13 +2,29 @@ // driver/char/mem.c read_null (/dev/null) ssize_t fop_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - printk("%s(<file>, <buf>, %lu, <ppos>)\n", __PRETTY_FUNCTION__, count); + printk("%s(<file>, <buf>, %u, <ppos>)\n", __PRETTY_FUNCTION__, count); return 0; } // driver/char/mem.c write_null ssize_t fop_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { - printk("%s(<file>, <buf>, %lu, <ppos>)\n", __PRETTY_FUNCTION__, count); + printk("%s(<file>, <buf>, %u, <ppos>)\n", __PRETTY_FUNCTION__, count); + + // only allow single character as input + if (count != 1) return count; + + // copy buffer for reading (see [kernel-labs-chrdev] in ../readme.md) + char input_buf[10]; + if (copy_from_user(input_buf + *ppos, buf, count)) + return -EFAULT; + + if (input_buf[0] == '0') { + printk("TODO: TURN OFF OUTPUT\n"); + } + if (input_buf[0] == '1') { + printk("TODO: TURN ON OUTPUT\n"); + } + return count; } |