LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 528|回复: 0

新手求助

[复制链接]
发表于 2005-5-6 10:35:51 | 显示全部楼层 |阅读模式
大家好啊,我是linux方面的新手,由于毕业设计做的是linux设备驱动程序研究,才开始接触它的,总的来说对它是一无所知。现在正在调试网上一个现成的字符设备驱动程序,可发现其中有很多编译错误,可不知从何开始调试,望大家能够帮帮我。因为我对gcc还是很陌生,谢谢啦!源代码如下:
#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)
static int write_tibet(struct inode *inode,struct file *file,
const char *buf,int count)
static int open_tibet(struct inode *inode,struct file *file )
static void release_tibet(struct inode *inode,struct file *file )
static void release_tibet(struct inode *inode,struct file *file )

struct file_operations test_fops = {
NULL,
read_test,
write_test,
NULL, /* test_readdir */
NULL,
NULL, /* test_ioctl */
NULL, /* test_mmap */
open_test,
release_test, NULL, /* test_fsync */
NULL, /* test_fasync */
/* nothing more, fill with NULLs */
};  
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;
}

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;
}
void cleanup_module(void)
{
unregister_chrdev(test_major, "test");
}  

编译结果如下:
[root@localhost root]# gcc -O2 -DMODULE -D__KERNEL__ -c test.c
In file included from /usr/include/linux/fs.h:23,
                 from test.c:2:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userland!
In file included from /usr/include/linux/sched.h:14,
                 from /usr/include/linux/mm.h:4,
                 from test.c:3:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
                 from /usr/include/asm/system.h:7,
                 from /usr/include/linux/sched.h:16,
                 from /usr/include/linux/mm.h:4,
                 from test.c:3:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/mm.h:4,
                 from test.c:3:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
                 from /usr/include/linux/mm.h:4,
                 from test.c:3:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
test.c: At top level:
test.c:11: variable `test_fops' has initializer but incomplete type
test.c:12: warning: excess elements in struct initializer
test.c:12: warning: (near initialization for `test_fops')
test.c:13: `read_test' undeclared here (not in a function)
test.c:13: warning: excess elements in struct initializer
test.c:13: warning: (near initialization for `test_fops')
test.c:14: `write_test' undeclared here (not in a function)
test.c:14: warning: excess elements in struct initializer
test.c:14: warning: (near initialization for `test_fops')
test.c:15: warning: excess elements in struct initializer
test.c:15: warning: (near initialization for `test_fops')
test.c:16: warning: excess elements in struct initializer
test.c:16: warning: (near initialization for `test_fops')
test.c:17: warning: excess elements in struct initializer
test.c:17: warning: (near initialization for `test_fops')
test.c:18: warning: excess elements in struct initializer
test.c:18: warning: (near initialization for `test_fops')
test.c:19: `open_test' undeclared here (not in a function)
test.c:19: warning: excess elements in struct initializer
test.c:19: warning: (near initialization for `test_fops')
test.c:20: `release_test' undeclared here (not in a function)
test.c:20: warning: excess elements in struct initializer
test.c:20: warning: (near initialization for `test_fops')
test.c:21: warning: excess elements in struct initializer
test.c:21: warning: (near initialization for `test_fops')
test.c:24: warning: `struct file' declared inside parameter list
test.c:24: warning: its scope is only this definition or declaration, which is probably not what you want
test.c:24: warning: `struct inode' declared inside parameter list
test.c: In function `read_test':
test.c:27: `VERIFY_WRITE' undeclared (first use in this function)
test.c:27: (Each undeclared identifier is reported only once
test.c:27: for each function it appears in.)
test.c: At top level:
test.c:37: warning: `struct file' declared inside parameter list
test.c:37: warning: `struct inode' declared inside parameter list
test.c:42: warning: `struct file' declared inside parameter list
test.c:42: warning: `struct inode' declared inside parameter list
test.c: In function `open_test':
test.c:44: `MOD_INC_USE_COUNT' undeclared (first use in this function)
test.c: At top level:
test.c:48: warning: `struct file' declared inside parameter list
test.c:48: warning: `struct inode' declared inside parameter list
test.c: In function `release_test':
test.c:50: `MOD_DEC_USE_COUNT' undeclared (first use in this function)
test.c: In function `init_module':
test.c:60: `KERN_WARNING' undeclared (first use in this function)
test.c:60: parse error before string constant
/usr/include/linux/timer.h: At top level:
test.c:11: storage size of `test_fops' isn't known
希望大家能帮调调错误!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表