Skip to content

Instantly share code, notes, and snippets.

@gut
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gut/ee81b29f536fed2de5d6 to your computer and use it in GitHub Desktop.
Save gut/ee81b29f536fed2de5d6 to your computer and use it in GitHub Desktop.
readfile system call behaves differently on x86_64 vs ppc64le. Reason: old kernel bug from ppc64le. Move to at least version 3.16.0 and it's ok!
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#define BIG_OFFSET 8589934592
#define TMP_FILE1 "XXXXYYYYZZZ45212480"
#define TMP_FILE2 "666666DDDDDFFFF2480"
int main(void)
{ // STRACE OUTPUT:
off_t off = BIG_OFFSET; // X86_64 PPC64le
ssize_t readfile_ret = 0; // ============================================================================================
int f1 = open(TMP_FILE1, O_RDWR|O_CREAT, 0700); // 3 3
int f2 = open(TMP_FILE2, O_RDWR|O_CREAT, 0700); // 4 4
lseek(f2, BIG_OFFSET, SEEK_SET); // 8589934592 8589934592
write(f2, "00001111222233334444555566667777", 32); // 32 32
lseek(f2, 0, SEEK_SET); // 0 0
readfile_ret = sendfile(f1, f2, &off, 16); // 16 -1 EOVERFLOW (Value too large for defined data type)
close(f1); // 0 0
close(f2); // 0 0
unlink(TMP_FILE1); // -1 ENOENT (No such file or directory) -1 ENOENT (No such file or directory)
unlink(TMP_FILE2); // -1 ENOENT (No such file or directory) -1 ENOENT (No such file or directory)
printf("Readfile return: %d\n", readfile_ret);
return 0;
}
/*
* System info: (uname -a)
* Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
* Linux debian-le-1-2 3.13.4 #2 SMP Fri Apr 11 15:34:54 UTC 2014 ppc64le GNU/Linux
*/
// vim: noai:ts=4:sw=4:sts=4:et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment