问题描述
在以下功能中,取自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 * offp
?我不能直接使用 filp
更新 f_pos
吗?
Why there is the need of loff_t *offp
? Can't I use directly filp
to update f_pos
?
此外,在第54页中,作者说:
Moreover in page 54 the author says:
好的,所以最好使用 offp
指针,但是为什么呢?
OK, so it's better to use the offp
pointer, but why?
推荐答案
filp-> f_pos
是文件中的当前指针位置,而 offp
是用户访问的位置归档.如果读/写操作成功,则将文件指针前进,如果失败,则不应更改文件指针.内核会自己执行,如果您成功地进行了读/写操作,它将把 filp-> f_pos
更改为 offp
.引用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:
这篇关于为什么使用loff_t * offp而不是直接使用filp-> f_pos的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!