I wrote a simple module. Why is the kernel function not running?

Source: Internet
Author: User
After writing a simple module, why is the kernel function not running-Linux general technology-Linux programming and kernel information? For details, refer to the following. # If defined (CONFIG_SMP)
# Define _ SMP __
# Endif

# If defined (CONFIG_MODVERSIONS)
# Define MODVERSIONS
# Include
# Endif

# Include
# Include
# Include
# Include

# Define BUFLEN 50

MODULE_LICENSE ("GPL ");
Int errno;
# Define _ kernel_syscils __
# Include


Int init_module (void)
{
Int fd, n;
Char * buffer = NULL;
Struct file * file = filp_open ("/usr/src/Hello", O_RDWR | O_CREAT, 0666 );
If (file-> f_op-> write)
{
Printk (KERN_DEBUG "AAAAA! \ N ");
File-> f_op-> write (file, "11111", 5, & file-> f_pos );
}
Return 0;
}
Void cleanup_module (void)
{
Printk (KERN_DEBUG "Sophia: Good-bye, kernel! \ N ");
}

Compile:
Gcc-D__KERNEL _-I/usr/src/linux-2.4.20-8/include/-DMODULE-Wall-O2-c test. c-o test. o
No error reported
Insmod test. o can be correctly loaded and the file "Hello" can be created.
However, you can view the log through dmesg | tail and find
If (file-> f_op-> write)
{
Printk (KERN_DEBUG "AAAAA! \ N ");
File-> f_op-> write (file, "11111", 5, & file-> f_pos );
} Not executed
I don't know why I didn't write 11111 to the file. Please give me some guidance!
Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.