- 论坛徽章:
- 0
|
我最近刚刚接触linux 看了一些书,感觉还不错,于是编写了一个很简单的驱动,可是怎么编译都通不过 请高手们帮忙看看啊 谢谢了!!
帮帮我啊我要郁闷死了~
编译后提示:
[root@zl wuliaotest]# gcc -D__KERNEL__-DMODULE-LINUX -c drvback.c
<command line>;: warning: ISO C requires whitespace after the macro name
drvback.c:127:1: warning: no newline at end of file
drvback.c:19: warning: `struct file' declared inside parameter list
drvback.c:19: warning: its scope is only this definition or declaration, which is probably not what you want.
drvback.c:19: warning: `struct inode' declared inside parameter list
drvback.c:46: warning: `struct file' declared inside parameter list
drvback.c:46: warning: `struct inode' declared inside parameter list
drvback.c:54: warning: `struct file' declared inside parameter list
drvback.c:54: warning: `struct inode' declared inside parameter list
drvback.c:62: warning: `struct file' declared inside parameter list
drvback.c:62: warning: `struct inode' declared inside parameter list
drvback.c:70: variable `test_fops' has initializer but incomplete type
drvback.c:72: warning: excess elements in struct initializer
drvback.c:72: warning: (near initialization for `test_fops')
drvback.c:74: warning: excess elements in struct initializer
drvback.c:74: warning: (near initialization for `test_fops')
drvback.c:76: warning: excess elements in struct initializer
drvback.c:76: warning: (near initialization for `test_fops')
drvback.c:78: warning: excess elements in struct initializer
drvback.c:78: warning: (near initialization for `test_fops')
drvback.c:80: warning: excess elements in struct initializer
drvback.c:80: warning: (near initialization for `test_fops')
drvback.c:82: warning: excess elements in struct initializer
drvback.c:82: warning: (near initialization for `test_fops')
drvback.c:84: warning: excess elements in struct initializer
drvback.c:84: warning: (near initialization for `test_fops')
drvback.c:86: warning: excess elements in struct initializer
drvback.c:86: warning: (near initialization for `test_fops')
drvback.c:88: warning: excess elements in struct initializer
drvback.c:88: warning: (near initialization for `test_fops')
drvback.c:88: warning: excess elements in struct initializer
drvback.c:88: warning: (near initialization for `test_fops')
drvback.c:90: warning: excess elements in struct initializer
drvback.c:90: warning:
源代码是:
#define __NO_VERSION__
#include <linux/module.h>;
#include <linux/version.h>;
#include <linux/kernel.h>;
char kernel_version [] = UTS_RELEASE;
#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;
unsigned int test_major = 0;
static int read_test(struct inode *node,struct file *file,
char *buf,int count)
{
int left;
if (verify_area(1,buf,count) == -EFAULT )
return -EFAULT;
for(left = count ; left >; 0 ; left--)
{
__put_user(1,buf,1);
buf++;
}
return count;
}
static int write_test(struct inode *inode,struct file *file,
const char *buf,int count)
{
return count;
}
static int open_test(struct inode *inode,struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
} static void release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
}
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 */
};
int init_module(void)
{
int result;
result = register_chrdev(0, "test", &test_fops);
if (result < 0) {
printk("test: can't get major number " ;
return result;
}
if (test_major == 0) test_major = result; /* dynamic */
return 0;
}
void cleanup_module(void)
{
unregister_chrdev(test_major, "test" ;
} |
|