From 5467cbf792cf164e1a7b91d29a4cbdf102e864ff Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Bj=C3=B6rn=20Jacke?= Date: Tue, 8 Dec 2009 21:13:19 +0100 Subject: [PATCH] s3: make sys_posix_fallocate more generic this is in preparation for other preallocation methods to be introduced. cherry-picked from 39be2d18a24176b9300834a0552180cdfb11ca5f --- source3/lib/system.c | 8 ++++---- source3/modules/vfs_default.c | 25 +++++++++++-------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/source3/lib/system.c b/source3/lib/system.c index 226a8d1..31ee77a 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -344,16 +344,16 @@ int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf) /******************************************************************* An posix_fallocate() wrapper that will deal with 64 bit filesizes. ********************************************************************/ -#if (defined(HAVE_POSIX_FALLOCATE64) || defined(HAVE_POSIX_FALLOCATE)) && !defined(HAVE_BROKEN_POSIX_FALLOCATE) int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len) { -#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) +#if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) && !defined(HAVE_BROKEN_POSIX_FALLOCATE) return posix_fallocate64(fd, offset, len); -#else +#elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE) return posix_fallocate(fd, offset, len); +#else + return ENOSYS; #endif } -#endif /******************************************************************* An ftruncate() wrapper that will deal with 64 bit filesizes. diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 39f027d..4b6c6a8 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -818,6 +818,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR); unsigned char zero_space[4096]; SMB_OFF_T space_to_write; + int ret; if (currpos == -1) return -1; @@ -844,21 +845,17 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs emulation is being done by the libc (like on AIX with JFS1). In that case we do our own emulation. posix_fallocate implementations can return ENOTSUP or EINVAL in cases like that. */ -#if defined(HAVE_POSIX_FALLOCATE) - { - int ret = sys_posix_fallocate(fsp->fh->fd, st.st_size, space_to_write); - if (ret == ENOSPC) { - errno = ENOSPC; - return -1; - } - if (ret == 0) { - return 0; - } - DEBUG(10,("strict_allocate_ftruncate: sys_posix_fallocate " - "failed with error %d. " - "Falling back to slow manual allocation\n", ret)); + ret = sys_posix_fallocate(fsp->fh->fd, st.st_size, space_to_write); + if (ret == ENOSPC) { + errno = ENOSPC; + return -1; } -#endif + if (ret == 0) { + return 0; + } + DEBUG(10,("strict_allocate_ftruncate: sys_posix_fallocate failed with " + "error %d. Falling back to slow manual allocation\n", ret)); + /* available disk space is enough or not? */ if (lp_strict_allocate(SNUM(fsp->conn))){ uint64_t space_avail; -- 1.6.0.2