Deleted Added
full compact
fdesc_vfsops.c (1541) fdesc_vfsops.c (2946)
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software donated to Berkeley by
6 * Jan-Simon Pendry.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)fdesc_vfsops.c 8.4 (Berkeley) 1/21/94
37 *
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software donated to Berkeley by
6 * Jan-Simon Pendry.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)fdesc_vfsops.c 8.4 (Berkeley) 1/21/94
37 *
38 * $Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp $
38 * $Id: fdesc_vfsops.c,v 1.1.1.1 1994/05/24 10:04:59 rgrimes Exp $
39 */
40
41/*
42 * /dev/fd Filesystem
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
39 */
40
41/*
42 * /dev/fd Filesystem
43 */
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
47#include <sys/time.h>
48#include <sys/types.h>
49#include <sys/proc.h>
50#include <sys/resourcevar.h>
51#include <sys/filedesc.h>
52#include <sys/vnode.h>
53#include <sys/mount.h>
54#include <sys/namei.h>
55#include <sys/malloc.h>
56#include <miscfs/fdesc/fdesc.h>
57
58/*
59 * Mount the per-process file descriptors (/dev/fd)
60 */
61int
62fdesc_mount(mp, path, data, ndp, p)
63 struct mount *mp;
64 char *path;
65 caddr_t data;
66 struct nameidata *ndp;
67 struct proc *p;
68{
69 int error = 0;
70 u_int size;
71 struct fdescmount *fmp;
72 struct vnode *rvp;
73
74 /*
75 * Update is a no-op
76 */
77 if (mp->mnt_flag & MNT_UPDATE)
78 return (EOPNOTSUPP);
79
80 error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
81 if (error)
82 return (error);
83
84 MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
85 M_UFSMNT, M_WAITOK); /* XXX */
86 rvp->v_type = VDIR;
87 rvp->v_flag |= VROOT;
88 fmp->f_root = rvp;
89 /* XXX -- don't mark as local to work around fts() problems */
90 /*mp->mnt_flag |= MNT_LOCAL;*/
91 mp->mnt_data = (qaddr_t) fmp;
92 getnewfsid(mp, MOUNT_FDESC);
93
94 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
95 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
96 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
97 bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc"));
98 return (0);
99}
100
101int
102fdesc_start(mp, flags, p)
103 struct mount *mp;
104 int flags;
105 struct proc *p;
106{
107 return (0);
108}
109
110int
111fdesc_unmount(mp, mntflags, p)
112 struct mount *mp;
113 int mntflags;
114 struct proc *p;
115{
116 int error;
117 int flags = 0;
118 extern int doforce;
119 struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
120
121 if (mntflags & MNT_FORCE) {
122 /* fdesc can never be rootfs so don't check for it */
123 if (!doforce)
124 return (EINVAL);
125 flags |= FORCECLOSE;
126 }
127
128 /*
129 * Clear out buffer cache. I don't think we
130 * ever get anything cached at this level at the
131 * moment, but who knows...
132 */
133 if (rootvp->v_usecount > 1)
134 return (EBUSY);
135 if (error = vflush(mp, rootvp, flags))
136 return (error);
137
138 /*
139 * Release reference on underlying root vnode
140 */
141 vrele(rootvp);
142 /*
143 * And blow it away for future re-use
144 */
145 vgone(rootvp);
146 /*
147 * Finally, throw away the fdescmount structure
148 */
149 free(mp->mnt_data, M_UFSMNT); /* XXX */
150 mp->mnt_data = 0;
151
152 return (0);
153}
154
155int
156fdesc_root(mp, vpp)
157 struct mount *mp;
158 struct vnode **vpp;
159{
160 struct vnode *vp;
161
162 /*
163 * Return locked reference to root.
164 */
165 vp = VFSTOFDESC(mp)->f_root;
166 VREF(vp);
167 VOP_LOCK(vp);
168 *vpp = vp;
169 return (0);
170}
171
172int
173fdesc_quotactl(mp, cmd, uid, arg, p)
174 struct mount *mp;
175 int cmd;
176 uid_t uid;
177 caddr_t arg;
178 struct proc *p;
179{
180
181 return (EOPNOTSUPP);
182}
183
184int
185fdesc_statfs(mp, sbp, p)
186 struct mount *mp;
187 struct statfs *sbp;
188 struct proc *p;
189{
190 struct filedesc *fdp;
191 int lim;
192 int i;
193 int last;
194 int freefd;
195
196 /*
197 * Compute number of free file descriptors.
198 * [ Strange results will ensue if the open file
199 * limit is ever reduced below the current number
200 * of open files... ]
201 */
202 lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
203 fdp = p->p_fd;
204 last = min(fdp->fd_nfiles, lim);
205 freefd = 0;
206 for (i = fdp->fd_freefile; i < last; i++)
207 if (fdp->fd_ofiles[i] == NULL)
208 freefd++;
209
210 /*
211 * Adjust for the fact that the fdesc array may not
212 * have been fully allocated yet.
213 */
214 if (fdp->fd_nfiles < lim)
215 freefd += (lim - fdp->fd_nfiles);
216
217 sbp->f_type = MOUNT_FDESC;
218 sbp->f_flags = 0;
219 sbp->f_bsize = DEV_BSIZE;
220 sbp->f_iosize = DEV_BSIZE;
221 sbp->f_blocks = 2; /* 1K to keep df happy */
222 sbp->f_bfree = 0;
223 sbp->f_bavail = 0;
224 sbp->f_files = lim + 1; /* Allow for "." */
225 sbp->f_ffree = freefd; /* See comments above */
226 if (sbp != &mp->mnt_stat) {
227 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
228 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
229 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
230 }
231 return (0);
232}
233
234int
235fdesc_sync(mp, waitfor)
236 struct mount *mp;
237 int waitfor;
238{
239
240 return (0);
241}
242
243/*
244 * Fdesc flat namespace lookup.
245 * Currently unsupported.
246 */
247int
248fdesc_vget(mp, ino, vpp)
249 struct mount *mp;
250 ino_t ino;
251 struct vnode **vpp;
252{
253
254 return (EOPNOTSUPP);
255}
256
257int
258fdesc_fhtovp(mp, fhp, setgen, vpp)
259 struct mount *mp;
260 struct fid *fhp;
261 int setgen;
262 struct vnode **vpp;
263{
264 return (EOPNOTSUPP);
265}
266
267int
268fdesc_vptofh(vp, fhp)
269 struct vnode *vp;
270 struct fid *fhp;
271{
272
273 return (EOPNOTSUPP);
274}
275
276struct vfsops fdesc_vfsops = {
277 fdesc_mount,
278 fdesc_start,
279 fdesc_unmount,
280 fdesc_root,
281 fdesc_quotactl,
282 fdesc_statfs,
283 fdesc_sync,
284 fdesc_vget,
285 fdesc_fhtovp,
286 fdesc_vptofh,
287 fdesc_init,
288};
48#include <sys/time.h>
49#include <sys/types.h>
50#include <sys/proc.h>
51#include <sys/resourcevar.h>
52#include <sys/filedesc.h>
53#include <sys/vnode.h>
54#include <sys/mount.h>
55#include <sys/namei.h>
56#include <sys/malloc.h>
57#include <miscfs/fdesc/fdesc.h>
58
59/*
60 * Mount the per-process file descriptors (/dev/fd)
61 */
62int
63fdesc_mount(mp, path, data, ndp, p)
64 struct mount *mp;
65 char *path;
66 caddr_t data;
67 struct nameidata *ndp;
68 struct proc *p;
69{
70 int error = 0;
71 u_int size;
72 struct fdescmount *fmp;
73 struct vnode *rvp;
74
75 /*
76 * Update is a no-op
77 */
78 if (mp->mnt_flag & MNT_UPDATE)
79 return (EOPNOTSUPP);
80
81 error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
82 if (error)
83 return (error);
84
85 MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
86 M_UFSMNT, M_WAITOK); /* XXX */
87 rvp->v_type = VDIR;
88 rvp->v_flag |= VROOT;
89 fmp->f_root = rvp;
90 /* XXX -- don't mark as local to work around fts() problems */
91 /*mp->mnt_flag |= MNT_LOCAL;*/
92 mp->mnt_data = (qaddr_t) fmp;
93 getnewfsid(mp, MOUNT_FDESC);
94
95 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
96 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
97 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
98 bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc"));
99 return (0);
100}
101
102int
103fdesc_start(mp, flags, p)
104 struct mount *mp;
105 int flags;
106 struct proc *p;
107{
108 return (0);
109}
110
111int
112fdesc_unmount(mp, mntflags, p)
113 struct mount *mp;
114 int mntflags;
115 struct proc *p;
116{
117 int error;
118 int flags = 0;
119 extern int doforce;
120 struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
121
122 if (mntflags & MNT_FORCE) {
123 /* fdesc can never be rootfs so don't check for it */
124 if (!doforce)
125 return (EINVAL);
126 flags |= FORCECLOSE;
127 }
128
129 /*
130 * Clear out buffer cache. I don't think we
131 * ever get anything cached at this level at the
132 * moment, but who knows...
133 */
134 if (rootvp->v_usecount > 1)
135 return (EBUSY);
136 if (error = vflush(mp, rootvp, flags))
137 return (error);
138
139 /*
140 * Release reference on underlying root vnode
141 */
142 vrele(rootvp);
143 /*
144 * And blow it away for future re-use
145 */
146 vgone(rootvp);
147 /*
148 * Finally, throw away the fdescmount structure
149 */
150 free(mp->mnt_data, M_UFSMNT); /* XXX */
151 mp->mnt_data = 0;
152
153 return (0);
154}
155
156int
157fdesc_root(mp, vpp)
158 struct mount *mp;
159 struct vnode **vpp;
160{
161 struct vnode *vp;
162
163 /*
164 * Return locked reference to root.
165 */
166 vp = VFSTOFDESC(mp)->f_root;
167 VREF(vp);
168 VOP_LOCK(vp);
169 *vpp = vp;
170 return (0);
171}
172
173int
174fdesc_quotactl(mp, cmd, uid, arg, p)
175 struct mount *mp;
176 int cmd;
177 uid_t uid;
178 caddr_t arg;
179 struct proc *p;
180{
181
182 return (EOPNOTSUPP);
183}
184
185int
186fdesc_statfs(mp, sbp, p)
187 struct mount *mp;
188 struct statfs *sbp;
189 struct proc *p;
190{
191 struct filedesc *fdp;
192 int lim;
193 int i;
194 int last;
195 int freefd;
196
197 /*
198 * Compute number of free file descriptors.
199 * [ Strange results will ensue if the open file
200 * limit is ever reduced below the current number
201 * of open files... ]
202 */
203 lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
204 fdp = p->p_fd;
205 last = min(fdp->fd_nfiles, lim);
206 freefd = 0;
207 for (i = fdp->fd_freefile; i < last; i++)
208 if (fdp->fd_ofiles[i] == NULL)
209 freefd++;
210
211 /*
212 * Adjust for the fact that the fdesc array may not
213 * have been fully allocated yet.
214 */
215 if (fdp->fd_nfiles < lim)
216 freefd += (lim - fdp->fd_nfiles);
217
218 sbp->f_type = MOUNT_FDESC;
219 sbp->f_flags = 0;
220 sbp->f_bsize = DEV_BSIZE;
221 sbp->f_iosize = DEV_BSIZE;
222 sbp->f_blocks = 2; /* 1K to keep df happy */
223 sbp->f_bfree = 0;
224 sbp->f_bavail = 0;
225 sbp->f_files = lim + 1; /* Allow for "." */
226 sbp->f_ffree = freefd; /* See comments above */
227 if (sbp != &mp->mnt_stat) {
228 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
229 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
230 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
231 }
232 return (0);
233}
234
235int
236fdesc_sync(mp, waitfor)
237 struct mount *mp;
238 int waitfor;
239{
240
241 return (0);
242}
243
244/*
245 * Fdesc flat namespace lookup.
246 * Currently unsupported.
247 */
248int
249fdesc_vget(mp, ino, vpp)
250 struct mount *mp;
251 ino_t ino;
252 struct vnode **vpp;
253{
254
255 return (EOPNOTSUPP);
256}
257
258int
259fdesc_fhtovp(mp, fhp, setgen, vpp)
260 struct mount *mp;
261 struct fid *fhp;
262 int setgen;
263 struct vnode **vpp;
264{
265 return (EOPNOTSUPP);
266}
267
268int
269fdesc_vptofh(vp, fhp)
270 struct vnode *vp;
271 struct fid *fhp;
272{
273
274 return (EOPNOTSUPP);
275}
276
277struct vfsops fdesc_vfsops = {
278 fdesc_mount,
279 fdesc_start,
280 fdesc_unmount,
281 fdesc_root,
282 fdesc_quotactl,
283 fdesc_statfs,
284 fdesc_sync,
285 fdesc_vget,
286 fdesc_fhtovp,
287 fdesc_vptofh,
288 fdesc_init,
289};
290
291VFS_SET(fdesc_vfsops, fdesc, MOUNT_FDESC, 0);