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