|
.我参照网上的资料,写了第一个linux驱动程序,但是调试不能够通过,请高手给看看吧.下面是源程序,然后就是提示信息.非常感谢.我的联系方式:[email protected]
#include<linux/config.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/version.h>
#include<linux/types.h>
#include<linux/fs.h>
#include<linux/mm.h>
#include<linux/errno.h>
#include<asm/segment.h>
char kernel_version[]=UTS_RELEASE;
struct file_operations
{
int (*seek) (struct inode *,struct file * ,off_t,int);
int (*read) (struct inode *,struct file * ,char ,int);
int (*write) (struct inode *,struct file * ,off_t,int);
int (*readdir) (struct inode *,struct file *,struct dirent * ,int);
int (*select) (struct inode *,struct file *,int ,select_table *);
int (*ioctl) (struct inode *,struct file *,unsigned int ,unsigned long);
int (*mmap) (struct inode *,struct file * ,struct file *,struct vm_area_struct * );
int (*open) (struct inode *,struct file *);
int (*release) (struct inode * ,struct file *);
int (*fsync ) (struct inode * ,struct file *);
int (*fasync) (struct inode *,struct file *,int);
int (*check_media_change) (struct inode * ,struct file *);
int (*revalidate) (dev_t dev);
};
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_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("<0> 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");
}
使用如下命令编译(我用的是红帽9):
[root@localhost kernel]# gcc -O2 -DMODULE -D_KERNEL_ -c test.c
问题提示:
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/mm.h:4,
from test.c:10:
/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:10:
/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:10:
/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:10:
/usr/include/linux/timer.h:32: field `vec' has incomplete type
/usr/include/linux/timer.h:37: field `vec' has incomplete type
/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:63: field `list' has incomplete type
/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:17: warning: `struct file' declared inside parameter list
test.c:17: warning: its scope is only this definition or declaration, which is probably not what you want
test.c:17: warning: `struct inode' declared inside parameter list
test.c:18: warning: `struct file' declared inside parameter list
test.c:18: warning: `struct inode' declared inside parameter list
test.c:19: warning: `struct file' declared inside parameter list
test.c:19: warning: `struct inode' declared inside parameter list
test.c:20: warning: `struct dirent' declared inside parameter list
test.c:20: warning: `struct file' declared inside parameter list
test.c:20: warning: `struct inode' declared inside parameter list
test.c:21: parse error before "select_table"
test.c:21: warning: `struct file' declared inside parameter list
test.c:21: warning: `struct inode' declared inside parameter list
test.c:22: warning: `struct file' declared inside parameter list
test.c:22: warning: `struct inode' declared inside parameter list
test.c:23: warning: `struct vm_area_struct' declared inside parameter list
test.c:23: warning: `struct file' declared inside parameter list
test.c:23: warning: `struct inode' declared inside parameter list
test.c:24: warning: `struct file' declared inside parameter list
test.c:24: warning: `struct inode' declared inside parameter list
test.c:25: warning: `struct file' declared inside parameter list
test.c:25: warning: `struct inode' declared inside parameter list
test.c:26: warning: `struct file' declared inside parameter list
test.c:26: warning: `struct inode' declared inside parameter list
test.c:27: warning: `struct file' declared inside parameter list
test.c:27: warning: `struct inode' declared inside parameter list
test.c:28: warning: `struct file' declared inside parameter list
test.c:28: warning: `struct inode' declared inside parameter list
test.c:32: warning: `struct file' declared inside parameter list
test.c:32: warning: `struct inode' declared inside parameter list
test.c: In function `read_test':
test.c:35: `VERIFY_WRITE' undeclared (first use in this function)
test.c:35: (Each undeclared identifier is reported only once
test.c:35: for each function it appears in.)
test.c: At top level:
test.c:45: warning: `struct file' declared inside parameter list
test.c:45: warning: `struct inode' declared inside parameter list
test.c:50: warning: `struct file' declared inside parameter list
test.c:50: warning: `struct inode' declared inside parameter list
test.c: In function `open_test':
test.c:52: union has no member named `usecount'
test.c: At top level:
test.c:55: warning: `struct file' declared inside parameter list
test.c:55: warning: `struct inode' declared inside parameter list
test.c: In function `release_test':
test.c:57: union has no member named `usecount'
test.c: At top level:
test.c:62: warning: initialization from incompatible pointer type
test.c:63: warning: initialization from incompatible pointer type
test.c:68: warning: initialization from incompatible pointer type
test.c:69: warning: initialization from incompatible pointer type
test.c:91:2: warning: no newline at end of file
谢谢.非常感谢. |
|