2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung (at) gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/vnode.h>
41 #include <sys/mount.h>
42 #include <sys/namecache.h>
43 #include <sys/nlookup.h>
45 #include <sys/thread2.h>
46 #include <sys/devfs.h>
48 struct mount
*synth_mp
;
49 struct vnode
*synth_vp
;
50 static int synth_inited
= 0;
51 static int synth_synced
= 0;
54 getsynthvnode(const char *devname
)
58 struct nlookupdata nd
;
59 struct ucred
*cred
= proc0
.p_ucred
;
62 KKASSERT(synth_inited
!= 0);
63 KKASSERT(synth_mp
!= NULL
);
64 KKASSERT(synth_mp
->mnt_ncmountpt
.mount
!= NULL
);
66 /* Sync devfs/disks twice to make sure all devices are around */
67 if (synth_synced
< 2) {
72 error
= nlookup_init_root(&nd
, devname
, UIO_SYSSPACE
, NLC_FOLLOW
,
73 cred
, &synth_mp
->mnt_ncmountpt
,
74 &synth_mp
->mnt_ncmountpt
);
77 panic("synth: nlookup_init_root failed with %d", error
);
83 if (nd
.nl_nch
.ncp
->nc_vp
== NULL
) {
84 kprintf("synth: nc_vp == NULL\n");
88 cache_zero(&nd
.nl_nch
);
93 if (error
!= ENOENT
) { /* Don't bother warning about ENOENT */
94 kprintf("synth: nlookup of %s failed with %d\n",
101 /* A VX locked & refd vnode must be returned. */
102 error
= vget(vp
, LK_EXCLUSIVE
);
106 kprintf("synth: could not vget vnode\n");
114 synthinit(void *arg __unused
)
118 if ((error
= vfs_rootmountalloc("devfs", "dummy", &synth_mp
))) {
119 panic("synth: vfs_rootmountalloc failed with %d", error
);
122 if ((error
= VFS_MOUNT(synth_mp
, NULL
, NULL
, proc0
.p_ucred
))) {
123 panic("synth: vfs_mount failed with %d", error
);
126 if ((error
= VFS_ROOT(synth_mp
, &synth_vp
))) {
127 panic("synth: vfs_root failed with %d", error
);
130 cache_allocroot(&synth_mp
->mnt_ncmountpt
, synth_mp
, synth_vp
);
131 cache_unlock(&synth_mp
->mnt_ncmountpt
); /* leave ref intact */
137 SYSINIT(synthinit
, SI_SUB_VFS
, SI_ORDER_ANY
, synthinit
, NULL
);