我的驱动程序模块,不能加载!!!

xiayu0912 2007-08-21 10:34:58
我才学驱动程序,按自己的理解写了个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

...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiayu0912 2007-08-21
  • 打赏
  • 举报
回复
dai_weitao(疯狂Linux C++社区) ( ) 信誉:100 2007-08-21 11:30:26 得分: 0


必须以root用户加载模块.


--------------------------------------
我是以root用户加载的

hzcpig() ( ) 信誉:100 2007-08-21 11:42:55 得分: 0


gcc -I /usr/src/linux-2.4.20-8/include -c hello.c //编译

-----------------------------------------------

模块编译的选项错误

gcc -c -D__KERNEL__ -DMODULE -o hello.o hello.c



-----------------------
我在文件开头定义了#define __KERNEL__ 和#define MODULE了的

现在我把init_module()的返回值变成0(return 0)之后,就加载正常了,如果为return 1,就会出现我上面说的那种情况,不知是为什么?
hzcpig 2007-08-21
  • 打赏
  • 举报
回复
gcc -I /usr/src/linux-2.4.20-8/include -c hello.c //编译

-----------------------------------------------

模块编译的选项错误

gcc -c -D__KERNEL__ -DMODULE -o hello.o hello.c

dai_weitao 2007-08-21
  • 打赏
  • 举报
回复
必须以root用户加载模块.
menuconfig 2007-08-21
  • 打赏
  • 举报
回复
c语言 一要 好好看看

return 0 是正常

4,436

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧