请教强人:关于设备驱动程序
我用的是radhat9。0, 2。4。20-8版的kernel这是一个最简单的空设备
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/fs.h>
#include<linux/wrapper.h>
#define NAME "null"
static int major=0;
static ssize_t read_null(struct file * file, char * buf,
size_t count, loff_t *ppos)
{
return 0;
}
static ssize_t write_null(struct file * file, const char * buf,
size_t count, loff_t *ppos)
{
return count;
}
static loff_t null_lseek(struct file * file, loff_t offset, int orig)
{
return file->f_pos = 0;
}
static struct file_operations null_fops = {
llseek: null_lseek,
read: read_null,
write: write_null,
};
int init_module()
{
major=module_register_chrdev(0,NAME,&null_fops);
return 0;
}
void cleanup_module()
{
module_unregister_chrdev(major,NAME);
}
编译不通过:
# gcc -O2 -D__KERNEL__ -DMODULE -o null.o -c null.c
In file included from /usr/include/linux/fs.h:23,
from null.c:3:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in user
land!
null.c:11: warning: `struct file' declared inside parameter list
null.c:11: warning: its scope is only this definition or declaration, which is
probably not what you want
null.c:17: warning: `struct file' declared inside parameter list
null.c:22: warning: `struct file' declared inside parameter list
null.c: In function `null_lseek':
null.c:24: dereferencing pointer to incomplete type
null.c: At top level:
null.c:27: variable `null_fops' has initializer but incomplete type
null.c:28: unknown field `llseek' specified in initializer
null.c:28: warning: excess elements in struct initializer
null.c:28: warning: (near initialization for `null_fops')
null.c:29: unknown field `read' specified in initializer
null.c:29: warning: excess elements in struct initializer
null.c:29: warning: (near initialization for `null_fops')
null.c:30: unknown field `write' specified in initializer
null.c:30: warning: excess elements in struct initializer
null.c:30: warning: (near initialization for `null_fops')
null.c:27: storage size of `null_fops' isn't known
#
若有牛人,麻烦帮忙看看,为什么编译不通过?
-- 我也不会,我也正在搞这个设备驱动,你是学生吧?
你的源代码上没有file_operation这个结构呀 check this example.
http://crab.ele.uri.edu/tmp/chdev_kstat.tgz
u need to include kernel header files. 除了没有file_operations结构外
似乎你没有对GCC指明库的位置,用户程序和内核程序使用的库是不一样的。 除了没有file_operations结构外
似乎你没有对GCC指明库的位置,用户程序和内核程序使用的库是不一样的。
kernel module does not use user space library. he used wrong header file
check my attachment see how to use a makefile
页:
[1]