Home | History | Annotate | Line # | Download | only in fstat
      1  1.11       chs /*	$NetBSD: tmpfs.c,v 1.11 2017/06/09 00:13:29 chs Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*-
      4   1.1  christos  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5   1.1  christos  * All rights reserved.
      6   1.1  christos  *
      7   1.1  christos  * Redistribution and use in source and binary forms, with or without
      8   1.1  christos  * modification, are permitted provided that the following conditions
      9   1.1  christos  * are met:
     10   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  christos  *    documentation and/or other materials provided with the distribution.
     15   1.1  christos  *
     16   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1  christos  */
     28   1.1  christos 
     29   1.1  christos #include <sys/cdefs.h>
     30  1.11       chs __RCSID("$NetBSD: tmpfs.c,v 1.11 2017/06/09 00:13:29 chs Exp $");
     31   1.1  christos 
     32   1.1  christos #include <sys/types.h>
     33   1.1  christos #include <sys/param.h>
     34   1.1  christos #include <sys/time.h>
     35   1.1  christos #include <sys/proc.h>
     36   1.1  christos #include <sys/stat.h>
     37   1.1  christos #include <sys/vnode.h>
     38  1.11       chs #define __EXPOSE_MOUNT
     39   1.1  christos #include <sys/mount.h>
     40   1.1  christos 
     41   1.7     pooka #include <fs/tmpfs/tmpfs.h>
     42   1.1  christos 
     43   1.1  christos #include <err.h>
     44   1.1  christos #include <kvm.h>
     45   1.1  christos #include "fstat.h"
     46   1.1  christos 
     47   1.1  christos int
     48   1.1  christos tmpfs_filestat(struct vnode *vp, struct filestat *fsp)
     49   1.1  christos {
     50   1.1  christos 	struct tmpfs_node tn;
     51   1.1  christos 	struct mount mt;
     52   1.1  christos 
     53   1.1  christos 	if (!KVM_READ(VP_TO_TMPFS_NODE(vp), &tn, sizeof(tn))) {
     54   1.1  christos 		dprintf("can't read tmpfs_node at %p for pid %d",
     55   1.1  christos 		    VP_TO_TMPFS_NODE(vp), Pid);
     56   1.1  christos 		return 0;
     57   1.1  christos 	}
     58   1.1  christos 	if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
     59   1.1  christos 		dprintf("can't read mount at %p for pid %d",
     60   1.1  christos 		    vp->v_mount, Pid);
     61   1.1  christos 		return 0;
     62   1.1  christos 	}
     63   1.1  christos 
     64   1.1  christos 	fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
     65   1.8     lukem 	fsp->fileid = tn.tn_id;
     66   1.1  christos 	fsp->mode = tn.tn_mode | getftype(vp->v_type);
     67   1.1  christos 	fsp->size = tn.tn_size;
     68   1.1  christos 	switch (tn.tn_type) {
     69   1.1  christos 	case VBLK:
     70   1.1  christos 	case VCHR:
     71   1.2      jmmv 		fsp->rdev = tn.tn_spec.tn_dev.tn_rdev;
     72   1.1  christos 		break;
     73   1.1  christos 	default:
     74   1.1  christos 		fsp->rdev = 0;
     75   1.1  christos 		break;
     76   1.1  christos 	}
     77   1.1  christos 
     78   1.1  christos 	return 1;
     79   1.1  christos }
     80