build the module

This commit is contained in:
2025-04-23 21:07:44 +08:00
parent 708409e485
commit 001941a9e6
3 changed files with 19 additions and 9 deletions

1
lab6/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

View File

@@ -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)

View File

@@ -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");