]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/fdesc/fdesc_vfsops.c
1d26b20e9735fc618d8539bb47719e4975617576
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1992, 1993, 1995
28 * The Regents of the University of California. All rights reserved.
30 * This code is derived from software donated to Berkeley by
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95
69 #include <sys/param.h>
70 #include <sys/systm.h>
72 #include <sys/types.h>
74 #include <sys/resourcevar.h>
75 #include <sys/filedesc.h>
76 #include <sys/vnode.h>
77 #include <sys/mount.h>
78 #include <sys/namei.h>
79 #include <sys/malloc.h>
80 #include <miscfs/fdesc/fdesc.h>
83 * Mount the per-process file descriptors (/dev/fd)
86 fdesc_mount(mp
, path
, data
, ndp
, p
)
90 struct nameidata
*ndp
;
95 struct fdescmount
*fmp
;
101 if (mp
->mnt_flag
& MNT_UPDATE
)
104 error
= fdesc_allocvp(Froot
, FD_ROOT
, mp
, &rvp
);
108 MALLOC(fmp
, struct fdescmount
*, sizeof(struct fdescmount
),
109 M_UFSMNT
, M_WAITOK
); /* XXX */
111 rvp
->v_flag
|= VROOT
;
113 /* XXX -- don't mark as local to work around fts() problems */
114 /*mp->mnt_flag |= MNT_LOCAL;*/
115 mp
->mnt_data
= (qaddr_t
) fmp
;
118 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
119 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
120 bzero(mp
->mnt_stat
.f_mntfromname
, MNAMELEN
);
121 bcopy("fdesc", mp
->mnt_stat
.f_mntfromname
, sizeof("fdesc"));
126 fdesc_start(mp
, flags
, p
)
135 fdesc_unmount(mp
, mntflags
, p
)
143 struct vnode
*rootvp
= VFSTOFDESC(mp
)->f_root
;
145 if (mntflags
& MNT_FORCE
) {
150 if ( (rootvp
->v_usecount
> 1) && !force
)
152 if ( (error
= vflush(mp
, rootvp
, flags
)) && !force
)
156 * Release reference on underlying root vnode
160 * And blow it away for future re-use
164 * Finally, throw away the fdescmount structure
166 _FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
177 struct proc
*p
= current_proc(); /* XXX */
181 * Return locked reference to root.
183 vp
= VFSTOFDESC(mp
)->f_root
;
185 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
191 fdesc_statfs(mp
, sbp
, p
)
196 struct filedesc
*fdp
;
203 * Compute number of free file descriptors.
204 * [ Strange results will ensue if the open file
205 * limit is ever reduced below the current number
208 lim
= p
->p_rlimit
[RLIMIT_NOFILE
].rlim_cur
;
210 last
= min(fdp
->fd_nfiles
, lim
);
212 for (i
= fdp
->fd_freefile
; i
< last
; i
++)
213 if (fdp
->fd_ofiles
[i
] == NULL
&&
214 !(fdp
->fd_ofileflags
[i
] & UF_RESERVED
))
218 * Adjust for the fact that the fdesc array may not
219 * have been fully allocated yet.
221 if (fdp
->fd_nfiles
< lim
)
222 freefd
+= (lim
- fdp
->fd_nfiles
);
225 sbp
->f_bsize
= DEV_BSIZE
;
226 sbp
->f_iosize
= DEV_BSIZE
;
227 sbp
->f_blocks
= 2; /* 1K to keep df happy */
230 sbp
->f_files
= lim
+ 1; /* Allow for "." */
231 sbp
->f_ffree
= freefd
; /* See comments above */
232 if (sbp
!= &mp
->mnt_stat
) {
233 sbp
->f_type
= mp
->mnt_vfc
->vfc_typenum
;
234 bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
235 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
236 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
242 fdesc_sync(mp
, waitfor
)
250 #define fdesc_fhtovp ((int (*) __P((struct mount *, struct fid *, \
251 struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
252 #define fdesc_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
253 struct proc *)))eopnotsupp)
254 #define fdesc_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
255 size_t, struct proc *)))eopnotsupp)
256 #define fdesc_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
258 #define fdesc_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
260 struct vfsops fdesc_vfsops
= {