]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Fix bug #5990 - strict allocate should be checked before ftruncate
authorJeremy Allison <jra@samba.org>
Thu, 25 Dec 2008 20:12:22 +0000 (12:12 -0800)
committerKarolin Seeger <kseeger@samba.org>
Fri, 2 Jan 2009 11:44:24 +0000 (12:44 +0100)
reported by and based on a patch by Yasuma Takeda <yasuma@osstech.co.jp>.
Jeremy.
(cherry picked from commit 60707022622068dd5df5c7b5aa82e0d34ed544f5)

source/modules/vfs_default.c

index 09ad3cb8e4783d310ecb1ecb93cb9c0fe4840ad7..d306b0f8481ce32d59bff215b02f06a1fbadb402 100644 (file)
@@ -714,6 +714,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))){
+               SMB_BIG_UINT space_avail;
+               SMB_BIG_UINT bsize,dfree,dsize;
+
+               space_avail = get_dfree_info(fsp->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;