On Sun, Dec 4, 2016 at 9:05 PM, Rick Payne <ri...@rossfell.co.uk> wrote:

>
> What about something like the following. Not sure if you favour a
> different approach rather than checking the extents in the sendfile code,
> but this certainly gets me moving forward again.
>

Your patch looks good - my only question was whether we should be using
fstat() here or, because we already have the file structure in_fp, we could
also use in_fp->stat() (I think) directly. But maybe you're right and it's
better to just use the general system calls like you did - we are already
using lseek() and mmap() in the same code, and not some internal functions,
so why not use fstat() as well?

>
> I can work on some tst-sendfile code too if you want - but don’t want to
> duplicate effort if you’re already looking into it… Will send proper patch
> after discussion.
>

That would be great. I only open the bug tracker issue (please write "Fixes
#..." on the commit message so it will be closed), but wasn't working on
any code or test.

Thanks!
Nadav.


>
> Cheers,
> Rick
>
> diff --git a/fs/vfs/main.cc b/fs/vfs/main.cc
> index 8fecc08..b611ff2 100644
> --- a/fs/vfs/main.cc
> +++ b/fs/vfs/main.cc
> @@ -2039,6 +2039,21 @@ int sendfile(int out_fd, int in_fd, off_t *_offset,
> size_t count)
>          offset = lseek(in_fd, 0, SEEK_CUR);
>      }
>
> +    // Constrain count to the extent of the file...
> +    struct stat st;
> +    if (fstat(in_fd, &st) < 0) {
> +      return -1;
> +    } else {
> +      if (offset >= st.st_size) {
> +        return 0;
> +      } else if ((offset + count) >= st.st_size) {
> +        count = st.st_size - offset;
> +        if (count == 0) {
> +          return 0;
> +        }
> +      }
> +    }
> +
>      size_t bytes_to_mmap = count + (offset % mmu::page_size);
>      off_t offset_for_mmap =  align_down(offset, (off_t)mmu::page_size);
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to