From 75efebac1e1eae7e23e121091cde1963fa2d8d26 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 16 Feb 2009 00:42:44 +0000 Subject: [PATCH] allocate files on unix when allocate storage mode is used --- src/file.cpp | 19 +++++++++++++++++++ src/storage.cpp | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/file.cpp b/src/file.cpp index b9117f551..2ff0ab2b6 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -765,6 +765,25 @@ namespace libtorrent ec = error_code(errno, get_posix_category()); return false; } + if ((m_open_mode & sparse) == 0) + { + // if we're not in sparse mode, allocate the storage +#ifdef F_PREALLOCATE + fstore_t f = {F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, s, 0}; + if (fcntl(m_fd, F_PREALLOCATE, &f) < 0) + { + ec = error_code(errno, get_posix_category()); + return false; + } +#else + int ret = posix_fallocate(m_fd, 0, s); + if (ret != 0) + { + ec = error_code(ret, get_posix_category()); + return false; + } +#endif + } #endif return true; } diff --git a/src/storage.cpp b/src/storage.cpp index 864ba321e..8db6d1f1f 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -104,6 +104,8 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef BOOST_WINDOWS #include +#else +#include #endif #include