Fix a bug in sendfile(2) when files larger than page size and nbytes=0.

When nbytes=0, sendfile(2) should use file size. Because of the bug, it
was sending half of a file. The bug is that 'off' variable can't be used
for size calculation, because it changes inside the loop, so we should
use uap->offset instead.
This commit is contained in:
Pawel Jakub Dawidek 2007-04-19 05:54:45 +00:00
parent f40fd96d5b
commit fb1daf8164

View File

@ -2016,12 +2016,12 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
*/
pgoff = (vm_offset_t)(off & PAGE_MASK);
xfsize = omin(PAGE_SIZE - pgoff,
obj->un_pager.vnp.vnp_size - off -
obj->un_pager.vnp.vnp_size - uap->offset -
sbytes - loopbytes);
if (uap->nbytes)
rem = (uap->nbytes - sbytes - loopbytes);
else
rem = obj->un_pager.vnp.vnp_size - off -
rem = obj->un_pager.vnp.vnp_size - uap->offset -
sbytes - loopbytes;
xfsize = omin(rem, xfsize);
if (xfsize <= 0) {