tmpfs.c revision 1.3.2.1 1 1.3.2.1 chap /* $NetBSD: tmpfs.c,v 1.3.2.1 2006/06/19 04:17:06 chap 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 * 3. All advertising materials mentioning features or use of this software
16 1.1 christos * must display the following acknowledgement:
17 1.1 christos * This product includes software developed by the NetBSD
18 1.1 christos * Foundation, Inc. and its contributors.
19 1.1 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1 christos * contributors may be used to endorse or promote products derived
21 1.1 christos * from this software without specific prior written permission.
22 1.1 christos *
23 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
34 1.1 christos */
35 1.1 christos
36 1.1 christos #include <sys/cdefs.h>
37 1.3.2.1 chap __RCSID("$NetBSD: tmpfs.c,v 1.3.2.1 2006/06/19 04:17:06 chap Exp $");
38 1.1 christos
39 1.1 christos #include <sys/types.h>
40 1.1 christos #include <sys/param.h>
41 1.1 christos #include <sys/time.h>
42 1.1 christos #include <sys/proc.h>
43 1.1 christos #include <sys/stat.h>
44 1.1 christos #include <sys/vnode.h>
45 1.1 christos #include <sys/mount.h>
46 1.1 christos
47 1.1 christos #include <fs/tmpfs/tmpfs.h>
48 1.1 christos
49 1.1 christos #include <err.h>
50 1.1 christos #include <kvm.h>
51 1.1 christos #include "fstat.h"
52 1.1 christos
53 1.1 christos int
54 1.1 christos tmpfs_filestat(struct vnode *vp, struct filestat *fsp)
55 1.1 christos {
56 1.1 christos struct tmpfs_node tn;
57 1.1 christos struct mount mt;
58 1.1 christos
59 1.1 christos if (!KVM_READ(VP_TO_TMPFS_NODE(vp), &tn, sizeof(tn))) {
60 1.1 christos dprintf("can't read tmpfs_node at %p for pid %d",
61 1.1 christos VP_TO_TMPFS_NODE(vp), Pid);
62 1.1 christos return 0;
63 1.1 christos }
64 1.1 christos if (!KVM_READ(vp->v_mount, &mt, sizeof(mt))) {
65 1.1 christos dprintf("can't read mount at %p for pid %d",
66 1.1 christos vp->v_mount, Pid);
67 1.1 christos return 0;
68 1.1 christos }
69 1.1 christos
70 1.1 christos fsp->fsid = mt.mnt_stat.f_fsidx.__fsid_val[0];
71 1.1 christos fsp->fileid = (long)tn.tn_id;
72 1.1 christos fsp->mode = tn.tn_mode | getftype(vp->v_type);
73 1.1 christos fsp->size = tn.tn_size;
74 1.1 christos switch (tn.tn_type) {
75 1.1 christos case VBLK:
76 1.1 christos case VCHR:
77 1.2 jmmv fsp->rdev = tn.tn_spec.tn_dev.tn_rdev;
78 1.1 christos break;
79 1.1 christos default:
80 1.1 christos fsp->rdev = 0;
81 1.1 christos break;
82 1.1 christos }
83 1.1 christos
84 1.1 christos return 1;
85 1.1 christos }
86