don't make files sparse when allocation mode is set on the storage (windows only)

This commit is contained in:
Arvid Norberg 2009-02-14 03:56:07 +00:00
parent 3187bd9905
commit dc4d50b117
3 changed files with 7 additions and 3 deletions

View File

@ -95,6 +95,7 @@ namespace libtorrent
rw_mask = read_only | write_only | read_write, rw_mask = read_only | write_only | read_write,
no_buffer = 4, no_buffer = 4,
mode_mask = rw_mask | no_buffer, mode_mask = rw_mask | no_buffer,
sparse = 8,
attribute_hidden = 0x1000, attribute_hidden = 0x1000,
attribute_executable = 0x2000, attribute_executable = 0x2000,

View File

@ -193,7 +193,7 @@ namespace libtorrent
} }
// try to make the file sparse if supported // 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; DWORD temp;
::DeviceIoControl(m_file_handle, FSCTL_SET_SPARSE, 0, 0 ::DeviceIoControl(m_file_handle, FSCTL_SET_SPARSE, 0, 0

View File

@ -416,6 +416,7 @@ namespace libtorrent
: m_files(fs) : m_files(fs)
, m_pool(fp) , m_pool(fp)
, m_page_size(4096) , m_page_size(4096)
, m_allocate_files(false)
{ {
TORRENT_ASSERT(m_files.begin() != m_files.end()); TORRENT_ASSERT(m_files.begin() != m_files.end());
m_save_path = fs::complete(path); m_save_path = fs::complete(path);
@ -483,6 +484,7 @@ namespace libtorrent
file_pool& m_pool; file_pool& m_pool;
int m_page_size; int m_page_size;
bool m_allocate_files;
}; };
sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size) 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) bool storage::initialize(bool allocate_files)
{ {
m_allocate_files = allocate_files;
error_code ec; error_code ec;
// first, create all missing directories // first, create all missing directories
fs::path last_path; fs::path last_path;
@ -570,6 +573,7 @@ namespace libtorrent
|| (settings().disk_io_read_mode == session_settings::disable_os_cache_for_aligned_files || (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))) && ((file_iter->offset + file_iter->file_base) & (m_page_size-1)) == 0)))
mode |= file::no_buffer; mode |= file::no_buffer;
if (!m_allocate_files) mode |= file::sparse;
boost::shared_ptr<file> f = m_pool.open_file(this boost::shared_ptr<file> f = m_pool.open_file(this
, m_save_path / file_iter->path, mode, ec); , m_save_path / file_iter->path, mode, ec);
if (ec) set_error(m_save_path / file_iter->path, 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 if (op.cache_setting == session_settings::disable_os_cache
|| (op.cache_setting == session_settings::disable_os_cache_for_aligned_files || (op.cache_setting == session_settings::disable_os_cache_for_aligned_files
&& ((file_iter->offset + file_iter->file_base) & (m_page_size-1)) == 0)) && ((file_iter->offset + file_iter->file_base) & (m_page_size-1)) == 0))
{
mode |= file::no_buffer; mode |= file::no_buffer;
} if (!m_allocate_files) mode |= file::sparse;
file_handle = m_pool.open_file(this, path, mode, ec); file_handle = m_pool.open_file(this, path, mode, ec);
if (!file_handle || ec) if (!file_handle || ec)