求助:驱动test编译问题,恳请高手帮忙。急,万分感谢。
make 后的错误信息如下:
[root@localhost test]# make
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux-2.4.20-8/include -c test.c
test.c: In function `read_test':
test.c:14: warning: implicit declaration of function `verify_area'
test.c:14: `VERIFY_WRITE' undeclared (first use in this function)
test.c:14: (Each undeclared identifier is reported only once
test.c:14: for each function it appears in.)
test.c:19: warning: implicit declaration of function `__put_user'
test.c:20: warning: statement with no effect
test.c: In function `open_tibet':
test.c:32: `MOD_INC_USE_COUNT' undeclared (first use in this function)
test.c: In function `release_tibet':
test.c:37: `MOD_DEC_USE_COUNT' undeclared (first use in this function)
test.c: At top level:
test.c:42: warning: initialization from incompatible pointer type
test.c:43: `write_test' undeclared here (not in a function)
test.c:43: initializer element is not constant
test.c:43: (near initialization for `test_fops.write')
test.c:48: `open_test' undeclared here (not in a function)
test.c:48: initializer element is not constant
test.c:48: (near initialization for `test_fops.open')
test.c:49: `release_test' undeclared here (not in a function)
test.c:49: initializer element is not constant
test.c:49: (near initialization for `test_fops.release')
test.c:27: warning: `write_tibet' defined but not used
test.c:31: warning: `open_tibet' defined but not used
test.c:36: warning: `release_tibet' defined but not used
make: *** [test.o] Error 1
========================================================================
我的makefile文件如下:
C=gcc
MODCFLAGS:=-Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux-2.4.20-8/include
test.o:test.c
$(CC) $(MODCFLAGS) -c test.c
========================================================================
我的C源程序如下:
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
unsigned int test_major = 0;
static int read_test(struct inode *node, struct file *file,
char *buf, int count)
{
int left;
if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
return -EFAULT;
for(left = count ; left > 0 ; left--)
{
__put_user(1, buf, 1);
buf ;
}
return count;
}
/********************************************************************/
static int write_tibet(struct inode *inode, struct file *file,
const char *buf, int count)
{
return count;
}
static int open_tibet(struct inode *inode, struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
static void release_tibet(struct inode *inode, struct file *file )
{
MOD_DEC_USE_COUNT;
}
/********************************************************************/
struct file_operations test_fops = {
NULL,
read:read_test,
write:write_test,
NULL, /* test_readdir */
NULL,
NULL, /* test_ioctl */
NULL, /* test_mmap */
open:open_test,
release:release_test, NULL, /* test_fsync */
NULL, /* test_fasync */
/* nothing more£¬ fill with NULLs */
};
/******************************************************************/
int init_module(void)
{
int result;
result = register_chrdev(0, "test", &test_fops);
if (result < 0) {
printk(KERN_INFO "test: can't get major number\n");
return result;
}
if (test_major == 0){
test_major = result; /* dynamic */
return 0;
}
}
========================================================================
不知是什么原因,恳请高手帮忙看看,小弟多谢了!