set permisson

This commit is contained in:
2025-04-23 23:06:10 +08:00
parent dc65192ef6
commit 3c7b6c2126
2 changed files with 16 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
obj-m += mypipe.o
obj-m += wendy.o
OUT_DIR := build
.PHONY: all kern_mod install uninstall clean reader writer
@@ -6,14 +6,14 @@ OUT_DIR := build
all: kern_mod
@true
kern_mod: mypipe.c
kern_mod: wendy.c
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) MO=$(PWD)/build/kern
install:
insmod ./build/mypipe.ko
sudo insmod ./build/kern/wendy.ko
uninstall:
rmmod mypipe
sudo rmmod wendy
reader:
mkdir -p $(OUT_DIR)

View File

@@ -39,12 +39,12 @@ static DECLARE_WAIT_QUEUE_HEAD(read_queue);
static DECLARE_WAIT_QUEUE_HEAD(write_queue);
static int mypipe_open(struct inode *inode, struct file *file) {
printk("Mypipe opened.");
printk(KERN_INFO "Wendy opened.");
return 0;
}
static int mypipe_release(struct inode *inode, struct file *file) {
printk("Mypipe released.");
printk(KERN_INFO "Wendy released.");
return 0;
}
@@ -102,8 +102,8 @@ out:
return ret;
}
static ssize_t mypipe_write(struct file *filep, const char __user *buf, size_t size,
loff_t *offset) {
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;
@@ -164,6 +164,12 @@ const struct file_operations mypipe_fops = {.owner = THIS_MODULE,
.write = mypipe_write,
.release = mypipe_release};
// Used to set the permission to allow any user to r/w
static int mypipe_uevent(const struct device *dev, struct kobj_uevent_env *env) {
add_uevent_var(env, "DEVMODE=%#o", 0666);
return 0;
}
static int __init mypipe_init(void) {
int ret;
dev_t dev;
@@ -183,6 +189,7 @@ static int __init mypipe_init(void) {
ret = PTR_ERR(mypipedev_class);
goto del_cdev;
}
mypipedev_class->dev_uevent = mypipe_uevent;
// Create a cdev in our pdata
cdev_init(&pdata.cdev, &mypipe_fops);