From dc4d50b117716a3b7df9805be4da21c2b75802b1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 14 Feb 2009 03:56:07 +0000 Subject: [PATCH] don't make files sparse when allocation mode is set on the storage (windows only) --- include/libtorrent/file.hpp | 1 + src/file.cpp | 2 +- src/storage.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 3f781f9dd..1b16d0c7e 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -95,6 +95,7 @@ namespace libtorrent rw_mask = read_only | write_only | read_write, no_buffer = 4, mode_mask = rw_mask | no_buffer, + sparse = 8, attribute_hidden = 0x1000, attribute_executable = 0x2000, diff --git a/src/file.cpp b/src/file.cpp index a93c7db2d..ecefaa2da 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -193,7 +193,7 @@ namespace libtorrent } // try to make the file sparse if supported - if ((mode & rw_mask) == write_only || (mode & rw_mask) == read_write) + if (mode & file::sparse) { DWORD temp; ::DeviceIoControl(m_file_handle, FSCTL_SET_SPARSE, 0, 0 diff --git a/src/storage.cpp b/src/storage.cpp index ce38f10e1..49e28f05a 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -416,6 +416,7 @@ namespace libtorrent : m_files(fs) , m_pool(fp) , m_page_size(4096) + , m_allocate_files(false) { TORRENT_ASSERT(m_files.begin() != m_files.end()); m_save_path = fs::complete(path); @@ -483,6 +484,7 @@ namespace libtorrent file_pool& m_pool; int m_page_size; + bool m_allocate_files; }; sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size) @@ -516,6 +518,7 @@ namespace libtorrent bool storage::initialize(bool allocate_files) { + m_allocate_files = allocate_files; error_code ec; // first, create all missing directories fs::path last_path; @@ -570,6 +573,7 @@ namespace libtorrent || (settings().disk_io_read_mode == session_settings::disable_os_cache_for_aligned_files && ((file_iter->offset + file_iter->file_base) & (m_page_size-1)) == 0))) mode |= file::no_buffer; + if (!m_allocate_files) mode |= file::sparse; boost::shared_ptr f = m_pool.open_file(this , m_save_path / file_iter->path, mode, ec); if (ec) set_error(m_save_path / file_iter->path, ec); @@ -1164,9 +1168,8 @@ ret: if (op.cache_setting == session_settings::disable_os_cache || (op.cache_setting == session_settings::disable_os_cache_for_aligned_files && ((file_iter->offset + file_iter->file_base) & (m_page_size-1)) == 0)) - { mode |= file::no_buffer; - } + if (!m_allocate_files) mode |= file::sparse; file_handle = m_pool.open_file(this, path, mode, ec); if (!file_handle || ec)