diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index b92668a85..cce84b3a2 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -177,6 +177,7 @@ namespace libtorrent no_buffer = 4, mode_mask = rw_mask | no_buffer, sparse = 8, + no_atime = 16, attribute_hidden = 0x1000, attribute_executable = 0x2000, diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index 0ff2ea6fc..a23cebe07 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -190,6 +190,7 @@ namespace libtorrent , guided_read_cache(true) , default_cache_min_age(1) , num_optimistic_unchoke_slots(0) + , no_atime_storage(true) {} // this is the user agent that will be sent to the tracker @@ -709,6 +710,10 @@ namespace libtorrent // the global number of optimistic unchokes // 0 means automatic int num_optimistic_unchoke_slots; + + // if set to true, files won't have their atime updated + // on disk reads. This works on linux + bool no_atime_storage; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/file.cpp b/src/file.cpp index 678465661..f62b312b2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -769,8 +769,17 @@ namespace libtorrent static const int no_buffer_flag[] = {0, 0}; #endif +#ifdef O_NOATIME + static const int no_atime_flag[] = {0, O_NOATIME}; +#endif + m_fd = ::open(convert_to_native(path).c_str() - , mode_array[mode & rw_mask] | no_buffer_flag[(mode & no_buffer) >> 2], permissions); + , mode_array[mode & rw_mask] + | no_buffer_flag[(mode & no_buffer) >> 2] +#ifdef O_NOATIME + | no_atime_flag[(mode & no_atime) >> 4] +#endif + , permissions); #ifdef TORRENT_LINUX // workaround for linux bug diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 645074310..724388ca1 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1021,6 +1021,7 @@ namespace aux { || m_settings.allow_reordered_disk_operations != s.allow_reordered_disk_operations || m_settings.file_pool_size != s.file_pool_size || m_settings.volatile_read_cache != s.volatile_read_cache + || m_settings.no_atime_storage!= s.no_atime_storage || m_settings.low_prio_disk != s.low_prio_disk) update_disk_io_thread = true; diff --git a/src/storage.cpp b/src/storage.cpp index c90eb4f60..29398f473 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1304,6 +1304,7 @@ ret: && ((fe.offset + fe.file_base) & (m_page_size-1)) == 0)) mode |= file::no_buffer; if (!m_allocate_files) mode |= file::sparse; + if (m_settings && settings().no_atime_storage) mode |= file::no_atime; return m_pool.open_file(const_cast(this), combine_path(m_save_path, fe.path), mode, ec); }