内核读取和写入 - 之所以使用参数loff_t *石油换食品计划,而不是直接filp-> f_pos使用 [英] kernel reads and writes - Reason why use loff_t *offp instead of direct filp->f_pos usage

查看:1630
本文介绍了内核读取和写入 - 之所以使用参数loff_t *石油换食品计划,而不是直接filp-> f_pos使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下功能,从LDD采取:

In following functions, taken from ldd:

ssize_t read(struct file *filp, char __user *buff, size_t count, loff_t *offp);
ssize_t write(struct file *filp, const char __user *buff, size_t count, loff_t *offp);

为什么有参数loff_t *石油换食品计划的需要?我不能用直接的filp更新f_pos?

Why there is the need of loff_t *offp? Can't I use directly filp to update f_pos?

此外,在第54页的作者说,读取和写入会使用它们接收到的最后一个参数,而不是作用于filp-> f_pos直接。一个例外,这个指针更新的位置......

Moreover in page 54 the author says "read and write should update a position using the pointer they receive as the last argument instead of acting on filp->f_pos directly. The one exception to this..."

好,更好地使用指针石油换食品计划,但是为什么呢?

Ok, better use the pointer offp, but why?

推荐答案

filp-> f_pos 是文件当前指针位置,而石油换食品计划是用户确实给文件访问。你对成功的读/写操作提前文件指针,如果你失败了,你不应该更改文件指针。内核是它本身,如果你没有成功的读/写它会改变 filp-> f_pos 石油换食品计划。引用LDD3:

filp->f_pos is current pointer position in file, whereas offp is where user does access to file. You advance file pointer on successful read/write operation, if you failed you should not change file pointer. Kernel does it itself, if you successfully did read/write it will change filp->f_pos to offp. Citing LDD3:

无论数据的方法传输量,他们应该
  一般在石油换食品计划*的更新文件中的位置重新present当前
  系统调用成功完成后文件的位置。该
  然后,内核传播的文件位置改变回文件
  结构在适当的时候。

Whatever the amount of data the methods transfer, they should generally update the file position at *offp to represent the current file position after successful completion of the system call. The kernel then propagates the file position change back into the file structure when appropriate.

这篇关于内核读取和写入 - 之所以使用参数loff_t *石油换食品计划,而不是直接filp-> f_pos使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆