| |

VerySource

 Forgot password?
 Register
Search
View: 2137|Reply: 3

Linux kernel master, please take the move

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-7 21:00:01
| Show all posts |Read mode
When writing a linux driver, you will call the register_chrdev() function to register your own driver (2.4, character driver). This function writes our own file_operation into a device struct structure.
When we test our own driver, we will call the system call open() to open the device file. The sys_open() function will call filep_open(). This function will call open_namei() and dentry_open() to generate a struct file structure, and The file_operation field in the structure is the file_operation field in the inode structure.
Question: How to assign the file_operation structure written by our driver to the inode structure in the kernel so that the user program can call our driver correctly?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-8 15:15:01
| Show all posts
Use the data structure to return the pointer callback
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-12-8 15:30:01
| Show all posts
I have already figured it out. When mknod, sys_mknod first assigns the default chrdev_fops to the inode when creating the device file index, and calls the default operation chrdev_open() when the device file is opened to write the operation in this function. Associate with the inode of the device file.
Reply

Use magic Report

0

Threads

1

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-15 15:45:08
| Show all posts
In the case of mknod, sys_mknod first assigns the default chrdev_fops to the inode when establishing the device file index, and calls the default operation chrdev_open() when opening the device file. In this function, the operation written by itself is associated with the inode of the device file
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list