本文介绍了如何copy_to_user在Linux内核中读取功能一个字符串,并用石油换食品计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
宣称:
static char status[128] = "off\0";
和实施读
功能:
static ssize_t read_proc(struct file *filep, char __user *buf,
size_t len, loff_t *offp)
{
ssize_t cnt = strlen(status), ret;
ret = copy_to_user(buf, status, cnt);
*offp += cnt;
return cnt;
}
- 如何兼顾
石油换食品计划
? - 目前它打印不已
状态
屏幕 - How do I take into account the
offp
? - currently it prints endless the
status
to screen
推荐答案
感谢这里的球员的意见,我想出了下面的实现,我相信这是用正确的方法石油换食品计划
:
Thanks the guys comments here I came up with the following implementation, which I believe is the right way to use offp
:
static ssize_t read_proc(struct file *filep, char __user *buf,
size_t len, loff_t *offp)
{
ssize_t cnt = strlen(status), ret;
/* ret contains the amount of chare wasn't successfully written to `buf` */
ret = copy_to_user(buf, status, cnt);
*offp += cnt - ret;
/* Making sure there are no left bytes of data to send user */
if (*offp > cnt)
return 0;
else
return cnt;
}
这篇关于如何copy_to_user在Linux内核中读取功能一个字符串,并用石油换食品计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!