]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/fdesc/fdesc_vfsops.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1992, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
27 * This code is derived from software donated to Berkeley by
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)fdesc_vfsops.c 8.10 (Berkeley) 5/14/95
66 #include <sys/param.h>
67 #include <sys/systm.h>
69 #include <sys/types.h>
71 #include <sys/resourcevar.h>
72 #include <sys/filedesc.h>
73 #include <sys/vnode.h>
74 #include <sys/mount.h>
75 #include <sys/namei.h>
76 #include <sys/malloc.h>
77 #include <miscfs/fdesc/fdesc.h>
80 * Mount the per-process file descriptors (/dev/fd)
83 fdesc_mount(mp
, path
, data
, ndp
, p
)
87 struct nameidata
*ndp
;
92 struct fdescmount
*fmp
;
98 if (mp
->mnt_flag
& MNT_UPDATE
)
101 error
= fdesc_allocvp(Froot
, FD_ROOT
, mp
, &rvp
);
105 MALLOC(fmp
, struct fdescmount
*, sizeof(struct fdescmount
),
106 M_UFSMNT
, M_WAITOK
); /* XXX */
108 rvp
->v_flag
|= VROOT
;
110 /* XXX -- don't mark as local to work around fts() problems */
111 /*mp->mnt_flag |= MNT_LOCAL;*/
112 mp
->mnt_data
= (qaddr_t
) fmp
;
115 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
116 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
117 bzero(mp
->mnt_stat
.f_mntfromname
, MNAMELEN
);
118 bcopy("fdesc", mp
->mnt_stat
.f_mntfromname
, sizeof("fdesc"));
123 fdesc_start(mp
, flags
, p
)
132 fdesc_unmount(mp
, mntflags
, p
)
140 struct vnode
*rootvp
= VFSTOFDESC(mp
)->f_root
;
142 if (mntflags
& MNT_FORCE
) {
147 if ( (rootvp
->v_usecount
> 1) && !force
)
149 if ( (error
= vflush(mp
, rootvp
, flags
)) && !force
)
153 * Release reference on underlying root vnode
157 * And blow it away for future re-use
161 * Finally, throw away the fdescmount structure
163 _FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
174 struct proc
*p
= current_proc(); /* XXX */
178 * Return locked reference to root.
180 vp
= VFSTOFDESC(mp
)->f_root
;
182 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
188 fdesc_statfs(mp
, sbp
, p
)
193 struct filedesc
*fdp
;
200 * Compute number of free file descriptors.
201 * [ Strange results will ensue if the open file
202 * limit is ever reduced below the current number
205 lim
= p
->p_rlimit
[RLIMIT_NOFILE
].rlim_cur
;
207 last
= min(fdp
->fd_nfiles
, lim
);
209 for (i
= fdp
->fd_freefile
; i
< last
; i
++)
210 if (fdp
->fd_ofiles
[i
] == NULL
&&
211 !(fdp
->fd_ofileflags
[i
] & UF_RESERVED
))
215 * Adjust for the fact that the fdesc array may not
216 * have been fully allocated yet.
218 if (fdp
->fd_nfiles
< lim
)
219 freefd
+= (lim
- fdp
->fd_nfiles
);
222 sbp
->f_bsize
= DEV_BSIZE
;
223 sbp
->f_iosize
= DEV_BSIZE
;
224 sbp
->f_blocks
= 2; /* 1K to keep df happy */
227 sbp
->f_files
= lim
+ 1; /* Allow for "." */
228 sbp
->f_ffree
= freefd
; /* See comments above */
229 if (sbp
!= &mp
->mnt_stat
) {
230 sbp
->f_type
= mp
->mnt_vfc
->vfc_typenum
;
231 bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
232 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
233 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
239 fdesc_sync(mp
, waitfor
)
247 #define fdesc_fhtovp ((int (*) __P((struct mount *, struct fid *, \
248 struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
249 #define fdesc_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
250 struct proc *)))eopnotsupp)
251 #define fdesc_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
252 size_t, struct proc *)))eopnotsupp)
253 #define fdesc_vget ((int (*) __P((struct mount *, void *, struct vnode **))) \
255 #define fdesc_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
257 struct vfsops fdesc_vfsops
= {