当前时区 GMT+8, 现在时间是 2008-7-7 10:29 游客: 注册 登录 仅登录论坛 | 搜索 帮助
标题: 求助:第一次写驱动
xmuch
新手上路
Rank: 1



UID 249204
精华 0
积分 1
帖子 2
阅读权限 10
注册 2008-4-19
状态 离线
发表于 2008-4-19 18:40  资料  短消息  加为好友 
求助:第一次写驱动

第一次学写驱动,试着按照 linuxdevicedriver3 里说的写的一个驱动

#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/error.h>
#include<linux/config.h>
#include<asm/segment.h>
unsigned int test_major = 0;
static int read_test(struct inode *inode,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 void release_test(struct inode *inode,struct file *file,){
MOD_DEC_USE_COUNT;
}

struct file_operations test_fops = {
NULL,
read_test,
write_test,
NULL,
NULL,
NULL,
NULL,
open_test,
release_test,
NULL,
};

int init_module(void){
int result;
result = regster_chrdev(0,"test",&test_fops);
if(result < 0){
printk(KERN_INFO "test:can't get major number!\n");
return result;
}
if(test_major == 0)test_major = result;
return 0;
}

void cleanup_module(void){
unregister_chrdev(test_major,"test");
}

一般设备驱动写这样一个.c文件就可以了吗?(本人实在不太懂,都没有说这样些一个完整驱动的例子),????
然后就执行:
gcc -O2 -DMODULE -D__KENEL__ -c test.c

出错:
linux/module.h:No such file or director
linux/mm.h:No such file or directory
linux/error.h:No such file or directory
linux/config.h:No such file or directory
asm/segment.h:No such file or directory

为什么会这样?是gcc找不到lib文件?我有装 linux-headers-

顶部
crook
新手上路
Rank: 1



UID 248465
精华 0
积分 19
帖子 37
阅读权限 10
注册 2008-4-2
状态 离线
发表于 2008-5-4 23:15  资料  短消息  加为好友 
编译问题。

linuxdevicedriver3 上面好像有个Makefile的例子,用那个编译驱动。

顶部
sunkepie
新手上路
Rank: 1



UID 249811
精华 0
积分 2
帖子 4
阅读权限 10
注册 2008-5-5
状态 离线
发表于 2008-5-5 15:02  资料  短消息  加为好友 
等指定 head的目录 -I/...

顶部
 


Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
清除 Cookies - 联系我们 - 中国Linux公社 - WAP