2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1992, 1993
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software donated to Berkeley by
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
66 * @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
71 * (See null_vnops.c for a description of what this does.)
74 #include <sys/param.h>
75 #include <sys/systm.h>
77 #include <sys/kauth.h>
79 #include <sys/types.h>
80 #include <sys/vnode.h>
81 #include <sys/mount_internal.h>
82 #include <sys/namei.h>
83 #include <sys/malloc.h>
84 #include <miscfs/nullfs/null.h>
90 nullfs_mount(mp
, devvp
, data
, context
)
94 vfs_context_t context
;
97 struct user_null_args args
;
98 struct vnode
*lowerrootvp
, *vp
;
99 struct vnode
*nullm_rootvp
;
100 struct null_mount
*xmp
;
103 #ifdef NULLFS_DIAGNOSTIC
104 printf("nullfs_mount(mp = %x)\n", mp
);
110 if (mp
->mnt_flag
& MNT_UPDATE
) {
112 /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, devvp, data, p);*/
118 if (vfs_context_is64bit(context
)) {
119 error
= copyin(data
, (caddr_t
)&args
, sizeof (args
));
122 struct null_args temp
;
123 error
= copyin(data
, (caddr_t
)&temp
, sizeof (temp
));
124 args
.target
= CAST_USER_ADDR_T(temp
.target
);
132 NDINIT(ndp
, LOOKUP
, FOLLOW
|WANTPARENT
|LOCKLEAF
,
133 UIO_USERSPACE
, args
.target
, context
);
134 if (error
= namei(ndp
))
138 * Sanity check on lower vnode
140 lowerrootvp
= ndp
->ni_vp
;
142 vnode_put(ndp
->ni_dvp
);
145 xmp
= (struct null_mount
*) _MALLOC(sizeof(struct null_mount
),
146 M_UFSMNT
, M_WAITOK
); /* XXX */
149 * Save reference to underlying FS
151 xmp
->nullm_vfs
= lowerrootvp
->v_mount
;
154 * Save reference. Each mount also holds
155 * a reference on the root vnode.
157 error
= null_node_create(mp
, lowerrootvp
, &vp
);
159 * Make sure the node alias worked
162 vnode_put(lowerrootvp
);
163 FREE(xmp
, M_UFSMNT
); /* XXX */
168 * Keep a held reference to the root vnode.
169 * It is vnode_put'd in nullfs_unmount.
172 nullm_rootvp
->v_flag
|= VROOT
;
173 xmp
->nullm_rootvp
= nullm_rootvp
;
174 if (NULLVPTOLOWERVP(nullm_rootvp
)->v_mount
->mnt_flag
& MNT_LOCAL
)
175 mp
->mnt_flag
|= MNT_LOCAL
;
176 mp
->mnt_data
= (qaddr_t
) xmp
;
179 (void) copyinstr(args
.target
, mp
->mnt_vfsstat
.f_mntfromname
, MAXPATHLEN
- 1,
181 bzero(mp
->mnt_vfsstat
.f_mntfromname
+ size
, MNAMELEN
- size
);
182 #ifdef NULLFS_DIAGNOSTIC
183 printf("nullfs_mount: lower %s, alias at %s\n",
184 mp
->mnt_vfsstat
.f_mntfromname
, mp
->mnt_vfsstat
.f_mntonname
);
190 * VFS start. Nothing needed here - the start routine
191 * on the underlying filesystem will have been called
192 * when that filesystem was mounted.
195 nullfs_start(mp
, flags
, context
)
198 vfs_context_t context
;
201 /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, context); */
205 * Free reference to null layer
208 nullfs_unmount(mp
, mntflags
, context
)
211 vfs_context_t context
;
213 struct vnode
*nullm_rootvp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
218 #ifdef NULLFS_DIAGNOSTIC
219 printf("nullfs_unmount(mp = %x)\n", mp
);
222 if (mntflags
& MNT_FORCE
) {
227 if ( (nullm_rootvp
->v_usecount
> 1) && !force
)
229 if ( (error
= vflush(mp
, nullm_rootvp
, flags
)) && !force
)
232 #ifdef NULLFS_DIAGNOSTIC
233 vprint("alias root of lower", nullm_rootvp
);
236 * Release reference on underlying root vnode
238 vnode_put(nullm_rootvp
);
240 * And blow it away for future re-use
242 vnode_reclaim(nullm_rootvp
);
244 * Finally, throw away the null_mount structure
246 FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
252 nullfs_root(mp
, vpp
, context
)
255 vfs_context_t context
;
257 struct proc
*p
= curproc
; /* XXX */
260 #ifdef NULLFS_DIAGNOSTIC
261 printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp
,
262 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
263 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
268 * Return locked reference to root.
270 vp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
277 nullfs_quotactl(mp
, cmd
, uid
, datap
, context
)
282 vfs_context_t context
;
284 return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, cmd
, uid
, datap
, context
);
288 nullfs_statfs(mp
, sbp
, context
)
290 struct vfsstatfs
*sbp
;
291 vfs_context_t context
;
294 struct vfsstatfs mstat
;
296 #ifdef NULLFS_DIAGNOSTIC
297 printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp
,
298 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
299 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
303 bzero(&mstat
, sizeof(mstat
));
305 error
= VFS_STATFS(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, &mstat
, context
);
309 /* now copy across the "interesting" information and fake the rest */
310 //sbp->f_type = mstat.f_type;
311 sbp
->f_flags
= mstat
.f_flags
;
312 sbp
->f_bsize
= mstat
.f_bsize
;
313 sbp
->f_iosize
= mstat
.f_iosize
;
314 sbp
->f_blocks
= mstat
.f_blocks
;
315 sbp
->f_bfree
= mstat
.f_bfree
;
316 sbp
->f_bavail
= mstat
.f_bavail
;
317 sbp
->f_files
= mstat
.f_files
;
318 sbp
->f_ffree
= mstat
.f_ffree
;
323 nullfs_sync(__unused
struct mount
*mp
, __unused
int waitfor
,
324 __unused kauth_cred_t cred
, __unused vfs_context_t context
)
327 * XXX - Assumes no data cached at null layer.
333 nullfs_vget(mp
, ino
, vpp
, context
)
337 vfs_context_t context
;
340 return VFS_VGET(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, ino
, vpp
, context
);
344 nullfs_fhtovp(mp
, fhlen
, fhp
, vpp
, context
)
349 vfs_context_t context
;
352 return VFS_FHTOVP(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, fhlen
, fhp
, vpp
, context
);
356 nullfs_vptofh(vp
, fhlenp
, fhp
, context
)
360 vfs_context_t context
;
362 return VFS_VPTOFH(NULLVPTOLOWERVP(vp
), fhlenp
, fhp
, context
);
365 int nullfs_init (struct vfsconf
*);
367 #define nullfs_sysctl (int (*) (int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, proc_t))eopnotsupp
369 struct vfsops null_vfsops
= {