When the new hello driver is handwritten, the problem is solved-Linux general technology-Linux programming and kernel information. The following is a detailed description. The younger brother just started to learn about linux simple driver. The driver can be insmod, but when an application is executed to call this driver, it does not respond because it is printed when I run the open () function.
This is the driver source code.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Static int hello_drv_open ()
{
Printk ("hello beautiful world !! \ N ");
Return 0;
}
Static int hello_drv_write ()
{
Printk ("crul world! \ N ");
Return 0;
}
Static struct file_operations hello_drv_fops () =
{
. Owner = THIS_MODULE,
. Open = hello_drv_open,
. Write = hello_drv_write,
}
Static int hello_drv_init (void)
{
Register_chrdev (260, "hello", & hello_drv_fops );
Return 0;
}
Void hello_drv_exit ()
{
Unregister_chrdev (260, "hello ");
}
Module_init (hello_drv_init );
Module_exit (hello_drv_exit );
Below is the test program
# Include
# Include
# Include
# Include
Int main (int argc, char ** argv)
{
Int fd;
Int val = 1;
Fd = open ("/dev/hello", O_RDWR );
If (fd <0)
Printf ("your directory can not open \ n ");
Write (fd, & val, 4 );
Return 0;
}
Solution
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service