- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在以下函数中,取自 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 *offp
?不能直接用filp
更新f_pos
吗?
此外,在第 54 页,作者说:
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...
好的,所以最好使用 offp
指针,但为什么呢?
最佳答案
filp->f_pos
是文件中的当前指针位置,而 offp
是用户访问文件的位置。你在成功的读/写操作上推进文件指针,如果你失败了你不应该改变文件指针。内核自己做,如果你成功读/写它会将 filp->f_pos
更改为 offp
。引用 LDD3:
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.
关于c - 为什么使用 loff_t *offp 而不是直接使用 filp->f_pos 的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23501185/
在以下函数中,取自 LDD: ssize_t read(struct file *filp, char __user *buff, size_t count, loff_t *offp); ssize
我是一名优秀的程序员,十分优秀!