From bf794d2df4869f62b46e13b7b132509d20a685b1 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sat, 12 Jul 2014 14:54:41 -0400 Subject: [PATCH] Use posix_fallocate64() if fallocate64() is unavailable --- configure | 2 +- configure.in | 2 ++ lib/config.h.in | 6 ++++++ misc/e4defrag.c | 10 +++++++--- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/configure b/configure index d8f6deb..ca0001c 100755 --- a/configure +++ b/configure @@ -13071,7 +13071,7 @@ if test "$ac_res" != no; then : fi fi -for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime valloc +for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_fallocate posix_fallocate64 posix_memalign prctl secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime valloc do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index 79c8dc2..0d9e992 100644 --- a/configure.in +++ b/configure.in @@ -1111,6 +1111,8 @@ AC_CHECK_FUNCS(m4_flatten([ pathconf posix_fadvise posix_fadvise64 + posix_fallocate + posix_fallocate64 posix_memalign prctl secure_getenv diff --git a/lib/config.h.in b/lib/config.h.in index 3ed71fa..30791e3 100644 --- a/lib/config.h.in +++ b/lib/config.h.in @@ -325,6 +325,12 @@ /* Define to 1 if you have the `posix_fadvise64' function. */ #undef HAVE_POSIX_FADVISE64 +/* Define to 1 if you have the `posix_fallocate' function. */ +#undef HAVE_POSIX_FALLOCATE + +/* Define to 1 if you have the `posix_fallocate64' function. */ +#undef HAVE_POSIX_FALLOCATE64 + /* Define to 1 if you have the `posix_memalign' function. */ #undef HAVE_POSIX_MEMALIGN diff --git a/misc/e4defrag.c b/misc/e4defrag.c index a204793..2ad90df 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -197,9 +197,9 @@ static struct frag_statistic_ino frag_rank[SHOW_FRAG_FILES]; #error sync_file_range not available! #endif /* ! HAVE_SYNC_FILE_RANGE */ -#ifndef HAVE_FALLOCATE64 -#error fallocate64 not available! -#endif /* ! HAVE_FALLOCATE64 */ +#ifdef !defined(HAVE_FALLOCATE64) && !defined(HAVE_POSIX_FALLOCATE64) +#error neither fallocate64 nor posix_fallocate64 available! +#endif /* ! HAVE_FALLOCATE64 && ! HAVE_POSIX_FALLOCATE64 */ /* * get_mount_point() - Get device's mount point. @@ -1552,7 +1552,11 @@ static int file_defrag(const char *file, const struct stat64 *buf, /* Allocate space for donor inode */ orig_group_tmp = orig_group_head; do { +#ifdef HAVE_FALLOCATE64 ret = fallocate64(donor_fd, 0, +#else /* HAVE_POSIX_FALLOCATE64 */ + ret = posix_fallocate64(donor_fd, +#endif (loff_t)orig_group_tmp->start->data.logical * block_size, (loff_t)orig_group_tmp->len * block_size); if (ret < 0) { -- 1.8.5.5