Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6585:a9dfe05dfadd HEAD
If posix_fallocate() returns EINVAL, fallback to writing.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 21 Oct 2007 14:32:34 +0300 |
parents | 4fb613eb8ce9 |
children | d6b2343238f9 |
files | src/lib/file-set-size.c |
diffstat | 1 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/file-set-size.c Sun Oct 21 04:49:45 2007 +0300 +++ b/src/lib/file-set-size.c Sun Oct 21 14:32:34 2007 +0300 @@ -10,11 +10,12 @@ int file_set_size(int fd, off_t size) { -#ifndef HAVE_POSIX_FALLOCATE +#ifdef HAVE_POSIX_FALLOCATE + static bool posix_fallocate_supported = TRUE; +#endif char block[4096]; off_t offset; ssize_t ret; -#endif struct stat st; i_assert(size >= 0); @@ -35,12 +36,20 @@ return 0; #ifdef HAVE_POSIX_FALLOCATE - if (posix_fallocate(fd, st.st_size, size - st.st_size) < 0) { - if (!ENOSPACE(errno)) - i_error("posix_fallocate() failed: %m"); - return -1; + if (posix_fallocate_supported) { + if (posix_fallocate(fd, st.st_size, size - st.st_size) == 0) + return 0; + + if (errno != EINVAL) { + if (!ENOSPACE(errno)) + i_error("posix_fallocate() failed: %m"); + return -1; + } + /* Solaris seems to fail with EINVAL if it's not supported + by the kernel. Fallback to writing. */ + posix_fallocate_supported = FALSE; } -#else +#endif /* start growing the file */ offset = st.st_size; memset(block, 0, I_MIN((ssize_t)sizeof(block), size - offset)); @@ -56,6 +65,5 @@ } offset += size; } -#endif return 0; }