From 9b368059deec8c9270bb0b384e894fc34ee07995 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 17 Mar 2022 18:25:38 -0500 Subject: [PATCH] Update comments and add "sanity check" from kernel commit f16acc9d9b376. (The kernel's been doing this since 2019, but older kernels may not, so...) --- lib/portability.c | 5 ++--- scripts/genconfig.sh | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/portability.c b/lib/portability.c index d7648a8f..4d9313c6 100644 --- a/lib/portability.c +++ b/lib/portability.c @@ -623,9 +623,8 @@ int get_block_device_size(int fd, unsigned long long* size) } #endif -// TODO copy_file_range // Return bytes copied from in to out. If bytes <0 copy all of in to out. -// If consuemd isn't null, amount read saved there (return is written or error) +// If consumed isn't null, amount read saved there (return is written or error) long long sendfile_len(int in, int out, long long bytes, long long *consumed) { long long total = 0, len, ww; @@ -639,7 +638,7 @@ long long sendfile_len(int in, int out, long long bytes, long long *consumed) errno = 0; if (copy_file_range) { - if (bytes<0) len = INT_MAX; + if (bytes<0 || bytes>(1<<30)) len = (1<<30); len = syscall(__NR_copy_file_range, in, 0, out, 0, len, 0); if (len < 0 && errno == EINVAL) copy_file_range = 0; diff --git a/scripts/genconfig.sh b/scripts/genconfig.sh index 38af2b36..d8f5241a 100755 --- a/scripts/genconfig.sh +++ b/scripts/genconfig.sh @@ -101,6 +101,8 @@ EOF int main(void) { char buf[100]; getrandom(buf, 100, 0); } EOF + # glibc requires #define GNU to get the wrapper for this Linux system call, + # so just use syscall(). probesymbol TOYBOX_COPYFILERANGE << EOF #include #include -- 2.39.2