]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/nullfs/null_vfsops.c
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
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 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
63 * @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
68 * (See null_vnops.c for a description of what this does.)
71 #include <sys/param.h>
72 #include <sys/systm.h>
75 #include <sys/types.h>
76 #include <sys/vnode.h>
77 #include <sys/mount.h>
78 #include <sys/namei.h>
79 #include <sys/malloc.h>
80 #include <miscfs/nullfs/null.h>
86 nullfs_mount(mp
, path
, data
, ndp
, p
)
90 struct nameidata
*ndp
;
94 struct null_args args
;
95 struct vnode
*lowerrootvp
, *vp
;
96 struct vnode
*nullm_rootvp
;
97 struct null_mount
*xmp
;
100 #ifdef NULLFS_DIAGNOSTIC
101 printf("nullfs_mount(mp = %x)\n", mp
);
107 if (mp
->mnt_flag
& MNT_UPDATE
) {
109 /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
115 if (error
= copyin(data
, (caddr_t
)&args
, sizeof(struct null_args
)))
121 NDINIT(ndp
, LOOKUP
, FOLLOW
|WANTPARENT
|LOCKLEAF
,
122 UIO_USERSPACE
, args
.target
, p
);
123 if (error
= namei(ndp
))
127 * Sanity check on lower vnode
129 lowerrootvp
= ndp
->ni_vp
;
134 xmp
= (struct null_mount
*) _MALLOC(sizeof(struct null_mount
),
135 M_UFSMNT
, M_WAITOK
); /* XXX */
138 * Save reference to underlying FS
140 xmp
->nullm_vfs
= lowerrootvp
->v_mount
;
143 * Save reference. Each mount also holds
144 * a reference on the root vnode.
146 error
= null_node_create(mp
, lowerrootvp
, &vp
);
148 * Unlock the node (either the lower or the alias)
150 VOP_UNLOCK(vp
, 0, p
);
152 * Make sure the node alias worked
156 FREE(xmp
, M_UFSMNT
); /* XXX */
161 * Keep a held reference to the root vnode.
162 * It is vrele'd in nullfs_unmount.
165 nullm_rootvp
->v_flag
|= VROOT
;
166 xmp
->nullm_rootvp
= nullm_rootvp
;
167 if (NULLVPTOLOWERVP(nullm_rootvp
)->v_mount
->mnt_flag
& MNT_LOCAL
)
168 mp
->mnt_flag
|= MNT_LOCAL
;
169 mp
->mnt_data
= (qaddr_t
) xmp
;
172 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
173 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
174 (void) copyinstr(args
.target
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
176 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
177 #ifdef NULLFS_DIAGNOSTIC
178 printf("nullfs_mount: lower %s, alias at %s\n",
179 mp
->mnt_stat
.f_mntfromname
, mp
->mnt_stat
.f_mntonname
);
185 * VFS start. Nothing needed here - the start routine
186 * on the underlying filesystem will have been called
187 * when that filesystem was mounted.
190 nullfs_start(mp
, flags
, p
)
196 /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
200 * Free reference to null layer
203 nullfs_unmount(mp
, mntflags
, p
)
208 struct vnode
*nullm_rootvp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
213 #ifdef NULLFS_DIAGNOSTIC
214 printf("nullfs_unmount(mp = %x)\n", mp
);
217 if (mntflags
& MNT_FORCE
) {
222 if ( (nullm_rootvp
->v_usecount
> 1) && !force
)
224 if ( (error
= vflush(mp
, nullm_rootvp
, flags
)) && !force
)
227 #ifdef NULLFS_DIAGNOSTIC
228 vprint("alias root of lower", nullm_rootvp
);
231 * Release reference on underlying root vnode
235 * And blow it away for future re-use
239 * Finally, throw away the null_mount structure
241 FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
251 struct proc
*p
= curproc
; /* XXX */
254 #ifdef NULLFS_DIAGNOSTIC
255 printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp
,
256 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
257 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
262 * Return locked reference to root.
264 vp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
266 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
272 nullfs_quotactl(mp
, cmd
, uid
, arg
, p
)
279 return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, cmd
, uid
, arg
, p
);
283 nullfs_statfs(mp
, sbp
, p
)
291 #ifdef NULLFS_DIAGNOSTIC
292 printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp
,
293 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
294 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
298 bzero(&mstat
, sizeof(mstat
));
300 error
= VFS_STATFS(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, &mstat
, p
);
304 /* now copy across the "interesting" information and fake the rest */
305 sbp
->f_type
= mstat
.f_type
;
306 sbp
->f_flags
= mstat
.f_flags
;
307 sbp
->f_bsize
= mstat
.f_bsize
;
308 sbp
->f_iosize
= mstat
.f_iosize
;
309 sbp
->f_blocks
= mstat
.f_blocks
;
310 sbp
->f_bfree
= mstat
.f_bfree
;
311 sbp
->f_bavail
= mstat
.f_bavail
;
312 sbp
->f_files
= mstat
.f_files
;
313 sbp
->f_ffree
= mstat
.f_ffree
;
314 if (sbp
!= &mp
->mnt_stat
) {
315 bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
316 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
317 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
323 nullfs_sync(mp
, waitfor
, cred
, p
)
330 * XXX - Assumes no data cached at null layer.
336 nullfs_vget(mp
, ino
, vpp
)
342 return VFS_VGET(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, ino
, vpp
);
346 nullfs_fhtovp(mp
, fidp
, nam
, vpp
, exflagsp
, credanonp
)
352 struct ucred
**credanonp
;
355 return VFS_FHTOVP(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, fidp
, nam
, vpp
, exflagsp
,credanonp
);
359 nullfs_vptofh(vp
, fhp
)
363 return VFS_VPTOFH(NULLVPTOLOWERVP(vp
), fhp
);
366 int nullfs_init
__P((struct vfsconf
*));
368 #define nullfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
369 size_t, struct proc *)))eopnotsupp)
371 struct vfsops null_vfsops
= {