From 5bdb5831626d6000a49d6ce6179810de28d86e29 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 21 Sep 2015 14:58:20 -0700 Subject: [PATCH] remove fallocate hack (in master) --- ChangeLog | 2 +- include/libtorrent/config.hpp | 8 ++++++++ src/file.cpp | 36 +---------------------------------- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26fb345e1..54180e9ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,7 +73,7 @@ * almost completely changed the storage interface (for custom storage) * added support for hashing pieces in multiple threads - + * fix fallocate hack on linux (fixes corruption on some architectures) * fix auto-manage bug with announce to tracker/lsd/dht limits * improve DHT routing table to not create an unbalanced tree * fix bug in uTP that would cause any connection taking more than one second diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 335db19e1..9787cd213 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -224,6 +224,14 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_USE_IFADDRS 1 #define TORRENT_USE_POSIX_MEMALIGN 1 #define TORRENT_USE_FDATASYNC 1 + +// posix_fallocate() is available under this condition +#if _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L +#define TORRENT_HAS_FALLOCATE 1 +#else +#define TORRENT_HAS_FALLOCATE 0 +#endif + #endif // ANDROID #if defined __GLIBC__ && ( defined __x86_64__ || defined __i386 \ diff --git a/src/file.cpp b/src/file.cpp index 94f3842d1..c2491a0d1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -131,23 +131,6 @@ POSSIBILITY OF SUCH DAMAGE. #define lseek lseek64 #endif -#include // For __NR_fallocate - -// circumvent the lack of support in glibc -static int my_fallocate(int fd, int mode, loff_t offset, loff_t len) -{ -#ifdef __NR_fallocate - // the man page on fallocate differes between versions of linux. - // it appears that fallocate in fact sets errno and returns -1 - // on failure. - return syscall(__NR_fallocate, fd, mode, offset, len); -#else - // pretend that the system call doesn't exist - errno = ENOSYS; - return -1; -#endif -} - #elif defined __APPLE__ && defined __MACH__ && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // mac specifics @@ -2136,23 +2119,6 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { int ret; #endif -#if defined TORRENT_LINUX - ret = my_fallocate(native_handle(), 0, 0, s); - // if we return 0, everything went fine - // the fallocate call succeeded - if (ret == 0) return true; - // otherwise, something went wrong. If the error - // is ENOSYS, just keep going and do it the old-fashioned - // way. If fallocate failed with some other error, it - // probably means the user should know about it, error out - // and report it. - if (errno != ENOSYS && errno != EOPNOTSUPP && errno != EINVAL) - { - ec.assign(errno, generic_category()); - return false; - } -#endif // TORRENT_LINUX - #if TORRENT_HAS_FALLOCATE // if fallocate failed, we have to use posix_fallocate // which can be painfully slow @@ -2160,7 +2126,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { // define TORRENT_HAS_FALLOCATE to 0. ret = posix_fallocate(native_handle(), 0, s); // posix_allocate fails with EINVAL in case the underlying - // filesystem does bot support this operation + // filesystem does not support this operation if (ret != 0 && ret != EINVAL) { ec.assign(ret, generic_category());