Can't read from linux character device

杀马特。学长 韩版系。学妹 提交于 2019-11-28 12:54:09

You misaunderstood the concept of the .read function:

The reader (user space) sees only value returned by the .read and interpret it as a number of bytes which has been read.

As for the last parameter to the .read (position in your case), its interpretation is fully up to the driver's author. Value, pointed by position, is initialized to 0 by the kernel core when the file is opened. After that, kernel itself never modifies it.

If you want to always read from the beginning, you may just ignore position parameter:

return size_requested;

Or, semantically better, you may increment value, pointed by the position, so it will reflect total number of bytes read. But otherwise ignore it:

*position += size_requested;
return size_requested;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!