diff --git a/configure.ac b/configure.ac index 9ba748638..a2f3bf269 100644 --- a/configure.ac +++ b/configure.ac @@ -146,6 +146,8 @@ if test "x$want_kqueue" = "xyes" ; then fi fi +AC_CHECK_HEADERS([xfs/xfs.h]) + dnl ---------------------------------------------------------------------------- dnl diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 13a0daebe..021642687 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -47,6 +47,10 @@ #include #endif +#ifdef HAVE_XFS_XFS_H + #include +#endif + #include #include #ifdef HAVE_GETRLIMIT @@ -158,30 +162,39 @@ preallocateFileFull( const char * filename, uint64_t length ) int fd = open( filename, flags, 0666 ); if( fd >= 0 ) { - +# ifdef HAVE_XFS_XFS_H + if( !success && platform_test_xfs_fd( fd ) ) + { + xfs_flock64_t fl; + fl.l_whence = 0; + fl.l_start = 0; + fl.l_len = length; + success = !xfsctl( NULL, fd, XFS_IOC_RESVSP64, &fl ); + } +# endif +# ifdef SYS_DARWIN + if( !success ) + { + fstore_t fst; + fst.fst_flags = F_ALLOCATECONTIG; + fst.fst_posmode = F_PEOFPOSMODE; + fst.fst_offset = 0; + fst.fst_length = length; + fst.fst_bytesalloc = 0; + success = !fcntl( fd, F_PREALLOCATE, &fst ); + } +# endif # ifdef HAVE_FALLOCATE - - success = !fallocate( fd, FALLOC_FL_KEEP_SIZE, 0, length ); - -# elif defined(HAVE_POSIX_FALLOCATE) - - success = !posix_fallocate( fd, 0, length ); - -# elif defined(SYS_DARWIN) - - fstore_t fst; - fst.fst_flags = F_ALLOCATECONTIG; - fst.fst_posmode = F_PEOFPOSMODE; - fst.fst_offset = 0; - fst.fst_length = length; - fst.fst_bytesalloc = 0; - success = !fcntl( fd, F_PREALLOCATE, &fst ); - -# else - - #warning no known method to preallocate files on this platform - success = 0; - + if( !success ) + { + success = !fallocate( fd, FALLOC_FL_KEEP_SIZE, 0, length ); + } +# endif +# ifdef HAVE_POSIX_FALLOCATE + if( !success ) + { + success = !posix_fallocate( fd, 0, length ); + } # endif close( fd );