|
我用的是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);
}
编译不通过:
[root@doudou doudou]# 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
[root@doudou doudou]#
若有牛人,麻烦帮忙看看,为什么编译不通过?
-- |
|