From f23607bc0567d9c1fd1d25fd752e3d9900514f63 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 21 Jan 2012 23:24:24 +0000 Subject: [PATCH] make sparse_end support unbuffered files --- src/file.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index f6e3e68bd..cf04edfd0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1812,13 +1812,24 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { error_code ec; size_type file_size = get_size(ec); if (ec) return start; - in.FileOffset.QuadPart = start; - in.Length.QuadPart = file_size - start; + + if (m_open_mode & no_buffer) + { + boost::uint64_t mask = size_alignment()-1; + in.FileOffset.QuadPart = start & (~mask); + in.Length.QuadPart = ((file_size + mask) & ~mask) - in.FileOffset.QuadPart; + TORRENT_ASSERT((in.Length.QuadPart & mask) == 0); + } + else + { + in.FileOffset.QuadPart = start; + in.Length.QuadPart = file_size - start; + } + if (!DeviceIoControl(m_file_handle, FSCTL_QUERY_ALLOCATED_RANGES , &in, sizeof(FILE_ALLOCATED_RANGE_BUFFER) , &buffer, sizeof(FILE_ALLOCATED_RANGE_BUFFER), &bytes_returned, 0)) { - int err = GetLastError(); if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return start; }