]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/kernfs/kernfs_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 /* $NetBSD: kernfs_vfsops.c,v 1.23 1995/03/09 12:05:52 mycroft Exp $ */
25 * Copyright (c) 1992, 1993
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software donated to Berkeley by
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * @(#)kernfs_vfsops.c 8.5 (Berkeley) 6/15/94
63 * Kernel params Filesystem
66 #include <sys/param.h>
67 #include <sys/systm.h>
69 #include <sys/types.h>
71 #include <sys/vnode.h>
72 #include <sys/mount.h>
73 #include <sys/namei.h>
74 #include <sys/malloc.h>
76 #include <miscfs/specfs/specdev.h>
77 #include <miscfs/kernfs/kernfs.h>
79 dev_t rrootdev
= NODEV
;
93 /* Already did it once. */
100 for (cmaj
= 0; cmaj
< nchrdev
; cmaj
++) {
101 rrootdev
= makedev(cmaj
, minor(rootdev
));
102 if (chrtoblk(rrootdev
) == rootdev
)
106 printf("kernfs_get_rrootdev: no raw root device\n");
110 * Mount the Kernel params filesystem
112 kernfs_mount(mp
, path
, data
, ndp
, p
)
116 struct nameidata
*ndp
;
121 struct kernfs_mount
*fmp
;
124 #ifdef KERNFS_DIAGNOSTIC
125 printf("kernfs_mount(mp = %x)\n", mp
);
131 if (mp
->mnt_flag
& MNT_UPDATE
)
134 MALLOC(fmp
, struct kernfs_mount
*, sizeof(struct kernfs_mount
),
135 M_MISCFSMNT
, M_WAITOK
);
136 if (error
= getnewvnode(VT_KERNFS
, mp
, kernfs_vnodeop_p
, &rvp
)) {
137 FREE(fmp
, M_MISCFSMNT
);
142 rvp
->v_flag
|= VROOT
;
143 #ifdef KERNFS_DIAGNOSTIC
144 printf("kernfs_mount: root vp = %x\n", rvp
);
147 mp
->mnt_flag
|= MNT_LOCAL
;
148 mp
->mnt_data
= (qaddr_t
)fmp
;
149 getnewfsid(mp
, makefstype(MOUNT_KERNFS
));
151 (void) copyinstr(path
, mp
->mnt_stat
.f_mntonname
, MNAMELEN
- 1, &size
);
152 bzero(mp
->mnt_stat
.f_mntonname
+ size
, MNAMELEN
- size
);
153 bzero(mp
->mnt_stat
.f_mntfromname
, MNAMELEN
);
154 bcopy("kernfs", mp
->mnt_stat
.f_mntfromname
, sizeof("kernfs"));
155 #ifdef KERNFS_DIAGNOSTIC
156 printf("kernfs_mount: at %s\n", mp
->mnt_stat
.f_mntonname
);
159 kernfs_get_rrootdev();
163 kernfs_start(mp
, flags
, p
)
172 kernfs_unmount(mp
, mntflags
, p
)
180 struct vnode
*rootvp
= VFSTOKERNFS(mp
)->kf_root
;
182 #ifdef KERNFS_DIAGNOSTIC
183 printf("kernfs_unmount(mp = %x)\n", mp
);
186 if (mntflags
& MNT_FORCE
) {
187 /* kernfs can never be rootfs so don't check for it */
194 * Clear out buffer cache. I don't think we
195 * ever get anything cached at this level at the
196 * moment, but who knows...
198 if (rootvp
->v_usecount
> 1)
200 #ifdef KERNFS_DIAGNOSTIC
201 printf("kernfs_unmount: calling vflush\n");
203 if (error
= vflush(mp
, rootvp
, flags
))
206 #ifdef KERNFS_DIAGNOSTIC
207 vprint("kernfs root", rootvp
);
210 * Clean out the old root vnode for reuse.
215 * Finally, throw away the kernfs_mount structure
217 free(mp
->mnt_data
, M_MISCFSMNT
);
228 #ifdef KERNFS_DIAGNOSTIC
229 printf("kernfs_root(mp = %x)\n", mp
);
233 * Return locked reference to root.
235 vp
= VFSTOKERNFS(mp
)->kf_root
;
242 kernfs_quotactl(mp
, cmd
, uid
, arg
, p
)
253 kernfs_statfs(mp
, sbp
, p
)
259 #ifdef KERNFS_DIAGNOSTIC
260 printf("kernfs_statfs(mp = %x)\n", mp
);
268 sbp
->f_bsize
= DEV_BSIZE
;
269 sbp
->f_iosize
= DEV_BSIZE
;
270 sbp
->f_blocks
= 2; /* 1K to keep df happy */
275 if (sbp
!= &mp
->mnt_stat
) {
276 bcopy(&mp
->mnt_stat
.f_fsid
, &sbp
->f_fsid
, sizeof(sbp
->f_fsid
));
277 bcopy(mp
->mnt_stat
.f_mntonname
, sbp
->f_mntonname
, MNAMELEN
);
278 bcopy(mp
->mnt_stat
.f_mntfromname
, sbp
->f_mntfromname
, MNAMELEN
);
280 strncpy(sbp
->f_fstypename
, mp
->mnt_op
->vfs_name
, MFSNAMELEN
);
281 sbp
->f_fstypename
[MFSNAMELEN
] = '\0';
285 kernfs_sync(mp
, waitfor
)
294 * Kernfs flat namespace lookup.
295 * Currently unsupported.
297 kernfs_vget(mp
, ino
, vpp
)
307 kernfs_fhtovp(mp
, fhp
, setgen
, vpp
)
317 kernfs_vptofh(vp
, fhp
)
325 struct vfsops kernfs_vfsops
= {