From 51dc3afcee6e036154b355b9869fd518d483ffff Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 30 Jun 2024 15:21:16 +0200 Subject: [PATCH] fix FreeBSD build, lacking fsync_range() --- include/libtorrent/config.hpp | 8 ++++++++ src/pread_storage.cpp | 10 +++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 20e7274a885..dfdd7ab0acc 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -91,6 +91,10 @@ see LICENSE file. || defined __FreeBSD_kernel__ #define TORRENT_BSD +#ifdef __NetBSD__ +#define TORRENT_HAS_FSYNC_RANGE 1 +#endif + #if defined __APPLE__ #include @@ -560,6 +564,10 @@ see LICENSE file. #define TORRENT_HAS_COPYFILE 0 #endif +#ifndef TORRENT_HAS_FSYNC_RANGE +#define TORRENT_HAS_FSYNC_RANGE 0 +#endif + // debug builds have asserts enabled by default, release // builds have asserts if they are explicitly enabled by // the release_asserts macro. diff --git a/src/pread_storage.cpp b/src/pread_storage.cpp index 563c83b026e..fcf6c533026 100644 --- a/src/pread_storage.cpp +++ b/src/pread_storage.cpp @@ -41,7 +41,7 @@ see LICENSE file. #include // for sync_file_range #elif defined TORRENT_WINDOWS #include "libtorrent/aux_/windows.hpp" // for FlushFileBuffers -#elif defined TORRENT_BSD && ! defined __APPLE__ +#elif TORRENT_HAS_FSYNC_RANGE #include // for fsync_range #else #include // for fsync @@ -72,8 +72,8 @@ namespace { ::FlushFileBuffers(handle); TORRENT_UNUSED(offset); TORRENT_UNUSED(len); -#elif defined TORRENT_BSD && ! defined __APPLE__ - ::fsync_range(handle, FFILESYNC, offset, len); +#elif TORRENT_HAS_FSYNC_RANGE + ::fsync_range(handle, FDATASYNC, offset, len); #else ::fsync(handle); TORRENT_UNUSED(offset); @@ -634,8 +634,6 @@ namespace { ph.update(scratch_buffer); if (flags & disk_interface::volatile_read) advise_dont_need(handle->fd(), file_offset, buf.size()); - if (flags & disk_interface::flush_piece) - sync_file(handle->fd(), file_offset, buf.size()); } return ret; @@ -688,8 +686,6 @@ namespace { ph.update(b); if (flags & disk_interface::volatile_read) advise_dont_need(handle->fd(), file_offset, len); - if (flags & disk_interface::flush_piece) - sync_file(handle->fd(), file_offset, len); return static_cast(len); }