|
我写了一个虚拟的字符驱动,编译没有问题,可是作为模块导入时,却出现如下的错误提示:
unresolved symbol DECLARE_WAIT_QUEUE
下面是源码,请帮忙找一下原因,谢谢!
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define test_major 253
MODULE_LICENSE("GPL");
static ssize_t test_read(struct file *,char *,size_t,loff_t *);
static ssize_t test_write(struct file *,const char *,size_t,loff_t *);
static int __init test_init(void);
static void __exit test_exit(void);
static wait_queue_head_t outq;
static wait_queue_t wait;
static int head=0,tail=0;
static char buf[10];
struct file_operations test_fops=
{
read:test_read,write:test_write,
};
static int __init test_init(void)
{
int ret;
ret=register_chrdev(test_major,"test",&test_fops);
if(ret)
{
printk("test_dev register failed!!!\n");
}
else
{
printk("test_dev register success!!!\n");
init_waitqueue_head(&outq);
}
return ret;
}
static void __exit test_exit(void)
{
unregister_chrdev(test_major,"test");
}
static ssize_t test_read(struct file *filp, char *buf1,size_t count,loff_t *off)
{
DECLARE_WAIT_QUEUE(wait,current);
char out_data;
if(head==tail)
{
if(filp->f_flags && O_NONBLOCK)
{
return -EAGAIN;
}
add_wait_queue(&outq,&wait);
current->state=TASK_INTERRUPTIBLE;
while((head==tail)&&!signal_pending(current))
{
schedule();
current->state=TASK_INTERRUPTIBLE;
}
if(head==tail)
{
return count;
}
current->state=TASK_RUNNING;
remove_wait_queue(&outq,&wait);
out_data=get_bufdata();
if(copy_to_user(buf1,&out_data,sizeof(out_data)));
return -EFAULT;
}
return count;
}
static char get_bufdata(void)
{
int last;
last=tail;
if(++tail==10)
tail=0;
return buf[last];
}
static ssize_t test_write(struct file *filp, const char *buf1,size_t len,loff_t *off)
{
buf[head]=buf1;
if(++head==10)
head=0;
wake_up_interruptible(&outq);//唤醒等待队列
return sizeof(char);
}
module_init(test_init);
module_exit(test_exit);
|
|