forked from premiere/premiere-libtorrent
don't turn off read-ahead by default on files. Might impact hash checking
This commit is contained in:
parent
990de1c243
commit
d0af936933
|
@ -185,6 +185,7 @@ namespace libtorrent
|
||||||
mode_mask = rw_mask | no_buffer,
|
mode_mask = rw_mask | no_buffer,
|
||||||
sparse = 8,
|
sparse = 8,
|
||||||
no_atime = 16,
|
no_atime = 16,
|
||||||
|
random_access = 32,
|
||||||
|
|
||||||
attribute_hidden = 0x1000,
|
attribute_hidden = 0x1000,
|
||||||
attribute_executable = 0x2000,
|
attribute_executable = 0x2000,
|
||||||
|
|
20
src/file.cpp
20
src/file.cpp
|
@ -763,19 +763,19 @@ namespace libtorrent
|
||||||
const static open_mode_t mode_array[] =
|
const static open_mode_t mode_array[] =
|
||||||
{
|
{
|
||||||
// read_only
|
// read_only
|
||||||
{GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS},
|
{GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0},
|
||||||
// write_only
|
// write_only
|
||||||
{GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS},
|
{GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS, 0},
|
||||||
// read_write
|
// read_write
|
||||||
{GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS},
|
{GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, 0},
|
||||||
// invalid option
|
// invalid option
|
||||||
{0,0,0,0},
|
{0,0,0,0},
|
||||||
// read_only no_buffer
|
// read_only no_buffer
|
||||||
{GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
{GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
||||||
// write_only no_buffer
|
// write_only no_buffer
|
||||||
{GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
{GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
||||||
// read_write no_buffer
|
// read_write no_buffer
|
||||||
{GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
{GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_ALWAYS, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING },
|
||||||
// invalid option
|
// invalid option
|
||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
};
|
};
|
||||||
|
@ -800,8 +800,11 @@ namespace libtorrent
|
||||||
open_mode_t const& m = mode_array[mode & mode_mask];
|
open_mode_t const& m = mode_array[mode & mode_mask];
|
||||||
DWORD a = attrib_array[(mode & attribute_mask) >> 12];
|
DWORD a = attrib_array[(mode & attribute_mask) >> 12];
|
||||||
|
|
||||||
|
DWORD extra_flags = ((mode & random_access) ? FILE_FLAG_RANDOM_ACCESS : 0)
|
||||||
|
| (a ? a : FILE_ATTRIBUTE_NORMAL);
|
||||||
|
|
||||||
m_file_handle = CreateFile_(m_path.c_str(), m.rw_mode, m.share_mode, 0
|
m_file_handle = CreateFile_(m_path.c_str(), m.rw_mode, m.share_mode, 0
|
||||||
, m.create_mode, m.flags | (a ? a : FILE_ATTRIBUTE_NORMAL), 0);
|
, m.create_mode, m.flags | extra_flags, 0);
|
||||||
|
|
||||||
if (m_file_handle == INVALID_HANDLE_VALUE)
|
if (m_file_handle == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
|
@ -885,8 +888,11 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef POSIX_FADV_RANDOM
|
#ifdef POSIX_FADV_RANDOM
|
||||||
|
if (mode & random_access)
|
||||||
|
{
|
||||||
// disable read-ahead
|
// disable read-ahead
|
||||||
posix_fadvise(m_fd, 0, 0, POSIX_FADV_RANDOM);
|
posix_fadvise(m_fd, 0, 0, POSIX_FADV_RANDOM);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -71,7 +71,8 @@ namespace libtorrent
|
||||||
// write mode, re-open it
|
// write mode, re-open it
|
||||||
if ((((e.mode & file::rw_mask) != file::read_write)
|
if ((((e.mode & file::rw_mask) != file::read_write)
|
||||||
&& ((m & file::rw_mask) == file::read_write))
|
&& ((m & file::rw_mask) == file::read_write))
|
||||||
|| (e.mode & file::no_buffer) != (m & file::no_buffer))
|
|| (e.mode & file::no_buffer) != (m & file::no_buffer)
|
||||||
|
|| (e.mode & file::random_access) != (m & file::random_access))
|
||||||
{
|
{
|
||||||
// close the file before we open it with
|
// close the file before we open it with
|
||||||
// the new read/write privilages
|
// the new read/write privilages
|
||||||
|
|
Loading…
Reference in New Issue