check for forcible unmount at syscall level
[unix-history] / usr / src / sys / miscfs / fdesc / fdesc_vfsops.c
CommitLineData
e2e9adba 1/*
99315dca
KB
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
e2e9adba
JSP
4 *
5 * This code is derived from software donated to Berkeley by
6 * Jan-Simon Pendry.
7 *
8 * %sccs.include.redist.c%
9 *
6902a390 10 * @(#)fdesc_vfsops.c 8.8 (Berkeley) %G%
e2e9adba 11 *
01936f59 12 * $Id: fdesc_vfsops.c,v 1.9 1993/04/06 15:28:33 jsp Exp $
e2e9adba
JSP
13 */
14
15/*
16 * /dev/fd Filesystem
17 */
18
19#include <sys/param.h>
20#include <sys/systm.h>
21#include <sys/time.h>
22#include <sys/types.h>
23#include <sys/proc.h>
24#include <sys/resourcevar.h>
25#include <sys/filedesc.h>
26#include <sys/vnode.h>
27#include <sys/mount.h>
28#include <sys/namei.h>
29#include <sys/malloc.h>
3e707a05 30#include <miscfs/fdesc/fdesc.h>
e2e9adba 31
e2e9adba
JSP
32/*
33 * Mount the per-process file descriptors (/dev/fd)
34 */
43ec9518 35int
e2e9adba
JSP
36fdesc_mount(mp, path, data, ndp, p)
37 struct mount *mp;
38 char *path;
39 caddr_t data;
40 struct nameidata *ndp;
41 struct proc *p;
42{
43 int error = 0;
44 u_int size;
45 struct fdescmount *fmp;
46 struct vnode *rvp;
47
e2e9adba
JSP
48 /*
49 * Update is a no-op
50 */
51 if (mp->mnt_flag & MNT_UPDATE)
52 return (EOPNOTSUPP);
53
01936f59 54 error = fdesc_allocvp(Froot, FD_ROOT, mp, &rvp);
e2e9adba
JSP
55 if (error)
56 return (error);
57
58 MALLOC(fmp, struct fdescmount *, sizeof(struct fdescmount),
59 M_UFSMNT, M_WAITOK); /* XXX */
60 rvp->v_type = VDIR;
61 rvp->v_flag |= VROOT;
e2e9adba 62 fmp->f_root = rvp;
b006c30c
JSP
63 /* XXX -- don't mark as local to work around fts() problems */
64 /*mp->mnt_flag |= MNT_LOCAL;*/
e2e9adba 65 mp->mnt_data = (qaddr_t) fmp;
0d540f6f 66 vfs_getnewfsid(mp);
e2e9adba
JSP
67
68 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
69 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
70 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
71 bcopy("fdesc", mp->mnt_stat.f_mntfromname, sizeof("fdesc"));
e2e9adba
JSP
72 return (0);
73}
74
43ec9518 75int
e2e9adba
JSP
76fdesc_start(mp, flags, p)
77 struct mount *mp;
78 int flags;
79 struct proc *p;
80{
81 return (0);
82}
83
43ec9518 84int
e2e9adba
JSP
85fdesc_unmount(mp, mntflags, p)
86 struct mount *mp;
87 int mntflags;
88 struct proc *p;
89{
90 int error;
91 int flags = 0;
e2e9adba
JSP
92 struct vnode *rootvp = VFSTOFDESC(mp)->f_root;
93
6902a390 94 if (mntflags & MNT_FORCE)
e2e9adba 95 flags |= FORCECLOSE;
e2e9adba
JSP
96
97 /*
98 * Clear out buffer cache. I don't think we
99 * ever get anything cached at this level at the
100 * moment, but who knows...
101 */
e2e9adba
JSP
102 if (rootvp->v_usecount > 1)
103 return (EBUSY);
e2e9adba
JSP
104 if (error = vflush(mp, rootvp, flags))
105 return (error);
106
e2e9adba
JSP
107 /*
108 * Release reference on underlying root vnode
109 */
110 vrele(rootvp);
111 /*
112 * And blow it away for future re-use
113 */
7f7fe314 114 VOP_REVOKE(rootvp, 0);
e2e9adba
JSP
115 /*
116 * Finally, throw away the fdescmount structure
117 */
118 free(mp->mnt_data, M_UFSMNT); /* XXX */
119 mp->mnt_data = 0;
43ec9518
JSP
120
121 return (0);
e2e9adba
JSP
122}
123
43ec9518 124int
e2e9adba
JSP
125fdesc_root(mp, vpp)
126 struct mount *mp;
127 struct vnode **vpp;
128{
e2e9adba 129 struct vnode *vp;
e2e9adba 130
e2e9adba
JSP
131 /*
132 * Return locked reference to root.
133 */
e2e9adba 134 vp = VFSTOFDESC(mp)->f_root;
e2e9adba 135 VREF(vp);
e2e9adba 136 VOP_LOCK(vp);
e2e9adba 137 *vpp = vp;
e2e9adba
JSP
138 return (0);
139}
140
43ec9518 141int
e2e9adba
JSP
142fdesc_statfs(mp, sbp, p)
143 struct mount *mp;
144 struct statfs *sbp;
145 struct proc *p;
146{
147 struct filedesc *fdp;
148 int lim;
149 int i;
150 int last;
151 int freefd;
152
e2e9adba
JSP
153 /*
154 * Compute number of free file descriptors.
155 * [ Strange results will ensue if the open file
156 * limit is ever reduced below the current number
157 * of open files... ]
158 */
0c2891f2 159 lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
e2e9adba
JSP
160 fdp = p->p_fd;
161 last = min(fdp->fd_nfiles, lim);
162 freefd = 0;
163 for (i = fdp->fd_freefile; i < last; i++)
164 if (fdp->fd_ofiles[i] == NULL)
165 freefd++;
166
167 /*
168 * Adjust for the fact that the fdesc array may not
169 * have been fully allocated yet.
170 */
171 if (fdp->fd_nfiles < lim)
172 freefd += (lim - fdp->fd_nfiles);
173
e2e9adba
JSP
174 sbp->f_flags = 0;
175 sbp->f_bsize = DEV_BSIZE;
176 sbp->f_iosize = DEV_BSIZE;
177 sbp->f_blocks = 2; /* 1K to keep df happy */
178 sbp->f_bfree = 0;
179 sbp->f_bavail = 0;
180 sbp->f_files = lim + 1; /* Allow for "." */
181 sbp->f_ffree = freefd; /* See comments above */
182 if (sbp != &mp->mnt_stat) {
0d540f6f 183 sbp->f_type = mp->mnt_vfc->vfc_typenum;
e2e9adba
JSP
184 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
185 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
186 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
187 }
188 return (0);
189}
190
43ec9518 191int
e2e9adba
JSP
192fdesc_sync(mp, waitfor)
193 struct mount *mp;
194 int waitfor;
195{
43ec9518 196
e2e9adba
JSP
197 return (0);
198}
199
cc7f3b61
KM
200#define fdesc_fhtovp ((int (*) __P((struct mount *, struct fid *, \
201 struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
202#define fdesc_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
203 struct proc *)))eopnotsupp)
204#define fdesc_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
205 size_t, struct proc *)))eopnotsupp)
206#define fdesc_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
207 eopnotsupp)
208#define fdesc_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
209
e2e9adba
JSP
210struct vfsops fdesc_vfsops = {
211 fdesc_mount,
212 fdesc_start,
213 fdesc_unmount,
214 fdesc_root,
215 fdesc_quotactl,
216 fdesc_statfs,
217 fdesc_sync,
159e7bde 218 fdesc_vget,
e2e9adba
JSP
219 fdesc_fhtovp,
220 fdesc_vptofh,
221 fdesc_init,
0d540f6f 222 fdesc_sysctl,
e2e9adba 223};