From b8d7de319980f9efade92dd0721ed02efcb7e48d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Dec 2010 17:26:00 -0800 Subject: Merge the two conflicting allocation codes into one function, vfs_slow_fallocate() and use that from both the truncate and fill_sparse functions. Jeremy. --- source3/modules/vfs_default.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'source3/modules') diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 0ec5b66df3..79f66db6d9 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -822,16 +822,11 @@ static int vfswrap_ntimes(vfs_handle_struct *handle, static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len) { SMB_STRUCT_STAT st; - SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR); - unsigned char zero_space[4096]; SMB_OFF_T space_to_write; uint64_t space_avail; uint64_t bsize,dfree,dsize; int ret; - if (currpos == -1) - return -1; - if (SMB_VFS_FSTAT(fsp, &st) == -1) return -1; @@ -877,25 +872,12 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs } /* Write out the real space on disk. */ - if (SMB_VFS_LSEEK(fsp, st.st_ex_size, SEEK_SET) != st.st_ex_size) - return -1; - - memset(zero_space, '\0', sizeof(zero_space)); - while ( space_to_write > 0) { - SMB_OFF_T retlen; - SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write); - - retlen = SMB_VFS_WRITE(fsp,(char *)zero_space,current_len_to_write); - if (retlen <= 0) - return -1; - - space_to_write -= retlen; + ret = vfs_slow_fallocate(fsp, st.st_ex_size, space_to_write); + if (ret != 0) { + errno = ret; + ret = -1; } - /* Seek to where we were */ - if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos) - return -1; - return 0; } -- cgit