add assignement 00 to 08

This commit is contained in:
2025-07-10 17:05:01 +02:00
commit 85301ea6e0
22 changed files with 9212 additions and 0 deletions

35
05/rw.c Normal file
View File

@ -0,0 +1,35 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#define VALUE "tomoron"
ssize_t dev_read(struct file *f, char __user *buf, size_t len, loff_t *off);
ssize_t dev_write(struct file *f, const char __user *buf, size_t len, loff_t *off);
ssize_t dev_read(struct file *f, char __user *buf, size_t len, loff_t *off) {
char msg[] = VALUE;
pr_info("someone read from the file\n");
return simple_read_from_buffer(buf, len, off, msg, sizeof(msg) - 1);
}
ssize_t dev_write(struct file *f, const char __user *buf, size_t len, loff_t *off) {
char kbuf[64];
if (len > sizeof(kbuf) - 1)
return -EINVAL;
if (copy_from_user(kbuf, buf, len))
return -EINVAL;
kbuf[len] = '\0';
if (strcmp(kbuf, VALUE) == 0)
{
pr_info("someone wrote the right string\n");
return len;
}
pr_info("someone wrote the wrong string\n");
return -EINVAL;
}