mirror of
https://github.com/samba-team/samba.git
synced 2025-12-14 20:23:54 +03:00
Fixed allocation bug in database prog. Some format fixes.
Jeremy.
This commit is contained in:
@@ -189,4 +189,7 @@
|
|||||||
/* the maximum age in seconds of a password. Should be a lp_ parameter */
|
/* the maximum age in seconds of a password. Should be a lp_ parameter */
|
||||||
#define MAX_PASSWORD_AGE (21*24*60*60)
|
#define MAX_PASSWORD_AGE (21*24*60*60)
|
||||||
|
|
||||||
|
/* Allocation roundup. */
|
||||||
|
#define SMB_ROUNDUP_ALLOCATION_SIZE 0x100000
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -159,6 +159,7 @@
|
|||||||
#define UNIXERROR(defclass,deferror) unix_error_packet(outbuf,defclass,deferror,__LINE__,__FILE__)
|
#define UNIXERROR(defclass,deferror) unix_error_packet(outbuf,defclass,deferror,__LINE__,__FILE__)
|
||||||
|
|
||||||
#define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
|
#define SMB_ROUNDUP(x,g) (((x)+((g)-1))&~((g)-1))
|
||||||
|
#define SMB_ROUNDUP_ALLOCATION(s) (SMB_ROUNDUP((SMB_OFF_T)((s)+1), ((SMB_OFF_T)SMB_ROUNDUP_ALLOCATION_SIZE)))
|
||||||
|
|
||||||
/* Extra macros added by Ying Chen at IBM - speed increase by inlining. */
|
/* Extra macros added by Ying Chen at IBM - speed increase by inlining. */
|
||||||
#define smb_buf(buf) (buf + smb_size + CVAL(buf,smb_wct)*2)
|
#define smb_buf(buf) (buf + smb_size + CVAL(buf,smb_wct)*2)
|
||||||
|
|||||||
2035
source/smbd/trans2.c
2035
source/smbd/trans2.c
File diff suppressed because it is too large
Load Diff
@@ -280,19 +280,20 @@ ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
|
|||||||
|
|
||||||
ssize_t vfs_write_data(files_struct *fsp,const char *buffer,size_t N)
|
ssize_t vfs_write_data(files_struct *fsp,const char *buffer,size_t N)
|
||||||
{
|
{
|
||||||
size_t total=0;
|
size_t total=0;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
while (total < N)
|
while (total < N) {
|
||||||
{
|
ret = fsp->conn->vfs_ops.write(fsp,fsp->fd,buffer + total,N - total);
|
||||||
ret = fsp->conn->vfs_ops.write(fsp,fsp->fd,buffer + total,N - total);
|
|
||||||
|
|
||||||
if (ret == -1) return -1;
|
if (ret == -1)
|
||||||
if (ret == 0) return total;
|
return -1;
|
||||||
|
if (ret == 0)
|
||||||
|
return total;
|
||||||
|
|
||||||
total += ret;
|
total += ret;
|
||||||
}
|
}
|
||||||
return (ssize_t)total;
|
return (ssize_t)total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -305,10 +306,15 @@ int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
SMB_STRUCT_STAT st;
|
SMB_STRUCT_STAT st;
|
||||||
struct vfs_ops *vfs_ops = &fsp->conn->vfs_ops;
|
connection_struct *conn = fsp->conn;
|
||||||
|
struct vfs_ops *vfs_ops = &conn->vfs_ops;
|
||||||
|
SMB_OFF_T space_avail;
|
||||||
|
SMB_BIG_UINT bsize,dfree,dsize;
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (!lp_strict_allocate(SNUM(fsp->conn)))
|
if (!lp_strict_allocate(SNUM(fsp->conn)))
|
||||||
return vfs_set_filelen(fsp, len);
|
return vfs_set_filelen(fsp, len);
|
||||||
|
#endif
|
||||||
|
|
||||||
release_level_2_oplocks_on_change(fsp);
|
release_level_2_oplocks_on_change(fsp);
|
||||||
|
|
||||||
@@ -337,41 +343,20 @@ int vfs_allocate_file_space(files_struct *fsp, SMB_OFF_T len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow - we need to write out the space.... */
|
/* Grow - we need to test if we have enough space. */
|
||||||
{
|
|
||||||
static unsigned char zero_space[65536];
|
|
||||||
|
|
||||||
SMB_OFF_T start_pos = st.st_size;
|
len -= st.st_size;
|
||||||
SMB_OFF_T len_to_write = len - st.st_size;
|
len /= 1024; /* Len is now number of 1k blocks needed. */
|
||||||
SMB_OFF_T retlen;
|
space_avail = (SMB_OFF_T)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\n",
|
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 ));
|
fsp->fsp_name, (double)st.st_size, (unsigned long)len, (unsigned long)space_avail ));
|
||||||
|
|
||||||
if ((retlen = vfs_ops->lseek(fsp, fsp->fd, start_pos, SEEK_SET)) != start_pos)
|
if (len > space_avail) {
|
||||||
return -1;
|
errno = ENOSPC;
|
||||||
|
return -1;
|
||||||
while ( len_to_write > 0) {
|
|
||||||
SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),len_to_write);
|
|
||||||
|
|
||||||
retlen = vfs_ops->write(fsp,fsp->fd,(const char *)zero_space,current_len_to_write);
|
|
||||||
if (retlen <= 0) {
|
|
||||||
/* Write fail - return to original size. */
|
|
||||||
int save_errno = errno;
|
|
||||||
fsp->conn->vfs_ops.ftruncate(fsp, fsp->fd, st.st_size);
|
|
||||||
errno = save_errno;
|
|
||||||
DEBUG(10,("vfs_allocate_file_space: file %s, grow. write fail %s\n",
|
|
||||||
fsp->fsp_name, strerror(errno) ));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG(10,("vfs_allocate_file_space: file %s, grow. wrote %.0f\n",
|
|
||||||
fsp->fsp_name, (double)retlen ));
|
|
||||||
|
|
||||||
len_to_write -= retlen;
|
|
||||||
}
|
|
||||||
set_filelen_write_cache(fsp, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user