From: Jeremy Allison Date: Thu, 25 Dec 2008 20:13:12 +0000 (-0800) Subject: Fix bug #5990 - strict allocate should be checked before ftruncate X-Git-Tag: samba-4.0.0alpha6~366 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5184baa9591640c7fac4574bad6c15f5c7302a87;p=thirdparty%2Fsamba.git Fix bug #5990 - strict allocate should be checked before ftruncate reported by and based on a patch by Yasuma Takeda . Jeremy. --- diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 8fa8f6ae067..d7f39229743 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -740,6 +740,20 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs if (st.st_size > len) return sys_ftruncate(fsp->fh->fd, len); + /* available disk space is enough or not? */ + if (lp_strict_allocate(SNUM(fsp->conn))){ + uint64_t space_avail; + uint64_t bsize,dfree,dsize; + + space_avail = get_dfree_info(conn,fsp->fsp_name,false,&bsize,&dfree,&dsize); + /* space_avail is 1k blocks */ + if (space_avail == (SMB_BIG_UINT)-1 || + ((SMB_BIG_UINT)space_to_write/1024 > space_avail) ) { + errno = ENOSPC; + return -1; + } + } + /* Write out the real space on disk. */ if (SMB_VFS_LSEEK(fsp, st.st_size, SEEK_SET) != st.st_size) return -1;