Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / vfs / procfs / procfs_vfsops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1993 Jan-Simon Pendry
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Jan-Simon Pendry.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)procfs_vfsops.c 8.7 (Berkeley) 5/10/95
38 *
39 * $FreeBSD: src/sys/miscfs/procfs/procfs_vfsops.c,v 1.32.2.1 2001/10/15 20:42:01 des Exp $
086c1d7e 40 * $DragonFly: src/sys/vfs/procfs/procfs_vfsops.c,v 1.16 2006/12/23 00:41:30 swildner Exp $
984263bc
MD
41 */
42
43/*
44 * procfs VFS interface
45 */
46
47#include <sys/param.h>
48#include <sys/systm.h>
49#include <sys/kernel.h>
50#include <sys/proc.h>
51#include <sys/mount.h>
52#include <sys/vnode.h>
1f2de5d4 53#include <vfs/procfs/procfs.h>
984263bc 54
66a1ddf5 55extern struct vop_ops procfs_vnode_vops;
0961aa92 56
a6ee311a 57static int procfs_mount (struct mount *mp, char *path, caddr_t data,
acde96db 58 struct ucred *cred);
a6ee311a 59static int procfs_statfs (struct mount *mp, struct statfs *sbp,
acde96db
MD
60 struct ucred *cred);
61static int procfs_unmount (struct mount *mp, int mntflags);
984263bc
MD
62
63/*
64 * VFS Operations.
65 *
66 * mount system call
67 */
68/* ARGSUSED */
69static int
acde96db 70procfs_mount(struct mount *mp, char *path, caddr_t data, struct ucred *cred)
984263bc
MD
71{
72 size_t size;
73 int error;
74
75 if (mp->mnt_flag & MNT_UPDATE)
76 return (EOPNOTSUPP);
77
78 if (mp->mnt_vfc->vfc_refcount == 1 && (error = at_exit(procfs_exit))) {
086c1d7e 79 kprintf("procfs: cannot register procfs_exit with at_exit\n");
984263bc
MD
80 return(error);
81 }
82
83 mp->mnt_flag |= MNT_LOCAL;
84 mp->mnt_data = 0;
85 vfs_getnewfsid(mp);
86
984263bc
MD
87 size = sizeof("procfs") - 1;
88 bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
89 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
acde96db 90 procfs_statfs(mp, &mp->mnt_stat, cred);
66a1ddf5 91 vfs_add_vnodeops(mp, &procfs_vnode_vops, &mp->mnt_vn_norm_ops);
984263bc
MD
92
93 return (0);
94}
95
96/*
97 * unmount system call
98 */
99static int
acde96db 100procfs_unmount(struct mount *mp, int mntflags)
984263bc
MD
101{
102 int error;
103 int flags = 0;
104
105 if (mntflags & MNT_FORCE)
106 flags |= FORCECLOSE;
107
108 error = vflush(mp, 0, flags);
109 if (error)
110 return (error);
111
112 if (mp->mnt_vfc->vfc_refcount == 1)
113 rm_at_exit(procfs_exit);
114
115 return (0);
116}
117
3446c007
MD
118/*
119 * Sets *vpp to the root procfs vnode, referenced and exclusively locked.
120 */
984263bc 121int
ac424f9b 122procfs_root(struct mount *mp, struct vnode **vpp)
984263bc 123{
984263bc
MD
124 return (procfs_allocvp(mp, vpp, 0, Proot));
125}
126
127/*
128 * Get file system statistics.
129 */
130static int
acde96db 131procfs_statfs(struct mount *mp, struct statfs *sbp, struct ucred *cred)
984263bc
MD
132{
133 sbp->f_bsize = PAGE_SIZE;
134 sbp->f_iosize = PAGE_SIZE;
135 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
136 sbp->f_bfree = 0;
137 sbp->f_bavail = 0;
138 sbp->f_files = maxproc; /* approx */
139 sbp->f_ffree = maxproc - nprocs; /* approx */
140
141 if (sbp != &mp->mnt_stat) {
142 sbp->f_type = mp->mnt_vfc->vfc_typenum;
143 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
984263bc
MD
144 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
145 }
146
147 return (0);
148}
149
150static struct vfsops procfs_vfsops = {
43c45e8f
HP
151 .vfs_mount = procfs_mount,
152 .vfs_unmount = procfs_unmount,
153 .vfs_root = procfs_root,
154 .vfs_statfs = procfs_statfs,
155 .vfs_sync = vfs_stdsync
984263bc
MD
156};
157
158VFS_SET(procfs_vfsops, procfs, VFCF_SYNTHETIC);
159MODULE_VERSION(procfs, 1);