From 6851254fdf85ba3c3cd5c16d5cfb3bd452b5993f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 11 Apr 2010 00:48:48 +0000 Subject: [PATCH] fixed FIEMAP support on linux --- ChangeLog | 1 + examples/fragmentation_test.cpp | 19 +++++++++++++++++-- src/file.cpp | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98eb266ad..8714ba8dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,7 @@ incoming connection * added more detailed instrumentation of the disk I/O thread + * fixed FIEMAP support on linux * fixed strict aliasing warning on gcc * fixed inconsistency when creating torrents with symlinks * properly detect windows version to initialize half-open connection limit diff --git a/examples/fragmentation_test.cpp b/examples/fragmentation_test.cpp index 6152da71e..cbcf33001 100644 --- a/examples/fragmentation_test.cpp +++ b/examples/fragmentation_test.cpp @@ -41,12 +41,27 @@ using namespace libtorrent; int main(int argc, char const* argv[]) { - if (argc != 3) + if (argc != 3 && argc != 2) { - fprintf(stderr, "Usage: fragmentation_test torrent-file file-storage-path\n"); + fprintf(stderr, "Usage: fragmentation_test torrent-file file-storage-path\n" + " fragmentation_test file\n\n"); return 1; } + if (argc == 2) + { + error_code ec; + file f(argv[1], file::read_only, ec); + if (ec) + { + fprintf(stderr, "Error opening file %s: %s\n", argv[1], ec.message().c_str()); + return 1; + } + size_type off = f.phys_offset(0); + printf("physical offset of file %s: %" PRId64 "\n", argv[1], off); + return 0; + } + error_code ec; boost::intrusive_ptr ti(new torrent_info(argv[1], ec)); diff --git a/src/file.cpp b/src/file.cpp index b66b23293..13c7f4f8a 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -73,7 +73,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef HAVE_LINUX_FIEMAP_H -#include +#include // FIEMAP_* +#include // FS_IOC_FIEMAP #endif #include // For __NR_fallocate @@ -1394,7 +1395,7 @@ namespace libtorrent size_type file::phys_offset(size_type offset) { -#ifdef FS_IOC_FIEMAP +#ifdef FIEMAP_EXTENT_UNKNOWN // for documentation of this feature // http://lwn.net/Articles/297696/ struct