Home | History | Annotate | Line # | Download | only in fstat
tmpfs.c revision 1.4.18.1
      1  1.4.18.1      yamt /*	$NetBSD: tmpfs.c,v 1.4.18.1 2008/05/18 12:36:05 yamt 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.4.18.1      yamt __RCSID("$NetBSD: tmpfs.c,v 1.4.18.1 2008/05/18 12:36:05 yamt 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.1  christos #include <sys/mount.h>
     39       1.1  christos 
     40       1.1  christos #include <fs/tmpfs/tmpfs.h>
     41       1.1  christos 
     42       1.1  christos #include <err.h>
     43       1.1  christos #include <kvm.h>
     44       1.1  christos #include "fstat.h"
     45       1.1  christos 
     46       1.1  christos int
     47       1.1  christos tmpfs_filestat(struct vnode *vp, struct filestat *fsp)
     48       1.1  christos {
     49       1.1  christos 	struct tmpfs_node tn;
     50       1.1  christos 	struct mount mt;
     51       1.1  christos 
     52       1.1  christos 	if (!KVM_READ(VP_TO_TMPFS_NODE(vp), &tn, sizeof(tn))) {
     53       1.1  christos 		dprintf("can't read tmpfs_node at %p for pid %d",
     54       1.1  christos 		    VP_TO_TMPFS_NODE(vp), Pid);
     55       1.1  christos 		return 0;
     56       1.1  christos 	}
     57       1.1  christos 	if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
     58       1.1  christos 		dprintf("can't read mount at %p for pid %d",
     59       1.1  christos 		    vp->v_mount, Pid);
     60       1.1  christos 		return 0;
     61       1.1  christos 	}
     62       1.1  christos 
     63       1.1  christos 	fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
     64       1.1  christos 	fsp->fileid = (long)tn.tn_id;
     65       1.1  christos 	fsp->mode = tn.tn_mode | getftype(vp->v_type);
     66       1.1  christos 	fsp->size = tn.tn_size;
     67       1.1  christos 	switch (tn.tn_type) {
     68       1.1  christos 	case VBLK:
     69       1.1  christos 	case VCHR:
     70       1.2      jmmv 		fsp->rdev = tn.tn_spec.tn_dev.tn_rdev;
     71       1.1  christos 		break;
     72       1.1  christos 	default:
     73       1.1  christos 		fsp->rdev = 0;
     74       1.1  christos 		break;
     75       1.1  christos 	}
     76       1.1  christos 
     77       1.1  christos 	return 1;
     78       1.1  christos }
     79