diff --git a/ChangeLog b/ChangeLog index 212953304..133fd8bdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -93,6 +93,7 @@ * only keeps one outstanding duplicate request per peer reduces waste download, specifically when streaming * added support for storing per-peer rate limits across reconnects + * improved fallocate support * disabled feature to drop requests after having been skipped too many times * fixed range request bug for files larger than 2 GB in web seeds diff --git a/src/file.cpp b/src/file.cpp index ed5533bc3..795bb23cd 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -76,6 +76,15 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +#include +#include // For __NR_fallocate + +// circumvent the lack of support in glibc +static int fallocate(int fd, int mode, loff_t offset, loff_t len) +{ + return syscall(__NR_fallocate, fd, mode, offset, len); +} + #elif defined __APPLE__ && defined __MACH__ // mac specifics @@ -1439,6 +1448,13 @@ namespace libtorrent ec.assign(errno, get_posix_category()); return false; } +#elif defined TORRENT_LINUX + int ret = fallocate(m_fd, FALLOC_FL_KEEP_SIZE, 0, s); + if (ret != 0 && ret != EOPNOTSUPP && errno != ENOSYS) + { + ec.assign(ret, get_posix_category()); + return false; + } #elif TORRENT_HAS_FALLOCATE int ret = posix_fallocate(m_fd, 0, s); if (ret != 0)