2
* Copyright (c) 2005 Martin Decky
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* - The name of the author may not be used to endorse or promote products
15
* derived from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
/** @addtogroup init Init
30
* @brief Init process for user space environment configuration.
53
static void info_print(void)
55
printf(NAME ": HelenOS init\n");
58
static bool mount_root(const char *fstype)
61
const char *root_dev = "initrd";
63
if (str_cmp(fstype, "tmpfs") == 0)
66
int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING);
70
printf(NAME ": Root filesystem mounted, %s at %s\n",
74
printf(NAME ": Root filesystem already mounted\n");
77
printf(NAME ": Unable to mount root filesystem\n");
80
printf(NAME ": Unknown filesystem type (%s)\n", fstype);
83
printf(NAME ": Error mounting root filesystem (%d)\n", rc);
90
static bool mount_devfs(void)
92
char null[MAX_DEVICE_NAME];
93
int null_id = devmap_null_create();
96
printf(NAME ": Unable to create null device\n");
100
snprintf(null, MAX_DEVICE_NAME, "null%d", null_id);
101
int rc = mount("devfs", "/dev", null, "", IPC_FLAG_BLOCKING);
105
printf(NAME ": Device filesystem mounted\n");
108
printf(NAME ": Device filesystem already mounted\n");
109
devmap_null_destroy(null_id);
112
printf(NAME ": Unable to mount device filesystem\n");
113
devmap_null_destroy(null_id);
116
printf(NAME ": Unknown filesystem type (devfs)\n");
117
devmap_null_destroy(null_id);
120
printf(NAME ": Error mounting device filesystem (%d)\n", rc);
121
devmap_null_destroy(null_id);
128
static void spawn(char *fname)
133
if (stat(fname, &s) == ENOENT)
136
printf(NAME ": Spawning %s\n", fname);
141
if (!task_spawn(fname, argv))
142
printf(NAME ": Error spawning %s\n", fname);
145
static void srv_start(char *fname)
153
if (stat(fname, &s) == ENOENT)
156
printf(NAME ": Starting %s\n", fname);
161
id = task_spawn(fname, argv);
163
printf(NAME ": Error spawning %s\n", fname);
167
rc = task_wait(id, &texit, &retval);
169
printf(NAME ": Error waiting for %s\n", fname);
173
if (texit != TASK_EXIT_NORMAL || retval != 0) {
174
printf(NAME ": Server %s failed to start (returned %d)\n",
179
static void getvc(char *dev, char *app)
182
char vc[MAX_DEVICE_NAME];
185
snprintf(vc, MAX_DEVICE_NAME, "/dev/%s", dev);
187
printf(NAME ": Spawning getvc on %s\n", vc);
190
rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);
193
argv[0] = "/app/getvc";
198
if (!task_spawn("/app/getvc", argv))
199
printf(NAME ": Error spawning getvc on %s\n", vc);
201
printf(NAME ": Error waiting on %s\n", vc);
205
static void mount_data(void)
209
printf("Trying to mount disk0 on /data... ");
212
rc = mount("fat", "/data", "disk0", "wtcache", 0);
219
int main(int argc, char *argv[])
223
if (!mount_root(STRING(RDFMT))) {
224
printf(NAME ": Exiting\n");
230
if (!mount_devfs()) {
231
printf(NAME ": Exiting\n");
237
spawn("/srv/console");
242
* Start these synchronously so that mount_data() can be
245
#ifdef CONFIG_START_BD
246
srv_start("/srv/ata_bd");
247
srv_start("/srv/gxe_bd");
252
#ifdef CONFIG_MOUNT_DATA
258
getvc("vc0", "/app/bdsh");
259
getvc("vc1", "/app/bdsh");
260
getvc("vc2", "/app/bdsh");
261
getvc("vc3", "/app/bdsh");
262
getvc("vc4", "/app/bdsh");
263
getvc("vc5", "/app/bdsh");
264
getvc("vc6", "/app/klog");