allocate files on unix when allocate storage mode is used

This commit is contained in:
Arvid Norberg 2009-02-16 00:42:44 +00:00
parent ad216ddcd1
commit 75efebac1e
2 changed files with 21 additions and 0 deletions

View File

@ -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;
}

View File

@ -104,6 +104,8 @@ POSSIBILITY OF SUCH DAMAGE.
#ifdef BOOST_WINDOWS
#include <windows.h>
#else
#include <fcntl.h>
#endif
#include <boost/filesystem/exception.hpp>