[glib/glib-2-36] g_file_set_contents(): use posix_fallocate()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-36] g_file_set_contents(): use posix_fallocate()
- Date: Sun, 9 Jun 2013 22:40:44 +0000 (UTC)
commit 2d827a25af4bea0513d5fc0796b139337278734b
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Jun 3 15:43:01 2013 -0400
g_file_set_contents(): use posix_fallocate()
Extents-based filesystems like knowing in advance how much data will be
written to a file in order to prevent fragmentation. If we have it, use
posix_fallocate() before writing data in g_file_set_contents().
https://bugzilla.gnome.org/show_bug.cgi?id=701560
configure.ac | 2 +-
glib/gfileutils.c | 7 +++++++
2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6fd16bd..51be1ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -992,7 +992,7 @@ AC_MSG_RESULT(unsigned $glib_size_type)
# Check for some functions
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd
vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem)
AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link utimes getgrgid getpwuid getresuid)
-AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getfsstat getvfsstat)
+AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getfsstat getvfsstat posix_fallocate)
# Check for high-resolution sleep functions
AC_CHECK_FUNCS(splice)
AC_CHECK_FUNCS(prlimit)
diff --git a/glib/gfileutils.c b/glib/gfileutils.c
index 3c1b135..2350643 100644
--- a/glib/gfileutils.c
+++ b/glib/gfileutils.c
@@ -1059,6 +1059,13 @@ write_to_temp_file (const gchar *contents,
if (length > 0)
{
gsize n_written;
+
+#ifdef HAVE_POSIX_FALLOCATE
+ /* We do this on a 'best effort' basis... It may not be supported
+ * on the underlying filesystem.
+ */
+ (void) posix_fallocate (fd, 0, length);
+#endif
errno = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]