From 677c3c0c66f7c3829fd1d1f868b786f1de0416d5 Mon Sep 17 00:00:00 2001 From: Will Andrews Date: Fri, 10 Apr 2015 19:04:39 +0000 Subject: tmpfs_getattr(): Return more correct allocated byte counts. For VREG vnodes, return the resident page count (multiplied by PAGE_SIZE) for the tmpfs node's anonymous VM object that stores actual file contents. For all other vnodes, return the tmpfs_node's tn_size, which should not be rounded to a page. This change allows using stat(2) to identify a sparse file on tmpfs. Reviewed by: kib MFC after: 1 week --- sys/fs/tmpfs/tmpfs_vnops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sys') diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index 885f84cdf2b5..9bdb1e90917c 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -342,7 +342,7 @@ tmpfs_getattr(struct vop_getattr_args *v) { struct vnode *vp = v->a_vp; struct vattr *vap = v->a_vap; - + vm_object_t obj; struct tmpfs_node *node; node = VP_TO_TMPFS_NODE(vp); @@ -366,7 +366,11 @@ tmpfs_getattr(struct vop_getattr_args *v) vap->va_flags = node->tn_flags; vap->va_rdev = (vp->v_type == VBLK || vp->v_type == VCHR) ? node->tn_rdev : NODEV; - vap->va_bytes = round_page(node->tn_size); + if (vp->v_type == VREG) { + obj = node->tn_reg.tn_aobj; + vap->va_bytes = (u_quad_t)obj->resident_page_count * PAGE_SIZE; + } else + vap->va_bytes = node->tn_size; vap->va_filerev = 0; return 0; -- cgit v1.2.3