Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/puffs If we truncate the file, make sure we zero-fill...



details:   https://anonhg.NetBSD.org/src/rev/fc8bdea75d99
branches:  trunk
changeset: 332709:fc8bdea75d99
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Oct 05 07:53:22 2014 +0000

description:
If we truncate the file, make sure we zero-fill the end of the last
page, otherwise if the file is later truncated to a larger size
(creating a hole), that area will not return zeroes as it should.

diffstat:

 sys/fs/puffs/puffs_vnops.c |  47 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 45 insertions(+), 2 deletions(-)

diffs (75 lines):

diff -r e680d885d653 -r fc8bdea75d99 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c        Sun Oct 05 03:47:17 2014 +0000
+++ b/sys/fs/puffs/puffs_vnops.c        Sun Oct 05 07:53:22 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vnops.c,v 1.187 2014/09/30 10:15:03 hannken Exp $        */
+/*     $NetBSD: puffs_vnops.c,v 1.188 2014/10/05 07:53:22 manu Exp $   */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.187 2014/09/30 10:15:03 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.188 2014/10/05 07:53:22 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -1130,6 +1130,38 @@
        return error;
 }
 
+static void
+zerofill_lastpage(struct vnode *vp, voff_t off)
+{
+       char zbuf[PAGE_SIZE];
+       struct iovec iov;
+       struct uio uio;
+       vsize_t len;
+       int error;
+
+       if (trunc_page(off) == off)
+               return;
+
+       len = round_page(off) - off;
+       memset(zbuf, 0, len);
+
+       iov.iov_base = zbuf;
+       iov.iov_len = len;
+       UIO_SETUP_SYSSPACE(&uio);
+       uio.uio_iov = &iov;
+       uio.uio_iovcnt = 1;
+       uio.uio_offset = off;
+       uio.uio_resid = len;
+       uio.uio_rw = UIO_WRITE;
+
+       error = ubc_uiomove(&vp->v_uobj, &uio, len,
+                           UVM_ADV_SEQUENTIAL, UBC_WRITE|UBC_UNMAP_FLAG(vp));
+       if (error)
+               DPRINTF(("zero-fill 0x%lx@0x%llx => %d\n", len, off, error));
+
+       return;
+}
+
 static int
 dosetattr(struct vnode *vp, struct vattr *vap, kauth_cred_t cred, int flags)
 {
@@ -1191,6 +1223,17 @@
        if ((flags & SETATTR_ASYNC) == 0)
                error = puffs_msg_wait2(pmp, park_setattr, vp->v_data, NULL);
 
+       /*
+        * If we truncate the file, make sure we zero-fill
+        * the end of the last page, otherwise if the file
+        * is later truncated to a larger size (creating a
+        * a hole), that area will not return zeroes as it
+        * should.
+        */
+       if ((error == 0) && (flags & SETATTR_CHSIZE) &&
+           (vap->va_size != VNOVAL) && (vap->va_size < vp->v_size))
+               zerofill_lastpage(vp, vap->va_size);
+
        if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
                struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl;
                struct vattr *rvap = &setattr_msg->pvnr_va;



Home | Main Index | Thread Index | Old Index