- 爱易网页
-
Linux
- 驱动编译异常 variable `globalvar_fops' has initializer but incomplete type
日期:2014-05-16 浏览次数:20828 次
驱动编译错误 variable `globalvar_fops' has initializer but incomplete type
#include <linux/module.h>
#include <linux/init.h>
#include </usr/src/linux-2.4.20-8/include/linux/fs.h>
#include <asm/uaccess.h>
#include <linux/kernel.h>
#include <errno.h>
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
MODULE_LICENSE ( "GPL ");
#define MAJOR_NUM 254
static ssize_t globalvar_read(struct file *, char *, size_t , loff_t * );
static ssize_t globalvar_write(struct file *, const char *, size_t , loff_t *);
static int global_var=0;
static ssize_t globalvar_read(struct file *filp, char * buf, size_t len, loff_t *off)
{
if(copy_to_user(buf, &global_var, sizeof(int)))
{
return -EFAULT;
}
return sizeof(int);
}
static ssize_t globalvar_write(struct file *filp, const char *buf, size_t len, loff_t *off)
{
if(copy_from_user(&global_var, buf,sizeof(int)))
{
return -EFAULT;
}
return sizeof(int);
}
static struct file_operations globalvar_fops =
{
read: globalvar_read,
write: globalvar_write,
} ;
static int __init globalvar_init(void)
{
int ret;
ret = register_chrdev(MAJOR_NUM, "glovalvar ", &globalvar_fops);
if(ret)
{
printk( "global register failure ");
}
else
{
printk( "global register sucess ");
}
return ret;
}
static int __exit globalvar_exit(void)
{
int ret;
ret = unregister_chrdev(MAJOR_NUM, "globalvar ");
if(ret)
{
printk( "gloval unregister failure ");
}
else
{
printk( "global unregistr success ");