简体   繁体   中英

Read from device file

I have a kernel module myModule with major number 100 and minor number 120. Here is what I did:

make all
sudo insmod ./myModule.ko
mknod ~/myModule c 100 120

When I check the log with

cat /proc/syslog

then it shows the printk() things from the init function.

But I have also implemented this function:

ssize_t myModule_read(struct file *f, char __user *user_buffer, size_t num, loff_t *offset);

It provides a printk() when a process reads from the device file. Since my device file is in my home directory, I tried the following:

cat ~/myModule

and

hexdump ~/myModule

but it said that there is no such device or address.

How can I actually trigger the read (or release) function then?

EDIT: In case the mknod was redundant: the device file is also not in the /dev/ directory. But it shows up with:

cat /proc/devices

您需要确定要设置从cdev_alloc()返回的cdev结构的struct file_operations *ops字段:

myModule->ops = &fops;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM