diff options
author | Ryan Lortie <desrt@desrt.ca> | 2013-06-03 15:43:01 -0400 |
---|---|---|
committer | Ryan Lortie <desrt@desrt.ca> | 2013-06-03 16:12:04 -0400 |
commit | d3be43fcc5165b7680c9073438ad60a3652c1703 (patch) | |
tree | 63cda821ccae693103b9f8c42ce2b0c91d6367a0 | |
parent | b9350597384502e51e800d9bcfea32d719b7b41b (diff) | |
download | glib-d3be43fcc5165b7680c9073438ad60a3652c1703.tar.gz |
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
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | glib/gfileutils.c | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index eb37a4d02..53b38bc4e 100644 --- a/configure.ac +++ b/configure.ac @@ -1056,7 +1056,7 @@ AC_MSG_RESULT($glib_ssize_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 5ef87a90b..d0c1fc916 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; |