gpt4 book ai didi

linux - 了解设备驱动程序读写函数中的指针

转载 作者:太空宇宙 更新时间:2023-11-04 11:46:06 26 4
gpt4 key购买 nike

每个读/写函数都有一个参数loff_t *f_pos。我在示例中看到,在读取函数中,它会在我们读取时递增指针,而在写入函数中,它会在我们写入时递增此指针。

两者是同一个指针吗?

ssize_t scull_write(struct file *filp, const char __user *buf, size_t count,loff_t *f_pos)
ssize_t scull_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)

最佳答案

是的。但这是个好问题。当您实现驱动程序时,您为读取和写入设置 f_pos,调用代码存储您提供的值。所以在引擎盖下理论上可以有单独的读取和写入文件位置。

但是lseek的描述清楚地表明读取和写入都有一个位置。否则我们将需要一个 read_seek() 和一个 write_seek()。

关于linux - 了解设备驱动程序读写函数中的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57726679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com