- 论坛徽章:
- 3
|
全局定义:char kbuf[] = "hello world";
static ssize_t read_test(struct file *file,char *outbuf,size_t count,loff_t *f_pos)
{
printk(KERN_ALERT "read1\n");
int bytes_read=0;
if(verify_area(VERIFY_WRITE,outbuf,count)==-EFAULT)
return -EFAULT;
Message_Ptr=kbuf;
while(count && *Message_Ptr)
{
//if(put_user(*(Message_Ptr++),outbuf++)) //最好别这么写,函数调用有时候会出问题
if(put_user(*(Message_Ptr),outbuf))
return -EINVAL;
Message_Ptr++;
outbuf++;
count--;
bytes_read++;
}
return bytes_read;
}
static ssize_t write_test(struct file *file,const char *outbuf,size_t count,loff_t *f_pos)
{
memset(kbuf, 0, sizeof(kbuf));
copy_from_user(kbuf,outbuf,count);
return count;
} |
|