procfs_vfsops.c revision 1.1.1.2 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 * From:
40 * $Id: procfs_vfsops.c,v 1.1.1.2 1998/03/01 02:13:20 fvdl Exp $
41 */
42
43 /*
44 * procfs VFS interface
45 */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/time.h>
50 #include <sys/kernel.h>
51 #include <sys/proc.h>
52 #include <sys/buf.h>
53 #include <sys/syslog.h>
54 #include <sys/mount.h>
55 #include <sys/signalvar.h>
56 #include <sys/vnode.h>
57 #include <miscfs/procfs/procfs.h>
58 #include <vm/vm.h> /* for PAGE_SIZE */
59
60 /*
61 * VFS Operations.
62 *
63 * mount system call
64 */
65 /* ARGSUSED */
66 procfs_mount(mp, path, data, ndp, p)
67 struct mount *mp;
68 char *path;
69 caddr_t data;
70 struct nameidata *ndp;
71 struct proc *p;
72 {
73 u_int size;
74
75 if (UIO_MX & (UIO_MX-1)) {
76 log(LOG_ERR, "procfs: invalid directory entry size");
77 return (EINVAL);
78 }
79
80 if (mp->mnt_flag & MNT_UPDATE)
81 return (EOPNOTSUPP);
82
83 mp->mnt_flag |= MNT_LOCAL;
84 mp->mnt_data = 0;
85 vfs_getnewfsid(mp);
86
87 (void) copyinstr(path, (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN, &size);
88 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
89
90 size = sizeof("procfs") - 1;
91 bcopy("procfs", mp->mnt_stat.f_mntfromname, size);
92 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
93
94 return (0);
95 }
96
97 /*
98 * unmount system call
99 */
100 procfs_unmount(mp, mntflags, p)
101 struct mount *mp;
102 int mntflags;
103 struct proc *p;
104 {
105 int error;
106 int flags = 0;
107
108 if (mntflags & MNT_FORCE)
109 flags |= FORCECLOSE;
110
111 if (error = vflush(mp, 0, flags))
112 return (error);
113
114 return (0);
115 }
116
117 procfs_root(mp, vpp)
118 struct mount *mp;
119 struct vnode **vpp;
120 {
121
122 return (procfs_allocvp(mp, vpp, 0, Proot));
123 }
124
125 /* ARGSUSED */
126 procfs_start(mp, flags, p)
127 struct mount *mp;
128 int flags;
129 struct proc *p;
130 {
131
132 return (0);
133 }
134
135 /*
136 * Get file system statistics.
137 */
138 procfs_statfs(mp, sbp, p)
139 struct mount *mp;
140 struct statfs *sbp;
141 struct proc *p;
142 {
143 sbp->f_bsize = PAGE_SIZE;
144 sbp->f_iosize = PAGE_SIZE;
145 sbp->f_blocks = 1; /* avoid divide by zero in some df's */
146 sbp->f_bfree = 0;
147 sbp->f_bavail = 0;
148 sbp->f_files = maxproc; /* approx */
149 sbp->f_ffree = maxproc - nprocs; /* approx */
150
151 if (sbp != &mp->mnt_stat) {
152 sbp->f_type = mp->mnt_vfc->vfc_typenum;
153 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
154 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
155 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
156 }
157
158 return (0);
159 }
160
161 procfs_init(vfsp)
162 struct vfsconf *vfsp;
163 {
164
165 return (0);
166 }
167
168 #define procfs_fhtovp ((int (*) __P((struct mount *, struct fid *, \
169 struct mbuf *, struct vnode **, int *, struct ucred **)))einval)
170 #define procfs_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
171 struct proc *)))eopnotsupp)
172 #define procfs_sync ((int (*) __P((struct mount *, int, struct ucred *, \
173 struct proc *)))nullop)
174 #define procfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
175 size_t, struct proc *)))eopnotsupp)
176 #define procfs_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
177 eopnotsupp)
178 #define procfs_vptofh ((int (*) __P((struct vnode *, struct fid *)))einval)
179
180 struct vfsops procfs_vfsops = {
181 procfs_mount,
182 procfs_start,
183 procfs_unmount,
184 procfs_root,
185 procfs_quotactl,
186 procfs_statfs,
187 procfs_sync,
188 procfs_vget,
189 procfs_fhtovp,
190 procfs_vptofh,
191 procfs_init,
192 procfs_sysctl,
193 };
194