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

54
07/id.c Normal file
View File

@ -0,0 +1,54 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/debugfs.h>
#define VALUE "tomoron"
extern struct dentry *module_dir;
ssize_t id_read(struct file *f, char __user *buf, size_t len, loff_t *off);
ssize_t id_write(struct file *f, const char __user *buf, size_t len, loff_t *off);
int init_id(void);
static const struct file_operations fops = {
.owner = THIS_MODULE,
.read = id_read,
.write = id_write,
};
ssize_t id_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 id_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;
}
int init_id(void)
{
struct dentry *ret;
ret = debugfs_create_file("id", 0666, module_dir, NULL, &fops);
if(IS_ERR(ret))
return PTR_ERR(ret);
return 0;
}