QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1179|回复: 4

请教强人:关于设备驱动程序

[复制链接]
发表于 2004-2-14 10:54:20 | 显示全部楼层 |阅读模式
我用的是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]#

若有牛人,麻烦帮忙看看,为什么编译不通过?
--
发表于 2004-2-15 19:29:28 | 显示全部楼层
我也不会,我也正在搞这个设备驱动,你是学生吧?

你的源代码上没有file_operation这个结构呀
回复

使用道具 举报

发表于 2004-2-17 08:58:34 | 显示全部楼层
check this example.
http://crab.ele.uri.edu/tmp/chdev_kstat.tgz


u need to include kernel header files.
回复

使用道具 举报

发表于 2004-2-22 23:09:28 | 显示全部楼层
除了没有file_operations结构外
似乎你没有对GCC指明库的位置,用户程序和内核程序使用的库是不一样的。
回复

使用道具 举报

发表于 2004-3-1 23:40:35 | 显示全部楼层
[quote:49dcaee5eb="fresh_linuxer"]除了没有file_operations结构外
似乎你没有对GCC指明库的位置,用户程序和内核程序使用的库是不一样的。[/quote]

kernel module does not use user space library. he used wrong header file
check my attachment see how to use a makefile
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-16 10:44 , Processed in 0.096203 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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