diff --git a/sys/rump/librump/rumpvfs/rumpfs.c b/sys/rump/librump/rumpvfs/rumpfs.c index 3b78a305bd65..8700e50099b9 100644 --- a/sys/rump/librump/rumpvfs/rumpfs.c +++ b/sys/rump/librump/rumpvfs/rumpfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: rumpfs.c,v 1.89 2011/01/14 11:07:42 pooka Exp $ */ +/* $NetBSD: rumpfs.c,v 1.90 2011/02/02 14:41:55 pooka Exp $ */ /* * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.89 2011/01/14 11:07:42 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.90 2011/02/02 14:41:55 pooka Exp $"); #include #include @@ -855,8 +855,24 @@ rump_vop_setattr(void *v) SETIFVAL(va_flags, u_long); #undef SETIFVAL - if (vp->v_type == VREG && vap->va_size != VSIZENOTSET) - uvm_vnp_setsize(vp, vap->va_size); + if (vp->v_type == VREG && + vap->va_size != VSIZENOTSET && + vap->va_size != rn->rn_dlen) { + void *newdata; + size_t copylen, newlen; + + newlen = vap->va_size; + newdata = rump_hypermalloc(newlen, 0, true, "rumpfs"); + + copylen = MIN(rn->rn_dlen, newlen); + memset(newdata, 0, newlen); + memcpy(newdata, rn->rn_data, copylen); + rump_hyperfree(rn->rn_data, rn->rn_dlen); + + rn->rn_data = newdata; + rn->rn_dlen = newlen; + uvm_vnp_setsize(vp, newlen); + } return 0; }