summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2002-04-24 19:11:34 +0000
committerJeremy Allison <jra@samba.org>2002-04-24 19:11:34 +0000
commiteb0736b09bc3552a3e2bebfce06df16c5538f12a (patch)
tree62d4f75ab56644f090f5425b038e1a89ae8ae63c
parent5922eaf61adf6cdec7cb9e5d942a19102f969ec6 (diff)
downloadsamba-eb0736b09bc3552a3e2bebfce06df16c5538f12a.tar.gz
samba-eb0736b09bc3552a3e2bebfce06df16c5538f12a.tar.bz2
samba-eb0736b09bc3552a3e2bebfce06df16c5538f12a.zip
smbd/fileio.c: debug changes so read/write/seek calls can be logged for name, pos, size easily.
Might help with access problem. Jeremy. (This used to be commit e08d72b3271ae1b155a59ae82acf9d619c22c81f)
-rw-r--r--source3/smbd/fileio.c775
1 files changed, 393 insertions, 382 deletions
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index addbcb0b3c..fd660f40d0 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -1,7 +1,9 @@
/*
- Unix SMB/CIFS implementation.
+ Unix SMB/Netbios implementation.
+ Version 1.9.
read/write to a files_struct
Copyright (C) Andrew Tridgell 1992-1998
+ Copyright (C) Jeremy Allison 2000-2002. - write cache.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,31 +25,32 @@
static BOOL setup_write_cache(files_struct *, SMB_OFF_T);
/****************************************************************************
-seek a file. Try to avoid the seek if possible
+ Seek a file. Try to avoid the seek if possible.
****************************************************************************/
SMB_OFF_T seek_file(files_struct *fsp,SMB_OFF_T pos)
{
- SMB_OFF_T offset = 0;
- SMB_OFF_T seek_ret;
+ SMB_OFF_T offset = 0;
+ SMB_OFF_T seek_ret;
- if (fsp->print_file && lp_postscript(fsp->conn->service))
- offset = 3;
+ if (fsp->print_file && lp_postscript(fsp->conn->service))
+ offset = 3;
- seek_ret = fsp->conn->vfs_ops.lseek(fsp,fsp->fd,pos+offset,SEEK_SET);
+ seek_ret = fsp->conn->vfs_ops.lseek(fsp,fsp->fd,pos+offset,SEEK_SET);
- if(seek_ret == -1) {
- DEBUG(0,("seek_file: sys_lseek failed. Error was %s\n", strerror(errno) ));
- fsp->pos = -1;
- return -1;
- }
+ if(seek_ret == -1) {
+ DEBUG(0,("seek_file: (%s) sys_lseek failed. Error was %s\n",
+ fsp->fsp_name, strerror(errno) ));
+ fsp->pos = -1;
+ return -1;
+ }
- fsp->pos = seek_ret - offset;
+ fsp->pos = seek_ret - offset;
- DEBUG(10,("seek_file: requested pos = %.0f, new pos = %.0f\n",
- (double)(pos+offset), (double)fsp->pos ));
+ DEBUG(10,("seek_file (%s): requested pos = %.0f, new pos = %.0f\n",
+ fsp->fsp_name, (double)(pos+offset), (double)fsp->pos ));
- return(fsp->pos);
+ return(fsp->pos);
}
/****************************************************************************
@@ -57,23 +60,23 @@ SMB_OFF_T seek_file(files_struct *fsp,SMB_OFF_T pos)
BOOL read_from_write_cache(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
{
- write_cache *wcp = fsp->wcp;
+ write_cache *wcp = fsp->wcp;
- if(!wcp)
- return False;
+ if(!wcp)
+ return False;
- if(n > wcp->data_size || pos < wcp->offset || pos + n > wcp->offset + wcp->data_size)
- return False;
+ if(n > wcp->data_size || pos < wcp->offset || pos + n > wcp->offset + wcp->data_size)
+ return False;
- memcpy(data, wcp->data + (pos - wcp->offset), n);
+ memcpy(data, wcp->data + (pos - wcp->offset), n);
- DO_PROFILE_INC(writecache_read_hits);
+ DO_PROFILE_INC(writecache_read_hits);
- return True;
+ return True;
}
/****************************************************************************
-read from a file
+ Read from a file.
****************************************************************************/
ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n)
@@ -121,6 +124,9 @@ tryagain:
ret += readret;
}
+ DEBUG(10,("read_file (%s): pos = %.0f, size = %lu, returned %lu\n",
+ fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
+
return(ret);
}
@@ -133,10 +139,17 @@ static unsigned int allocated_write_caches;
static ssize_t real_write_file(files_struct *fsp,char *data,SMB_OFF_T pos, size_t n)
{
- if ((pos != -1) && (seek_file(fsp,pos) == -1))
- return -1;
+ ssize_t ret;
+
+ if ((pos != -1) && (seek_file(fsp,pos) == -1))
+ return -1;
+
+ ret = vfs_write_data(fsp,data,n);
+
+ DEBUG(10,("real_write_file (%s): pos = %.0f, size = %lu, returned %ld\n",
+ fsp->fsp_name, (double)pos, (unsigned long)n, (long)ret ));
- return vfs_write_data(fsp,data,n);
+ return ret;
}
/****************************************************************************
@@ -145,367 +158,365 @@ write to a file
ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
{
- write_cache *wcp = fsp->wcp;
- ssize_t total_written = 0;
- int write_path = -1;
-
- if (fsp->print_file) {
- return print_job_write(fsp->print_jobid, data, n);
- }
-
- if (!fsp->can_write) {
- errno = EPERM;
- return(0);
- }
-
- if (!fsp->modified) {
- SMB_STRUCT_STAT st;
- fsp->modified = True;
-
- if (fsp->conn->vfs_ops.fstat(fsp,fsp->fd,&st) == 0) {
- int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
- fsp->size = st.st_size;
- if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode)) {
- file_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st);
- }
-
- /*
- * If this is the first write and we have an exclusive oplock then setup
- * the write cache.
- */
-
- if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
- setup_write_cache(fsp, st.st_size);
- wcp = fsp->wcp;
- }
- }
- }
+ write_cache *wcp = fsp->wcp;
+ ssize_t total_written = 0;
+ int write_path = -1;
+
+ if (fsp->print_file)
+ return print_job_write(fsp->print_jobid, data, n);
+
+ if (!fsp->can_write) {
+ errno = EPERM;
+ return(0);
+ }
+
+ if (!fsp->modified) {
+ SMB_STRUCT_STAT st;
+ fsp->modified = True;
+
+ if (fsp->conn->vfs_ops.fstat(fsp,fsp->fd,&st) == 0) {
+ int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st);
+ fsp->size = st.st_size;
+ if (MAP_ARCHIVE(fsp->conn) && !IS_DOS_ARCHIVE(dosmode))
+ file_chmod(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st);
+
+ /*
+ * If this is the first write and we have an exclusive oplock then setup
+ * the write cache.
+ */
+
+ if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type) && !wcp) {
+ setup_write_cache(fsp, st.st_size);
+ wcp = fsp->wcp;
+ }
+ }
+ }
#ifdef WITH_PROFILE
- DO_PROFILE_INC(writecache_total_writes);
- if (!fsp->oplock_type) {
- DO_PROFILE_INC(writecache_non_oplock_writes);
- }
+ DO_PROFILE_INC(writecache_total_writes);
+ if (!fsp->oplock_type) {
+ DO_PROFILE_INC(writecache_non_oplock_writes);
+ }
#endif
- /*
- * If this file is level II oplocked then we need
- * to grab the shared memory lock and inform all
- * other files with a level II lock that they need
- * to flush their read caches. We keep the lock over
- * the shared memory area whilst doing this.
- */
+ /*
+ * If this file is level II oplocked then we need
+ * to grab the shared memory lock and inform all
+ * other files with a level II lock that they need
+ * to flush their read caches. We keep the lock over
+ * the shared memory area whilst doing this.
+ */
- release_level_2_oplocks_on_change(fsp);
+ release_level_2_oplocks_on_change(fsp);
#ifdef WITH_PROFILE
- if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
- DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
+ if (profile_p && profile_p->writecache_total_writes % 500 == 0) {
+ DEBUG(3,("WRITECACHE: initwrites=%u abutted=%u total=%u \
nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
- profile_p->writecache_init_writes,
- profile_p->writecache_abutted_writes,
- profile_p->writecache_total_writes,
- profile_p->writecache_non_oplock_writes,
- profile_p->writecache_allocated_write_caches,
- profile_p->writecache_num_write_caches,
- profile_p->writecache_direct_writes,
- profile_p->writecache_num_perfect_writes,
- profile_p->writecache_read_hits ));
-
- DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
- profile_p->writecache_flushed_writes[SEEK_FLUSH],
- profile_p->writecache_flushed_writes[READ_FLUSH],
- profile_p->writecache_flushed_writes[WRITE_FLUSH],
- profile_p->writecache_flushed_writes[READRAW_FLUSH],
- profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH],
- profile_p->writecache_flushed_writes[CLOSE_FLUSH],
- profile_p->writecache_flushed_writes[SYNC_FLUSH] ));
- }
+ profile_p->writecache_init_writes,
+ profile_p->writecache_abutted_writes,
+ profile_p->writecache_total_writes,
+ profile_p->writecache_non_oplock_writes,
+ profile_p->writecache_allocated_write_caches,
+ profile_p->writecache_num_write_caches,
+ profile_p->writecache_direct_writes,
+ profile_p->writecache_num_perfect_writes,
+ profile_p->writecache_read_hits ));
+
+ DEBUG(3,("WRITECACHE: Flushes SEEK=%d, READ=%d, WRITE=%d, READRAW=%d, OPLOCK=%d, CLOSE=%d, SYNC=%d\n",
+ profile_p->writecache_flushed_writes[SEEK_FLUSH],
+ profile_p->writecache_flushed_writes[READ_FLUSH],
+ profile_p->writecache_flushed_writes[WRITE_FLUSH],
+ profile_p->writecache_flushed_writes[READRAW_FLUSH],
+ profile_p->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH],
+ profile_p->writecache_flushed_writes[CLOSE_FLUSH],
+ profile_p->writecache_flushed_writes[SYNC_FLUSH] ));
+ }
#endif
- if(!wcp) {
- DO_PROFILE_INC(writecache_direct_writes);
- total_written = real_write_file(fsp, data, pos, n);
- if ((total_written != -1) && (pos + total_written > fsp->size))
- fsp->size = pos + total_written;
- return total_written;
- }
+ if(!wcp) {
+ DO_PROFILE_INC(writecache_direct_writes);
+ total_written = real_write_file(fsp, data, pos, n);
+ if ((total_written != -1) && (pos + total_written > fsp->size))
+ fsp->size = pos + total_written;
+ return total_written;
+ }
- DEBUG(9,("write_file(fd=%d pos=%.0f size=%u) wcp->offset=%.0f wcp->data_size=%u\n",
- fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size));
+ DEBUG(9,("write_file (%s)(fd=%d pos=%.0f size=%u) wcp->offset=%.0f wcp->data_size=%u\n",
+ fsp->fsp_name, fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size));
- /*
- * If we have active cache and it isn't contiguous then we flush.
- * NOTE: There is a small problem with running out of disk ....
- */
+ /*
+ * If we have active cache and it isn't contiguous then we flush.
+ * NOTE: There is a small problem with running out of disk ....
+ */
- if (wcp->data_size) {
+ if (wcp->data_size) {
- BOOL cache_flush_needed = False;
+ BOOL cache_flush_needed = False;
- if ((pos >= wcp->offset) && (pos <= wcp->offset + wcp->data_size)) {
+ if ((pos >= wcp->offset) && (pos <= wcp->offset + wcp->data_size)) {
- /*
- * Start of write overlaps or abutts the existing data.
- */
+ /*
+ * Start of write overlaps or abutts the existing data.
+ */
- size_t data_used = MIN((wcp->alloc_size - (pos - wcp->offset)), n);
+ size_t data_used = MIN((wcp->alloc_size - (pos - wcp->offset)), n);
- memcpy(wcp->data + (pos - wcp->offset), data, data_used);
+ memcpy(wcp->data + (pos - wcp->offset), data, data_used);
- /*
- * Update the current buffer size with the new data.
- */
+ /*
+ * Update the current buffer size with the new data.
+ */
- if(pos + data_used > wcp->offset + wcp->data_size)
- wcp->data_size = pos + data_used - wcp->offset;
+ if(pos + data_used > wcp->offset + wcp->data_size)
+ wcp->data_size = pos + data_used - wcp->offset;
- /*
- * Update the file size if changed.
- */
+ /*
+ * Update the file size if changed.
+ */
- if (wcp->offset + wcp->data_size > wcp->file_size)
- fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
+ if (wcp->offset + wcp->data_size > wcp->file_size)
+ fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
- /*
- * If we used all the data then
- * return here.
- */
+ /*
+ * If we used all the data then
+ * return here.
+ */
- if(n == data_used)
- return n;
- else
- cache_flush_needed = True;
+ if(n == data_used)
+ return n;
+ else
+ cache_flush_needed = True;
- /*
- * Move the start of data forward by the amount used,
- * cut down the amount left by the same amount.
- */
+ /*
+ * Move the start of data forward by the amount used,
+ * cut down the amount left by the same amount.
+ */
- data += data_used;
- pos += data_used;
- n -= data_used;
+ data += data_used;
+ pos += data_used;
+ n -= data_used;
- DO_PROFILE_INC(writecache_abutted_writes);
- total_written = data_used;
+ DO_PROFILE_INC(writecache_abutted_writes);
+ total_written = data_used;
- write_path = 1;
+ write_path = 1;
- } else if ((pos < wcp->offset) && (pos + n > wcp->offset) &&
- (pos + n <= wcp->offset + wcp->alloc_size)) {
+ } else if ((pos < wcp->offset) && (pos + n > wcp->offset) &&
+ (pos + n <= wcp->offset + wcp->alloc_size)) {
- /*
- * End of write overlaps the existing data.
- */
+ /*
+ * End of write overlaps the existing data.
+ */
- size_t data_used = pos + n - wcp->offset;
+ size_t data_used = pos + n - wcp->offset;
- memcpy(wcp->data, data + n - data_used, data_used);
+ memcpy(wcp->data, data + n - data_used, data_used);
- /*
- * Update the current buffer size with the new data.
- */
+ /*
+ * Update the current buffer size with the new data.
+ */
- if(pos + n > wcp->offset + wcp->data_size)
- wcp->data_size = pos + n - wcp->offset;
+ if(pos + n > wcp->offset + wcp->data_size)
+ wcp->data_size = pos + n - wcp->offset;
- /*
- * Update the file size if changed.
- */
+ /*
+ * Update the file size if changed.
+ */
- if (wcp->offset + wcp->data_size > wcp->file_size)
- fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
+ if (wcp->offset + wcp->data_size > wcp->file_size)
+ fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
- /*
- * We don't need to move the start of data, but we
- * cut down the amount left by the amount used.
- */
+ /*
+ * We don't need to move the start of data, but we
+ * cut down the amount left by the amount used.
+ */
- n -= data_used;
+ n -= data_used;
- /*
- * We cannot have used all the data here.
- */
+ /*
+ * We cannot have used all the data here.
+ */
- cache_flush_needed = True;
+ cache_flush_needed = True;
- DO_PROFILE_INC(writecache_abutted_writes);
- total_written = data_used;
+ DO_PROFILE_INC(writecache_abutted_writes);
+ total_written = data_used;
- write_path = 2;
+ write_path = 2;
- } else if ( (pos >= wcp->file_size) &&
- (wcp->offset + wcp->data_size == wcp->file_size) &&
- (pos > wcp->offset + wcp->data_size) &&
- (pos < wcp->offset + wcp->alloc_size) ) {
+ } else if ( (pos >= wcp->file_size) &&
+ (wcp->offset + wcp->data_size == wcp->file_size) &&
+ (pos > wcp->offset + wcp->data_size) &&
+ (pos < wcp->offset + wcp->alloc_size) ) {
- /*
- * Non-contiguous write part of which fits within
- * the cache buffer and is extending the file
- * and the cache contents reflect the current
- * data up to the current end of the file.
- */
+ /*
+ * Non-contiguous write part of which fits within
+ * the cache buffer and is extending the file
+ * and the cache contents reflect the current
+ * data up to the current end of the file.
+ */
- size_t data_used;
+ size_t data_used;
- if(pos + n <= wcp->offset + wcp->alloc_size)
- data_used = n;
- else
- data_used = wcp->offset + wcp->alloc_size - pos;
+ if(pos + n <= wcp->offset + wcp->alloc_size)
+ data_used = n;
+ else
+ data_used = wcp->offset + wcp->alloc_size - pos;
- /*
- * Fill in the non-continuous area with zeros.
- */
+ /*
+ * Fill in the non-continuous area with zeros.
+ */
- memset(wcp->data + wcp->data_size, '\0',
- pos - (wcp->offset + wcp->data_size) );
+ memset(wcp->data + wcp->data_size, '\0',
+ pos - (wcp->offset + wcp->data_size) );
- memcpy(wcp->data + (pos - wcp->offset), data, data_used);
+ memcpy(wcp->data + (pos - wcp->offset), data, data_used);
- /*
- * Update the current buffer size with the new data.
- */
+ /*
+ * Update the current buffer size with the new data.
+ */
- if(pos + data_used > wcp->offset + wcp->data_size)
- wcp->data_size = pos + data_used - wcp->offset;
+ if(pos + data_used > wcp->offset + wcp->data_size)
+ wcp->data_size = pos + data_used - wcp->offset;
- /*
- * Update the file size if changed.
- */
+ /*
+ * Update the file size if changed.
+ */
- if (wcp->offset + wcp->data_size > wcp->file_size)
- fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
+ if (wcp->offset + wcp->data_size > wcp->file_size)
+ fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
- /*
- * If we used all the data then
- * return here.
- */
+ /*
+ * If we used all the data then
+ * return here.
+ */
- if(n == data_used)
- return n;
- else
- cache_flush_needed = True;
+ if(n == data_used)
+ return n;
+ else
+ cache_flush_needed = True;
- /*
- * Move the start of data forward by the amount used,
- * cut down the amount left by the same amount.
- */
+ /*
+ * Move the start of data forward by the amount used,
+ * cut down the amount left by the same amount.
+ */
- data += data_used;
- pos += data_used;
- n -= data_used;
+ data += data_used;
+ pos += data_used;
+ n -= data_used;
- DO_PROFILE_INC(writecache_abutted_writes);
- total_written = data_used;
+ DO_PROFILE_INC(writecache_abutted_writes);
+ total_written = data_used;
- write_path = 3;
+ write_path = 3;
- } else {
+ } else {
- /*
- * Write is bigger than buffer, or there is no overlap on the
- * low or high ends.
- */
+ /*
+ * Write is bigger than buffer, or there is no overlap on the
+ * low or high ends.
+ */
- DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
+ DEBUG(9,("write_file: non cacheable write : fd = %d, pos = %.0f, len = %u, current cache pos = %.0f \
len = %u\n",fsp->fd, (double)pos, (unsigned int)n, (double)wcp->offset, (unsigned int)wcp->data_size ));
- /*
- * Update the file size if needed.
- */
+ /*
+ * Update the file size if needed.
+ */
- if(pos + n > wcp->file_size)
- fsp->size = wcp->file_size = pos + n;
+ if(pos + n > wcp->file_size)
+ fsp->size = wcp->file_size = pos + n;
- /*
- * If write would fit in the cache, and is larger than
- * the data already in the cache, flush the cache and
- * preferentially copy the data new data into it. Otherwise
- * just write the data directly.
- */
+ /*
+ * If write would fit in the cache, and is larger than
+ * the data already in the cache, flush the cache and
+ * preferentially copy the data new data into it. Otherwise
+ * just write the data directly.
+ */
- if ( n <= wcp->alloc_size && n > wcp->data_size) {
- cache_flush_needed = True;
- } else {
- ssize_t ret = real_write_file(fsp, data, pos, n);
+ if ( n <= wcp->alloc_size && n > wcp->data_size) {
+ cache_flush_needed = True;
+ } else {
+ ssize_t ret = real_write_file(fsp, data, pos, n);
- DO_PROFILE_INC(writecache_direct_writes);
- if (ret == -1)
- return ret;
+ DO_PROFILE_INC(writecache_direct_writes);
+ if (ret == -1)
+ return ret;
- if (pos + ret > wcp->file_size)
- fsp->size = wcp->file_size = pos + ret;
+ if (pos + ret > wcp->file_size)
+ fsp->size = wcp->file_size = pos + ret;
- return ret;
- }
+ return ret;
+ }
- write_path = 4;
+ write_path = 4;
- }
+ }
- if(wcp->data_size > wcp->file_size)
- fsp->size = wcp->file_size = wcp->data_size;
+ if(wcp->data_size > wcp->file_size)
+ fsp->size = wcp->file_size = wcp->data_size;
- if (cache_flush_needed) {
- DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
+ if (cache_flush_needed) {
+ DEBUG(3,("WRITE_FLUSH:%d: due to noncontinuous write: fd = %d, size = %.0f, pos = %.0f, \
n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
- write_path, fsp->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
- (double)wcp->offset, (unsigned int)wcp->data_size ));
+ write_path, fsp->fd, (double)wcp->file_size, (double)pos, (unsigned int)n,
+ (double)wcp->offset, (unsigned int)wcp->data_size ));
- flush_write_cache(fsp, WRITE_FLUSH);
- }
- }
+ flush_write_cache(fsp, WRITE_FLUSH);
+ }
+ }
- /*
- * If the write request is bigger than the cache
- * size, write it all out.
- */
+ /*
+ * If the write request is bigger than the cache
+ * size, write it all out.
+ */
- if (n > wcp->alloc_size ) {
- ssize_t ret = real_write_file(fsp, data, pos, n);
- if (ret == -1)
- return -1;
+ if (n > wcp->alloc_size ) {
+ ssize_t ret = real_write_file(fsp, data, pos, n);
+ if (ret == -1)
+ return -1;
- if (pos + ret > wcp->file_size)
- fsp->size = wcp->file_size = pos + n;
+ if (pos + ret > wcp->file_size)
+ fsp->size = wcp->file_size = pos + n;
- DO_PROFILE_INC(writecache_direct_writes);
- return total_written + n;
- }
+ DO_PROFILE_INC(writecache_direct_writes);
+ return total_written + n;
+ }
- /*
- * If there's any data left, cache it.
- */
+ /*
+ * If there's any data left, cache it.
+ */
- if (n) {
+ if (n) {
#ifdef WITH_PROFILE
- if (wcp->data_size) {
- DO_PROFILE_INC(writecache_abutted_writes);
- } else {
- DO_PROFILE_INC(writecache_init_writes);
- }
+ if (wcp->data_size) {
+ DO_PROFILE_INC(writecache_abutted_writes);
+ } else {
+ DO_PROFILE_INC(writecache_init_writes);
+ }
#endif
- memcpy(wcp->data+wcp->data_size, data, n);
- if (wcp->data_size == 0) {
- wcp->offset = pos;
- DO_PROFILE_INC(writecache_num_write_caches);
- }
- wcp->data_size += n;
-
- /*
- * Update the file size if changed.
- */
-
- if (wcp->offset + wcp->data_size > wcp->file_size)
- fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
- DEBUG(9,("wcp->offset = %.0f wcp->data_size = %u cache return %u\n",
- (double)wcp->offset, (unsigned int)wcp->data_size, (unsigned int)n));
-
- total_written += n;
- return total_written; /* .... that's a write :) */
- }
+ memcpy(wcp->data+wcp->data_size, data, n);
+ if (wcp->data_size == 0) {
+ wcp->offset = pos;
+ DO_PROFILE_INC(writecache_num_write_caches);
+ }
+ wcp->data_size += n;
+
+ /*
+ * Update the file size if changed.
+ */
+
+ if (wcp->offset + wcp->data_size > wcp->file_size)
+ fsp->size = wcp->file_size = wcp->offset + wcp->data_size;
+ DEBUG(9,("wcp->offset = %.0f wcp->data_size = %u cache return %u\n",
+ (double)wcp->offset, (unsigned int)wcp->data_size, (unsigned int)n));
+
+ total_written += n;
+ return total_written; /* .... that's a write :) */
+ }
- return total_written;
+ return total_written;
}
/****************************************************************************
@@ -514,24 +525,23 @@ n = %u, wcp->offset=%.0f, wcp->data_size=%u\n",
void delete_write_cache(files_struct *fsp)
{
- write_cache *wcp;
-
- if(!fsp)
- return;
+ write_cache *wcp;
- if(!(wcp = fsp->wcp))
- return;
+ if(!fsp)
+ return;
- DO_PROFILE_DEC(writecache_allocated_write_caches);
- allocated_write_caches--;
+ if(!(wcp = fsp->wcp))
+ return;
- SMB_ASSERT(wcp->data_size == 0);
+ DO_PROFILE_DEC(writecache_allocated_write_caches);
+ allocated_write_caches--;
- SAFE_FREE(wcp->data);
- SAFE_FREE(fsp->wcp);
+ SMB_ASSERT(wcp->data_size == 0);
- DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
+ SAFE_FREE(wcp->data);
+ SAFE_FREE(fsp->wcp);
+ DEBUG(10,("delete_write_cache: File %s deleted write cache\n", fsp->fsp_name ));
}
/****************************************************************************
@@ -540,41 +550,41 @@ void delete_write_cache(files_struct *fsp)
static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
{
- ssize_t alloc_size = lp_write_cache_size(SNUM(fsp->conn));
- write_cache *wcp;
-
- if (allocated_write_caches >= MAX_WRITE_CACHES)
- return False;
-
- if(alloc_size == 0 || fsp->wcp)
- return False;
-
- if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
- DEBUG(0,("setup_write_cache: malloc fail.\n"));
- return False;
- }
-
- wcp->file_size = file_size;
- wcp->offset = 0;
- wcp->alloc_size = alloc_size;
- wcp->data_size = 0;
- if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
- DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
- (unsigned int)wcp->alloc_size ));
- SAFE_FREE(wcp);
- return False;
- }
-
- memset(wcp->data, '\0', wcp->alloc_size );
-
- fsp->wcp = wcp;
- DO_PROFILE_INC(writecache_allocated_write_caches);
- allocated_write_caches++;
-
- DEBUG(10,("setup_write_cache: File %s allocated write cache size %u\n",
+ ssize_t alloc_size = lp_write_cache_size(SNUM(fsp->conn));
+ write_cache *wcp;
+
+ if (allocated_write_caches >= MAX_WRITE_CACHES)
+ return False;
+
+ if(alloc_size == 0 || fsp->wcp)
+ return False;
+
+ if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
+ DEBUG(0,("setup_write_cache: malloc fail.\n"));
+ return False;
+ }
+
+ wcp->file_size = file_size;
+ wcp->offset = 0;
+ wcp->alloc_size = alloc_size;
+ wcp->data_size = 0;
+ if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
+ DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
+ (unsigned int)wcp->alloc_size ));
+ SAFE_FREE(wcp);
+ return False;
+ }
+
+ memset(wcp->data, '\0', wcp->alloc_size );
+
+ fsp->wcp = wcp;
+ DO_PROFILE_INC(writecache_allocated_write_caches);
+ allocated_write_caches++;
+
+ DEBUG(10,("setup_write_cache: File %s allocated write cache size %u\n",
fsp->fsp_name, wcp->alloc_size ));
- return True;
+ return True;
}
/****************************************************************************
@@ -583,17 +593,17 @@ static BOOL setup_write_cache(files_struct *fsp, SMB_OFF_T file_size)
void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size)
{
- fsp->size = file_size;
- if(fsp->wcp) {
- /* The cache *must* have been flushed before we do this. */
- if (fsp->wcp->data_size != 0) {
- pstring msg;
- slprintf(msg, sizeof(msg)-1, "set_filelen_write_cache: size change \
+ fsp->size = file_size;
+ if(fsp->wcp) {
+ /* The cache *must* have been flushed before we do this. */
+ if (fsp->wcp->data_size != 0) {
+ pstring msg;
+ slprintf(msg, sizeof(msg)-1, "set_filelen_write_cache: size change \
on file %s with write cache size = %u\n", fsp->fsp_name, fsp->wcp->data_size );
- smb_panic(msg);
- }
- fsp->wcp->file_size = file_size;
- }
+ smb_panic(msg);
+ }
+ fsp->wcp->file_size = file_size;
+ }
}
/*******************************************************************
@@ -602,36 +612,36 @@ on file %s with write cache size = %u\n", fsp->fsp_name, fsp->wcp->data_size );
ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason)
{
- write_cache *wcp = fsp->wcp;
- size_t data_size;
- ssize_t ret;
+ write_cache *wcp = fsp->wcp;
+ size_t data_size;
+ ssize_t ret;
- if(!wcp || !wcp->data_size)
- return 0;
+ if(!wcp || !wcp->data_size)
+ return 0;
- data_size = wcp->data_size;
- wcp->data_size = 0;
+ data_size = wcp->data_size;
+ wcp->data_size = 0;
- DO_PROFILE_DEC_INC(writecache_num_write_caches,writecache_flushed_writes[reason]);
+ DO_PROFILE_DEC_INC(writecache_num_write_caches,writecache_flushed_writes[reason]);
- DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
- fsp->fd, (double)wcp->offset, (unsigned int)data_size));
+ DEBUG(9,("flushing write cache: fd = %d, off=%.0f, size=%u\n",
+ fsp->fd, (double)wcp->offset, (unsigned int)data_size));
#ifdef WITH_PROFILE
- if(data_size == wcp->alloc_size)
- DO_PROFILE_INC(writecache_num_perfect_writes);
+ if(data_size == wcp->alloc_size)
+ DO_PROFILE_INC(writecache_num_perfect_writes);
#endif
- ret = real_write_file(fsp, wcp->data, wcp->offset, data_size);
+ ret = real_write_file(fsp, wcp->data, wcp->offset, data_size);
- /*
- * Ensure file size if kept up to date if write extends file.
- */
+ /*
+ * Ensure file size if kept up to date if write extends file.
+ */
- if ((ret != -1) && (wcp->offset + ret > wcp->file_size))
- wcp->file_size = wcp->offset + ret;
+ if ((ret != -1) && (wcp->offset + ret > wcp->file_size))
+ wcp->file_size = wcp->offset + ret;
- return ret;
+ return ret;
}
/*******************************************************************
@@ -640,12 +650,13 @@ sync a file
void sync_file(connection_struct *conn, files_struct *fsp)
{
- if(lp_strict_sync(SNUM(conn)) && fsp->fd != -1) {
- flush_write_cache(fsp, SYNC_FLUSH);
- conn->vfs_ops.fsync(fsp,fsp->fd);
- }
+ if(lp_strict_sync(SNUM(conn)) && fsp->fd != -1) {
+ flush_write_cache(fsp, SYNC_FLUSH);
+ conn->vfs_ops.fsync(fsp,fsp->fd);
+ }
}
+
/************************************************************
Perform a stat whether a valid fd or not.
************************************************************/