summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2010-07-29 14:48:06 +0200
committerVolker Lendecke <vl@samba.org>2010-07-29 22:46:44 +0200
commita8cd3ef99eb70d70b9272b6e3ab5cc737195e06c (patch)
tree92db1a1cfb7c7515270650ac5c9ee274ebf70ae4 /source3
parenta86cad3921c4a8ddbcab1929c825356aec4fe76a (diff)
downloadsamba-a8cd3ef99eb70d70b9272b6e3ab5cc737195e06c.tar.gz
samba-a8cd3ef99eb70d70b9272b6e3ab5cc737195e06c.tar.bz2
samba-a8cd3ef99eb70d70b9272b6e3ab5cc737195e06c.zip
s3: Do the ftruncate write cache optimization in one place
Instead of hand-tuning all the cases that are below this piece of code, this is a general case that we can catch upfront.
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/fileio.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c
index c6094f902b..b4e8a1d5d4 100644
--- a/source3/smbd/fileio.c
+++ b/source3/smbd/fileio.c
@@ -401,6 +401,37 @@ nonop=%u allocated=%u active=%u direct=%u perfect=%u readhits=%u\n",
fsp->fh->pos = pos + n;
+ if ((n == 1) && (data[0] == '\0') && (pos > wcp->file_size)) {
+ int ret;
+
+ /*
+ * This is a 1-byte write of a 0 beyond the EOF and
+ * thus implicitly also beyond the current active
+ * write cache, the typical file-extending (and
+ * allocating, but we're using the write cache here)
+ * write done by Windows. We just have to ftruncate
+ * the file and rely on posix semantics to return
+ * zeros for non-written file data that is within the
+ * file length.
+ *
+ * We can not use wcp_file_size_change here because we
+ * might have an existing write cache, and
+ * wcp_file_size_change assumes a change to just the
+ * end of the current write cache.
+ */
+
+ wcp->file_size = pos + 1;
+ ret = SMB_VFS_FTRUNCATE(fsp, wcp->file_size);
+ if (ret == -1) {
+ DEBUG(0,("wcp_file_size_change (%s): ftruncate of size %.0f"
+ "error %s\n", fsp_str_dbg(fsp),
+ (double)wcp->file_size, strerror(errno)));
+ return -1;
+ }
+ return 1;
+ }
+
+
/*
* If we have active cache and it isn't contiguous then we flush.
* NOTE: There is a small problem with running out of disk ....