QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 802|回复: 1

从内核空间往用户空间写数据

[复制链接]
发表于 2005-3-17 14:46:40 | 显示全部楼层 |阅读模式
简单驱动实验程序,用__put_user给用户空间传递数据,用户应用程序就是收不到我设定的字符,打印出来的不对,请教,谢谢!
驱动模块程序主要功能部分:
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); //////////////////////////////////////////////////
buf++;
}
return count;
}
测试函数:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
main()
{
int testdev;
int i;
char buf[10];
testdev = open("/dev/test",O_RDWR);
if ( testdev == -1 )
{
printf("Cann't open file ");
exit(0);
}
read(testdev,buf,10); //////////////////////////////////////
for (i = 0; i < 10;i++)
printf("%c ",buf); /////////////////////////////////////////
close(testdev);
}
 楼主| 发表于 2005-3-22 09:30:50 | 显示全部楼层
是不是用verify_area()和access_ok(),效果不同,verify_area()作的事情不就是调用个access_ok么?
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-5-21 00:26 , Processed in 0.239171 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

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