|
以下我的第一个驱动程序代码,但似乎我对编写驱动程序的理解不对
在编译时有奇怪的错误,大虾们帮忙指点一下
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/fs.h>
static int major;
int my_open(struct inode *inode,struct file *filp)
{
MOD_INC_USE_COUNT;
printk(KERN_ALERT"Device is open\n");
return 0;
}
int my_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
printk(KERN_ALERT"Device is closed\n");
return 0;
}
struct file_operations my_ops={
open: my_open,
release:my_release,
};
int init_module(void)
{
major=register_chrdev(0,"mydriver",&my_ops);
if(major<=0)
{
printk(KERN_ALERT"Fails to register_chrdev()\n");
return major;
}
return 0;
}
void cleanup_module(void)
{
major=unregister_chrdev(major,"mydriver");
if(major!=0)
printk(KERN_ALERT"Fails to call unregister_chrdev()\n");
}
gcc -Wall -O2 -D__KERNEL__ -DMODULE -c mydriver.c
提示错误信息:my_ops的大小不能确定,且不识别open和release
还有警告信息:在用户区程序里使用了核心的头文件 |
|