2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1992, 1993
33 * The Regents of the University of California. All rights reserved.
35 * This code is derived from software donated to Berkeley by
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
68 * @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
73 * (See null_vnops.c for a description of what this does.)
76 #include <sys/param.h>
77 #include <sys/systm.h>
79 #include <sys/kauth.h>
81 #include <sys/types.h>
82 #include <sys/vnode.h>
83 #include <sys/mount_internal.h>
84 #include <sys/namei.h>
85 #include <sys/malloc.h>
86 #include <miscfs/nullfs/null.h>
92 nullfs_mount(mp
, devvp
, data
, context
)
96 vfs_context_t context
;
99 struct user_null_args args
;
100 struct vnode
*lowerrootvp
, *vp
;
101 struct vnode
*nullm_rootvp
;
102 struct null_mount
*xmp
;
105 #ifdef NULLFS_DIAGNOSTIC
106 printf("nullfs_mount(mp = %x)\n", mp
);
112 if (mp
->mnt_flag
& MNT_UPDATE
) {
114 /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, devvp, data, p);*/
120 if (vfs_context_is64bit(context
)) {
121 error
= copyin(data
, (caddr_t
)&args
, sizeof (args
));
124 struct null_args temp
;
125 error
= copyin(data
, (caddr_t
)&temp
, sizeof (temp
));
126 args
.target
= CAST_USER_ADDR_T(temp
.target
);
134 NDINIT(ndp
, LOOKUP
, FOLLOW
|WANTPARENT
|LOCKLEAF
,
135 UIO_USERSPACE
, args
.target
, context
);
136 if (error
= namei(ndp
))
140 * Sanity check on lower vnode
142 lowerrootvp
= ndp
->ni_vp
;
144 vnode_put(ndp
->ni_dvp
);
147 xmp
= (struct null_mount
*) _MALLOC(sizeof(struct null_mount
),
148 M_UFSMNT
, M_WAITOK
); /* XXX */
151 * Save reference to underlying FS
153 xmp
->nullm_vfs
= lowerrootvp
->v_mount
;
156 * Save reference. Each mount also holds
157 * a reference on the root vnode.
159 error
= null_node_create(mp
, lowerrootvp
, &vp
);
161 * Make sure the node alias worked
164 vnode_put(lowerrootvp
);
165 FREE(xmp
, M_UFSMNT
); /* XXX */
170 * Keep a held reference to the root vnode.
171 * It is vnode_put'd in nullfs_unmount.
174 nullm_rootvp
->v_flag
|= VROOT
;
175 xmp
->nullm_rootvp
= nullm_rootvp
;
176 if (NULLVPTOLOWERVP(nullm_rootvp
)->v_mount
->mnt_flag
& MNT_LOCAL
)
177 mp
->mnt_flag
|= MNT_LOCAL
;
178 mp
->mnt_data
= (qaddr_t
) xmp
;
181 (void) copyinstr(args
.target
, mp
->mnt_vfsstat
.f_mntfromname
, MAXPATHLEN
- 1,
183 bzero(mp
->mnt_vfsstat
.f_mntfromname
+ size
, MNAMELEN
- size
);
184 #ifdef NULLFS_DIAGNOSTIC
185 printf("nullfs_mount: lower %s, alias at %s\n",
186 mp
->mnt_vfsstat
.f_mntfromname
, mp
->mnt_vfsstat
.f_mntonname
);
192 * VFS start. Nothing needed here - the start routine
193 * on the underlying filesystem will have been called
194 * when that filesystem was mounted.
197 nullfs_start(mp
, flags
, context
)
200 vfs_context_t context
;
203 /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, context); */
207 * Free reference to null layer
210 nullfs_unmount(mp
, mntflags
, context
)
213 vfs_context_t context
;
215 struct vnode
*nullm_rootvp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
220 #ifdef NULLFS_DIAGNOSTIC
221 printf("nullfs_unmount(mp = %x)\n", mp
);
224 if (mntflags
& MNT_FORCE
) {
229 if ( (nullm_rootvp
->v_usecount
> 1) && !force
)
231 if ( (error
= vflush(mp
, nullm_rootvp
, flags
)) && !force
)
234 #ifdef NULLFS_DIAGNOSTIC
235 vprint("alias root of lower", nullm_rootvp
);
238 * Release reference on underlying root vnode
240 vnode_put(nullm_rootvp
);
242 * And blow it away for future re-use
244 vnode_reclaim(nullm_rootvp
);
246 * Finally, throw away the null_mount structure
248 FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
254 nullfs_root(mp
, vpp
, context
)
257 vfs_context_t context
;
259 struct proc
*p
= curproc
; /* XXX */
262 #ifdef NULLFS_DIAGNOSTIC
263 printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp
,
264 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
265 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
270 * Return locked reference to root.
272 vp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
279 nullfs_quotactl(mp
, cmd
, uid
, datap
, context
)
284 vfs_context_t context
;
286 return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, cmd
, uid
, datap
, context
);
290 nullfs_statfs(mp
, sbp
, context
)
292 struct vfsstatfs
*sbp
;
293 vfs_context_t context
;
296 struct vfsstatfs mstat
;
298 #ifdef NULLFS_DIAGNOSTIC
299 printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp
,
300 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
301 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
305 bzero(&mstat
, sizeof(mstat
));
307 error
= VFS_STATFS(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, &mstat
, context
);
311 /* now copy across the "interesting" information and fake the rest */
312 //sbp->f_type = mstat.f_type;
313 sbp
->f_flags
= mstat
.f_flags
;
314 sbp
->f_bsize
= mstat
.f_bsize
;
315 sbp
->f_iosize
= mstat
.f_iosize
;
316 sbp
->f_blocks
= mstat
.f_blocks
;
317 sbp
->f_bfree
= mstat
.f_bfree
;
318 sbp
->f_bavail
= mstat
.f_bavail
;
319 sbp
->f_files
= mstat
.f_files
;
320 sbp
->f_ffree
= mstat
.f_ffree
;
325 nullfs_sync(__unused
struct mount
*mp
, __unused
int waitfor
,
326 __unused kauth_cred_t cred
, __unused vfs_context_t context
)
329 * XXX - Assumes no data cached at null layer.
335 nullfs_vget(mp
, ino
, vpp
, context
)
339 vfs_context_t context
;
342 return VFS_VGET(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, ino
, vpp
, context
);
346 nullfs_fhtovp(mp
, fhlen
, fhp
, vpp
, context
)
351 vfs_context_t context
;
354 return VFS_FHTOVP(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, fhlen
, fhp
, vpp
, context
);
358 nullfs_vptofh(vp
, fhlenp
, fhp
, context
)
362 vfs_context_t context
;
364 return VFS_VPTOFH(NULLVPTOLOWERVP(vp
), fhlenp
, fhp
, context
);
367 int nullfs_init (struct vfsconf
*);
369 #define nullfs_sysctl (int (*) (int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, proc_t))eopnotsupp
371 struct vfsops null_vfsops
= {