1*ffdbc0ccSchs /* $NetBSD: tmpfs.c,v 1.11 2017/06/09 00:13:29 chs Exp $ */
262bee0ffSchristos
362bee0ffSchristos /*-
462bee0ffSchristos * Copyright (c) 2006 The NetBSD Foundation, Inc.
562bee0ffSchristos * All rights reserved.
662bee0ffSchristos *
762bee0ffSchristos * Redistribution and use in source and binary forms, with or without
862bee0ffSchristos * modification, are permitted provided that the following conditions
962bee0ffSchristos * are met:
1062bee0ffSchristos * 1. Redistributions of source code must retain the above copyright
1162bee0ffSchristos * notice, this list of conditions and the following disclaimer.
1262bee0ffSchristos * 2. Redistributions in binary form must reproduce the above copyright
1362bee0ffSchristos * notice, this list of conditions and the following disclaimer in the
1462bee0ffSchristos * documentation and/or other materials provided with the distribution.
1562bee0ffSchristos *
1662bee0ffSchristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1762bee0ffSchristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1862bee0ffSchristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1962bee0ffSchristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2062bee0ffSchristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2162bee0ffSchristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2262bee0ffSchristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2362bee0ffSchristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2462bee0ffSchristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2562bee0ffSchristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2662bee0ffSchristos * POSSIBILITY OF SUCH DAMAGE.
2762bee0ffSchristos */
2862bee0ffSchristos
2962bee0ffSchristos #include <sys/cdefs.h>
30*ffdbc0ccSchs __RCSID("$NetBSD: tmpfs.c,v 1.11 2017/06/09 00:13:29 chs Exp $");
3162bee0ffSchristos
3262bee0ffSchristos #include <sys/types.h>
3362bee0ffSchristos #include <sys/param.h>
3462bee0ffSchristos #include <sys/time.h>
3562bee0ffSchristos #include <sys/proc.h>
3662bee0ffSchristos #include <sys/stat.h>
3762bee0ffSchristos #include <sys/vnode.h>
38*ffdbc0ccSchs #define __EXPOSE_MOUNT
3962bee0ffSchristos #include <sys/mount.h>
4062bee0ffSchristos
41f00b7c9bSpooka #include <fs/tmpfs/tmpfs.h>
4262bee0ffSchristos
4362bee0ffSchristos #include <err.h>
4462bee0ffSchristos #include <kvm.h>
4562bee0ffSchristos #include "fstat.h"
4662bee0ffSchristos
4762bee0ffSchristos int
tmpfs_filestat(struct vnode * vp,struct filestat * fsp)4862bee0ffSchristos tmpfs_filestat(struct vnode *vp, struct filestat *fsp)
4962bee0ffSchristos {
5062bee0ffSchristos struct tmpfs_node tn;
5162bee0ffSchristos struct mount mt;
5262bee0ffSchristos
5362bee0ffSchristos if (!KVM_READ(VP_TO_TMPFS_NODE(vp), &tn, sizeof(tn))) {
5462bee0ffSchristos dprintf("can't read tmpfs_node at %p for pid %d",
5562bee0ffSchristos VP_TO_TMPFS_NODE(vp), Pid);
5662bee0ffSchristos return 0;
5762bee0ffSchristos }
5862bee0ffSchristos if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
5962bee0ffSchristos dprintf("can't read mount at %p for pid %d",
6062bee0ffSchristos vp->v_mount, Pid);
6162bee0ffSchristos return 0;
6262bee0ffSchristos }
6362bee0ffSchristos
6462bee0ffSchristos fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
65dadffc77Slukem fsp->fileid = tn.tn_id;
6662bee0ffSchristos fsp->mode = tn.tn_mode | getftype(vp->v_type);
6762bee0ffSchristos fsp->size = tn.tn_size;
6862bee0ffSchristos switch (tn.tn_type) {
6962bee0ffSchristos case VBLK:
7062bee0ffSchristos case VCHR:
71772e1db6Sjmmv fsp->rdev = tn.tn_spec.tn_dev.tn_rdev;
7262bee0ffSchristos break;
7362bee0ffSchristos default:
7462bee0ffSchristos fsp->rdev = 0;
7562bee0ffSchristos break;
7662bee0ffSchristos }
7762bee0ffSchristos
7862bee0ffSchristos return 1;
7962bee0ffSchristos }
80