mirror of
https://github.com/transmission/transmission
synced 2025-03-04 02:28:03 +00:00
(trunk libT) #1966: add explicit support for preallocating files on XFS filesystems
This commit is contained in:
parent
822a192758
commit
1e327f593d
2 changed files with 38 additions and 23 deletions
|
@ -146,6 +146,8 @@ if test "x$want_kqueue" = "xyes" ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS([xfs/xfs.h])
|
||||
|
||||
|
||||
dnl ----------------------------------------------------------------------------
|
||||
dnl
|
||||
|
|
|
@ -47,6 +47,10 @@
|
|||
#include <linux/falloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XFS_XFS_H
|
||||
#include <xfs/xfs.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#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 );
|
||||
|
|
Loading…
Add table
Reference in a new issue