]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/nullfs/null_vfsops.c
ffcaa3d810e8969cbb589e4fe9e12e397ca8cbce
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
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 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
60 * @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
65 * (See null_vnops.c for a description of what this does.)
68 #include <sys/param.h>
69 #include <sys/systm.h>
72 #include <sys/types.h>
73 #include <sys/vnode.h>
74 #include <sys/mount.h>
75 #include <sys/namei.h>
76 #include <sys/malloc.h>
77 #include <miscfs/nullfs/null.h>
83 nullfs_mount(mp
, path
, data
, ndp
, p
)
87 struct nameidata
*ndp
;
91 struct null_args args
;
92 struct vnode
*lowerrootvp
, *vp
;
93 struct vnode
*nullm_rootvp
;
94 struct null_mount
*xmp
;
97 #ifdef NULLFS_DIAGNOSTIC
98 printf("nullfs_mount(mp = %x)\n", mp
);
104 if (mp
->mnt_flag
& MNT_UPDATE
) {
106 /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
112 if (error
= copyin(data
, (caddr_t
)&args
, sizeof(struct null_args
)))
118 NDINIT(ndp
, LOOKUP
, FOLLOW
|WANTPARENT
|LOCKLEAF
,
119 UIO_USERSPACE
, args
.target
, p
);
120 if (error
= namei(ndp
))
124 * Sanity check on lower vnode
126 lowerrootvp
= ndp
->ni_vp
;
131 xmp
= (struct null_mount
*) _MALLOC(sizeof(struct null_mount
),
132 M_UFSMNT
, M_WAITOK
); /* XXX */
135 * Save reference to underlying FS
137 xmp
->nullm_vfs
= lowerrootvp
->v_mount
;
140 * Save reference. Each mount also holds
141 * a reference on the root vnode.
143 error
= null_node_create(mp
, lowerrootvp
, &vp
);
145 * Unlock the node (either the lower or the alias)
147 VOP_UNLOCK(vp
, 0, p
);
149 * Make sure the node alias worked
153 FREE(xmp
, M_UFSMNT
); /* XXX */
158 * Keep a held reference to the root vnode.
159 * It is vrele'd in nullfs_unmount.
162 nullm_rootvp
->v_flag
|= VROOT
;
163 xmp
->nullm_rootvp
= nullm_rootvp
;
164 if (NULLVPTOLOWERVP(nullm_rootvp
)->v_mount
->mnt_flag
& MNT_LOCAL
)
165 mp
->mnt_flag
|= MNT_LOCAL
;
166 mp
->mnt_data
= (qaddr_t
) xmp
;
169 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
170 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
171 (void) copyinstr(args
.target
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1,
173 bzero(mp
->mnt_stat
.f_mntfromname
+ size
, MNAMELEN
- size
);
174 #ifdef NULLFS_DIAGNOSTIC
175 printf("nullfs_mount: lower %s, alias at %s\n",
176 mp
->mnt_stat
.f_mntfromname
, mp
->mnt_stat
.f_mntonname
);
182 * VFS start. Nothing needed here - the start routine
183 * on the underlying filesystem will have been called
184 * when that filesystem was mounted.
187 nullfs_start(mp
, flags
, p
)
193 /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
197 * Free reference to null layer
200 nullfs_unmount(mp
, mntflags
, p
)
205 struct vnode
*nullm_rootvp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
209 #ifdef NULLFS_DIAGNOSTIC
210 printf("nullfs_unmount(mp = %x)\n", mp
);
213 if (mntflags
& MNT_FORCE
)
217 * Clear out buffer cache. I don't think we
218 * ever get anything cached at this level at the
219 * moment, but who knows...
223 if (mntinvalbuf(mp
, 1))
226 if (nullm_rootvp
->v_usecount
> 1)
228 if (error
= vflush(mp
, nullm_rootvp
, flags
))
231 #ifdef NULLFS_DIAGNOSTIC
232 vprint("alias root of lower", nullm_rootvp
);
235 * Release reference on underlying root vnode
239 * And blow it away for future re-use
243 * Finally, throw away the null_mount structure
245 FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
255 struct proc
*p
= curproc
; /* XXX */
258 #ifdef NULLFS_DIAGNOSTIC
259 printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp
,
260 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
261 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
266 * Return locked reference to root.
268 vp
= MOUNTTONULLMOUNT(mp
)->nullm_rootvp
;
270 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
276 nullfs_quotactl(mp
, cmd
, uid
, arg
, p
)
283 return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, cmd
, uid
, arg
, p
);
287 nullfs_statfs(mp
, sbp
, p
)
295 #ifdef NULLFS_DIAGNOSTIC
296 printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp
,
297 MOUNTTONULLMOUNT(mp
)->nullm_rootvp
,
298 NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp
)->nullm_rootvp
)
302 bzero(&mstat
, sizeof(mstat
));
304 error
= VFS_STATFS(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, &mstat
, p
);
308 /* now copy across the "interesting" information and fake the rest */
309 sbp
->f_type
= mstat
.f_type
;
310 sbp
->f_flags
= mstat
.f_flags
;
311 sbp
->f_bsize
= mstat
.f_bsize
;
312 sbp
->f_iosize
= mstat
.f_iosize
;
313 sbp
->f_blocks
= mstat
.f_blocks
;
314 sbp
->f_bfree
= mstat
.f_bfree
;
315 sbp
->f_bavail
= mstat
.f_bavail
;
316 sbp
->f_files
= mstat
.f_files
;
317 sbp
->f_ffree
= mstat
.f_ffree
;
318 if (sbp
!= &mp
->mnt_stat
) {
319 bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
320 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
321 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
327 nullfs_sync(mp
, waitfor
, cred
, p
)
334 * XXX - Assumes no data cached at null layer.
340 nullfs_vget(mp
, ino
, vpp
)
346 return VFS_VGET(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, ino
, vpp
);
350 nullfs_fhtovp(mp
, fidp
, nam
, vpp
, exflagsp
, credanonp
)
356 struct ucred
**credanonp
;
359 return VFS_FHTOVP(MOUNTTONULLMOUNT(mp
)->nullm_vfs
, fidp
, nam
, vpp
, exflagsp
,credanonp
);
363 nullfs_vptofh(vp
, fhp
)
367 return VFS_VPTOFH(NULLVPTOLOWERVP(vp
), fhp
);
370 int nullfs_init
__P((struct vfsconf
*));
372 #define nullfs_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
373 size_t, struct proc *)))eopnotsupp)
375 struct vfsops null_vfsops
= {