我的驱动程序模块,不能加载!!!
我才学驱动程序,按自己的理解写了个open和release函数,但是加载模块时,出现错误提示,大家帮我看看我这个模块有错吗?
#define MODULE
#define __KERNEL__
#include <linux/module.h>
#include <linux/fs.h>
int xy_open(struct inode *inode,struct file * filp)
{
printk( "open\n ");
return 1;
}
int xy_release(struct inode *inode,struct file *filp)
{
printk( "close\n ");
return 1;
}
static struct file_operations xy_fop=
{
open: xy_open,
release: xy_release,
};
int init_module(void)
{
int result;
MODULE_LICENSE( "GPL ");
printk( "hello,world\n ");
result=register_chrdev(127, "xiayu ",&xy_fop);
if(result <0)
{
printk( "register_chrdev failure\n ");
return 0;
}
else
printk( "register_chrdev success\n ");
return 1;}
void cleanup_module(void)
{
int result;
printk( " <1> Goodbye cruel world\n ");
result=unregister_chrdev(127, "xiayu ");
if(result <0)
{
printk( "unregister_chrdev failure\n ");
}
else
printk( "unregister_chrdev success\n ");
}
gcc -I /usr/src/linux-2.4.20-8/include -c hello.c //编译
insmod hello.o //加载之后出现下面的信息
hello.o: init_module: Device or resource busy
Hint: insmod errors can be caused by incorrect module parameters, including invalid IO or IRQ parameters.
You may find more information in syslog or the output from dmesg
------解决方案--------------------必须以root用户加载模块.
------解决方案--------------------gcc -I /usr/src/linux-2.4.20-8/include -c hello.c //编译
-----------------------------------------------
模块编译的选项错误
gcc -c -D__KERNEL__ -DMODULE -o hello.o hello.c
------解决方案--------------------c语言 一要 好好看看
return 0 是正常