From 001941a9e66a44cc9437e64f63d23e15456e9837 Mon Sep 17 00:00:00 2001 From: un-lock-able Date: Wed, 23 Apr 2025 21:07:44 +0800 Subject: [PATCH] build the module --- lab6/.gitignore | 1 + lab6/Makefile | 17 +++++++++++++---- lab6/mypipe.c | 10 +++++----- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 lab6/.gitignore diff --git a/lab6/.gitignore b/lab6/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/lab6/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/lab6/Makefile b/lab6/Makefile index 315c2ac..fc0d6c2 100644 --- a/lab6/Makefile +++ b/lab6/Makefile @@ -1,13 +1,22 @@ obj-m += mypipe.o OUT_DIR := build -.PHONY kern_mod writer reader clean -all: kern_mod writer reader +.PHONY: all kern_mod install uninstall clean + +all: kern_mod + @true kern_mod: mypipe.c - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) MO=$(PWD)/build + + +install: + insmod ./build/mypipe.ko + +uninstall: + rmmod mypipe clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean + $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean rm -rf $(OUT_DIR) diff --git a/lab6/mypipe.c b/lab6/mypipe.c index 6a77c4d..14d985b 100644 --- a/lab6/mypipe.c +++ b/lab6/mypipe.c @@ -48,11 +48,11 @@ static int mypipe_release(struct inode *inode, struct file *file) { return 0; } -static int mypipe_read(struct file *filep, char __user *buf, size_t size, +static ssize_t mypipe_read(struct file *filep, char __user *buf, size_t size, loff_t *offset) { ssize_t ret = 0; - if (iminor(file_iniode(filep)) != MYPIPE_MINOR_OUT) { + if (iminor(file_inode(filep)) != MYPIPE_MINOR_OUT) { return -EINVAL; } @@ -102,13 +102,13 @@ out: return ret; } -static int mypipe_write(struct file *filep, char __user *buf, size_t size, +static ssize_t mypipe_write(struct file *filep, const char __user *buf, size_t size, loff_t *offset) { // This is very similar to read(), just write instead of read ssize_t ret = 0; - if (iminor(file_indo(filep)) != MYPIPE_MINOR_IN) { + if (iminor(file_inode(filep)) != MYPIPE_MINOR_IN) { return -EINVAL; } @@ -218,7 +218,7 @@ static void __exit mypipe_destroy(void) { device_destroy(mypipedev_class, MKDEV(dev_major, MYPIPE_MINOR_IN)); device_destroy(mypipedev_class, MKDEV(dev_major, MYPIPE_MINOR_OUT)); class_unregister(mypipedev_class); - class_destory(mypipedev_class); + class_destroy(mypipedev_class); cdev_del(&pdata.cdev); unregister_chrdev_region(MKDEV(dev_major, 0), MYPIPE_MINOR_COUNT); printk(KERN_INFO "Wendy: module unloaded");