From ce4628c199f8e8ac84aa7f2afe2de1d9d23e6fab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 4 Dec 2002 03:12:09 +0000 Subject: Fix for 64 bit issues with oplocks and allocation size. Jeremy. (This used to be commit 379e719e983fb71f94cd2b691f8b194c109496c3) --- source3/smbd/vfs.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'source3/smbd/vfs.c') diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index f6dad7b6e7..7e60d3dacb 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -423,13 +423,13 @@ ssize_t vfs_write_data(files_struct *fsp,const char *buffer,size_t N) Returns 0 on success, -1 on failure. ****************************************************************************/ -int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len) +int vfs_allocate_file_space(files_struct *fsp, SMB_BIG_UINT len) { int ret; SMB_STRUCT_STAT st; connection_struct *conn = fsp->conn; struct vfs_ops *vfs_ops = &conn->vfs_ops; - SMB_OFF_T space_avail; + SMB_BIG_UINT space_avail; SMB_BIG_UINT bsize,dfree,dsize; release_level_2_oplocks_on_change(fsp); @@ -440,21 +440,26 @@ int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len) DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n", fsp->fsp_name, (double)len )); + if (((SMB_OFF_T)len) < 0) { + DEBUG(0,("vfs_allocate_file_space: %s negative len requested.\n", fsp->fsp_name )); + return -1; + } + ret = vfs_fstat(fsp,fsp->fd,&st); if (ret == -1) return ret; - if (len == st.st_size) + if (len == (SMB_BIG_UINT)st.st_size) return 0; - if (len < st.st_size) { + if (len < (SMB_BIG_UINT)st.st_size) { /* Shrink - use ftruncate. */ DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current size %.0f\n", fsp->fsp_name, (double)st.st_size )); flush_write_cache(fsp, SIZECHANGE_FLUSH); - if ((ret = vfs_ops->ftruncate(fsp, fsp->fd, len)) != -1) { + if ((ret = vfs_ops->ftruncate(fsp, fsp->fd, (SMB_OFF_T)len)) != -1) { set_filelen_write_cache(fsp, len); } return ret; @@ -467,10 +472,10 @@ int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len) len -= st.st_size; len /= 1024; /* Len is now number of 1k blocks needed. */ - space_avail = (SMB_OFF_T)conn->vfs_ops.disk_free(conn,fsp->fsp_name,False,&bsize,&dfree,&dsize); + space_avail = conn->vfs_ops.disk_free(conn,fsp->fsp_name,False,&bsize,&dfree,&dsize); - DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, needed blocks = %lu, space avail = %lu\n", - fsp->fsp_name, (double)st.st_size, (unsigned long)len, (unsigned long)space_avail )); + DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, needed blocks = %.0f, space avail = %.0f\n", + fsp->fsp_name, (double)st.st_size, (double)len, (double)space_avail )); if (len > space_avail) { errno = ENOSPC; -- cgit