[3eddaff] | 1 | /*
|
---|
[04e520e] | 2 | * Copyright (c) 2024 Jiri Svoboda
|
---|
[df4ed85] | 3 | * Copyright (c) 2005 Martin Decky
|
---|
[3eddaff] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[a63966d] | 30 | /** @addtogroup init
|
---|
[b2951e2] | 31 | * @{
|
---|
[c91c9fb] | 32 | */
|
---|
[b2951e2] | 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[0b63dc2] | 37 | #include <fibril.h>
|
---|
[04e520e] | 38 | #include <futil.h>
|
---|
[00c4994] | 39 | #include <stdio.h>
|
---|
[6d5e378] | 40 | #include <stdarg.h>
|
---|
[860271d4] | 41 | #include <vfs/vfs.h>
|
---|
[3e6a98c5] | 42 | #include <stdbool.h>
|
---|
[860271d4] | 43 | #include <errno.h>
|
---|
| 44 | #include <task.h>
|
---|
[38d150e] | 45 | #include <stdlib.h>
|
---|
[c91c9fb] | 46 | #include <macros.h>
|
---|
[19f857a] | 47 | #include <str.h>
|
---|
[15f3c3f] | 48 | #include <loc.h>
|
---|
[d9fae235] | 49 | #include <str_error.h>
|
---|
[73d8600] | 50 | #include <config.h>
|
---|
[8e9b2534] | 51 | #include <io/logctl.h>
|
---|
[0b63dc2] | 52 | #include <vfs/vfs.h>
|
---|
[63c1dd5] | 53 | #include <vol.h>
|
---|
[75701004] | 54 | #include "untar.h"
|
---|
[860271d4] | 55 | #include "init.h"
|
---|
| 56 |
|
---|
[51da086] | 57 | #define BANNER_LEFT "######> "
|
---|
| 58 | #define BANNER_RIGHT " <######"
|
---|
| 59 |
|
---|
[d9fae235] | 60 | #define ROOT_DEVICE "bd/initrd"
|
---|
| 61 | #define ROOT_MOUNT_POINT "/"
|
---|
| 62 |
|
---|
[15f3c3f] | 63 | #define LOCFS_FS_TYPE "locfs"
|
---|
| 64 | #define LOCFS_MOUNT_POINT "/loc"
|
---|
[47a350f] | 65 |
|
---|
[1ab0852] | 66 | #define TMPFS_FS_TYPE "tmpfs"
|
---|
| 67 | #define TMPFS_MOUNT_POINT "/tmp"
|
---|
[d9fae235] | 68 |
|
---|
[8fefd8b] | 69 | #define SRV_CONSOLE "/srv/hid/console"
|
---|
[df747bd8] | 70 | #define APP_GETTERM "/app/getterm"
|
---|
[47a350f] | 71 |
|
---|
[0b63dc2] | 72 | #define SRV_DISPLAY "/srv/hid/display"
|
---|
[6d5e378] | 73 |
|
---|
| 74 | #define HID_INPUT "hid/input"
|
---|
| 75 | #define HID_OUTPUT "hid/output"
|
---|
| 76 |
|
---|
| 77 | #define srv_start(path, ...) \
|
---|
| 78 | srv_startl(path, path, ##__VA_ARGS__, NULL)
|
---|
| 79 |
|
---|
[63c1dd5] | 80 | static const char *sys_dirs[] = {
|
---|
| 81 | "/w/cfg",
|
---|
[c06bd5e] | 82 | "/w/data",
|
---|
| 83 | NULL,
|
---|
[63c1dd5] | 84 | };
|
---|
| 85 |
|
---|
[53d6ac3d] | 86 | /** Print banner */
|
---|
[36b8100a] | 87 | static void info_print(void)
|
---|
| 88 | {
|
---|
[d9fae235] | 89 | printf("%s: HelenOS init\n", NAME);
|
---|
[36b8100a] | 90 | }
|
---|
| 91 |
|
---|
[51da086] | 92 | static void oom_check(errno_t rc, const char *path)
|
---|
| 93 | {
|
---|
| 94 | if (rc == ENOMEM) {
|
---|
| 95 | printf("%sOut-of-memory condition detected%s\n", BANNER_LEFT,
|
---|
| 96 | BANNER_RIGHT);
|
---|
| 97 | printf("%sBailing out of the boot process after %s%s\n",
|
---|
| 98 | BANNER_LEFT, path, BANNER_RIGHT);
|
---|
| 99 | printf("%sMore physical memory is required%s\n", BANNER_LEFT,
|
---|
| 100 | BANNER_RIGHT);
|
---|
| 101 | exit(ENOMEM);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[53d6ac3d] | 105 | /** Report mount operation success */
|
---|
[d9fae235] | 106 | static bool mount_report(const char *desc, const char *mntpt,
|
---|
[b7fd2a0] | 107 | const char *fstype, const char *dev, errno_t rc)
|
---|
[860271d4] | 108 | {
|
---|
[f49cf64] | 109 | switch (rc) {
|
---|
| 110 | case EOK:
|
---|
[75701004] | 111 | if ((dev != NULL) && (str_cmp(dev, "") != 0))
|
---|
[d9fae235] | 112 | printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
|
---|
| 113 | fstype, dev);
|
---|
| 114 | else
|
---|
| 115 | printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
|
---|
[f49cf64] | 116 | break;
|
---|
| 117 | case EBUSY:
|
---|
[d9fae235] | 118 | printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
|
---|
[f49cf64] | 119 | return false;
|
---|
| 120 | case ELIMIT:
|
---|
[d9fae235] | 121 | printf("%s: %s limit exceeded\n", NAME, desc);
|
---|
[f49cf64] | 122 | return false;
|
---|
| 123 | case ENOENT:
|
---|
[d9fae235] | 124 | printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
|
---|
[f49cf64] | 125 | return false;
|
---|
| 126 | default:
|
---|
[d9fae235] | 127 | printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
|
---|
| 128 | str_error(rc));
|
---|
[f49cf64] | 129 | return false;
|
---|
[860271d4] | 130 | }
|
---|
[a35b458] | 131 |
|
---|
[860271d4] | 132 | return true;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[75701004] | 135 | /** Mount root file system
|
---|
[53d6ac3d] | 136 | *
|
---|
[75701004] | 137 | * The operation blocks until the root file system
|
---|
[53d6ac3d] | 138 | * server is ready for mounting.
|
---|
| 139 | *
|
---|
[75701004] | 140 | * @param[in] fstype Root file system type.
|
---|
[53d6ac3d] | 141 | *
|
---|
| 142 | * @return True on success.
|
---|
| 143 | * @return False on failure.
|
---|
| 144 | *
|
---|
| 145 | */
|
---|
[d9fae235] | 146 | static bool mount_root(const char *fstype)
|
---|
[a095d20] | 147 | {
|
---|
[75701004] | 148 | const char *root_device = "";
|
---|
[a35b458] | 149 |
|
---|
[75701004] | 150 | if (str_cmp(fstype, "tmpfs") != 0)
|
---|
| 151 | root_device = ROOT_DEVICE;
|
---|
[a35b458] | 152 |
|
---|
[75701004] | 153 | errno_t rc = vfs_mount_path(ROOT_MOUNT_POINT, fstype, root_device, "",
|
---|
[4979403] | 154 | IPC_FLAG_BLOCKING, 0);
|
---|
[8e9b2534] | 155 | if (rc == EOK)
|
---|
| 156 | logctl_set_root();
|
---|
[75701004] | 157 |
|
---|
| 158 | bool ret = mount_report("Root file system", ROOT_MOUNT_POINT, fstype,
|
---|
| 159 | root_device, rc);
|
---|
| 160 |
|
---|
| 161 | rc = vfs_cwd_set(ROOT_MOUNT_POINT);
|
---|
| 162 | if (rc != EOK) {
|
---|
| 163 | printf("%s: Unable to set current directory to %s (%s)\n",
|
---|
| 164 | NAME, ROOT_MOUNT_POINT, str_error(ret));
|
---|
| 165 | return false;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | if ((ret) && (str_cmp(fstype, "tmpfs") == 0)) {
|
---|
| 169 | printf("%s: Extracting root file system archive\n", NAME);
|
---|
| 170 | ret = bd_untar(ROOT_DEVICE);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | return ret;
|
---|
[d9fae235] | 174 | }
|
---|
| 175 |
|
---|
[75701004] | 176 | /** Mount locfs file system
|
---|
[53d6ac3d] | 177 | *
|
---|
[75701004] | 178 | * The operation blocks until the locfs file system
|
---|
[53d6ac3d] | 179 | * server is ready for mounting.
|
---|
| 180 | *
|
---|
| 181 | * @return True on success.
|
---|
| 182 | * @return False on failure.
|
---|
| 183 | *
|
---|
| 184 | */
|
---|
[15f3c3f] | 185 | static bool mount_locfs(void)
|
---|
[d9fae235] | 186 | {
|
---|
[b7fd2a0] | 187 | errno_t rc = vfs_mount_path(LOCFS_MOUNT_POINT, LOCFS_FS_TYPE, "", "",
|
---|
[4979403] | 188 | IPC_FLAG_BLOCKING, 0);
|
---|
[75701004] | 189 | return mount_report("Location service file system", LOCFS_MOUNT_POINT,
|
---|
[15f3c3f] | 190 | LOCFS_FS_TYPE, NULL, rc);
|
---|
[a095d20] | 191 | }
|
---|
| 192 |
|
---|
[b7fd2a0] | 193 | static errno_t srv_startl(const char *path, ...)
|
---|
[860271d4] | 194 | {
|
---|
[39330200] | 195 | vfs_stat_t s;
|
---|
[23a0368] | 196 | if (vfs_stat_path(path, &s) != EOK) {
|
---|
[6d5e378] | 197 | printf("%s: Unable to stat %s\n", NAME, path);
|
---|
| 198 | return ENOENT;
|
---|
| 199 | }
|
---|
[a35b458] | 200 |
|
---|
[6d5e378] | 201 | printf("%s: Starting %s\n", NAME, path);
|
---|
[a35b458] | 202 |
|
---|
[6d5e378] | 203 | va_list ap;
|
---|
| 204 | const char *arg;
|
---|
| 205 | int cnt = 0;
|
---|
[a35b458] | 206 |
|
---|
[6d5e378] | 207 | va_start(ap, path);
|
---|
| 208 | do {
|
---|
| 209 | arg = va_arg(ap, const char *);
|
---|
| 210 | cnt++;
|
---|
| 211 | } while (arg != NULL);
|
---|
| 212 | va_end(ap);
|
---|
[a35b458] | 213 |
|
---|
[6d5e378] | 214 | va_start(ap, path);
|
---|
| 215 | task_id_t id;
|
---|
[1c635d6] | 216 | task_wait_t wait;
|
---|
[b7fd2a0] | 217 | errno_t rc = task_spawn(&id, &wait, path, cnt, ap);
|
---|
[6d5e378] | 218 | va_end(ap);
|
---|
[a35b458] | 219 |
|
---|
[0485135] | 220 | if (rc != EOK) {
|
---|
[51da086] | 221 | oom_check(rc, path);
|
---|
[6d5e378] | 222 | printf("%s: Error spawning %s (%s)\n", NAME, path,
|
---|
[0485135] | 223 | str_error(rc));
|
---|
[6d5e378] | 224 | return rc;
|
---|
[0485135] | 225 | }
|
---|
[a35b458] | 226 |
|
---|
[95bc57c] | 227 | if (!id) {
|
---|
[6d5e378] | 228 | printf("%s: Error spawning %s (invalid task id)\n", NAME,
|
---|
| 229 | path);
|
---|
| 230 | return EINVAL;
|
---|
[95bc57c] | 231 | }
|
---|
[a35b458] | 232 |
|
---|
[6d5e378] | 233 | task_exit_t texit;
|
---|
| 234 | int retval;
|
---|
[1c635d6] | 235 | rc = task_wait(&wait, &texit, &retval);
|
---|
[95bc57c] | 236 | if (rc != EOK) {
|
---|
[6d5e378] | 237 | printf("%s: Error waiting for %s (%s)\n", NAME, path,
|
---|
[0485135] | 238 | str_error(rc));
|
---|
[6d5e378] | 239 | return rc;
|
---|
[95bc57c] | 240 | }
|
---|
[a35b458] | 241 |
|
---|
[0485135] | 242 | if (texit != TASK_EXIT_NORMAL) {
|
---|
| 243 | printf("%s: Server %s failed to start (unexpectedly "
|
---|
[6d5e378] | 244 | "terminated)\n", NAME, path);
|
---|
| 245 | return EINVAL;
|
---|
[0485135] | 246 | }
|
---|
[a35b458] | 247 |
|
---|
[6d5e378] | 248 | if (retval != 0)
|
---|
[0485135] | 249 | printf("%s: Server %s failed to start (exit code %d)\n", NAME,
|
---|
[6d5e378] | 250 | path, retval);
|
---|
[a35b458] | 251 |
|
---|
[1569a9b] | 252 | return retval == 0 ? EOK : EPARTY;
|
---|
[95bc57c] | 253 | }
|
---|
| 254 |
|
---|
[b7fd2a0] | 255 | static errno_t console(const char *isvc, const char *osvc)
|
---|
[47a350f] | 256 | {
|
---|
[15f3c3f] | 257 | /* Wait for the input service to be ready */
|
---|
| 258 | service_id_t service_id;
|
---|
[b7fd2a0] | 259 | errno_t rc = loc_service_get_id(isvc, &service_id, IPC_FLAG_BLOCKING);
|
---|
[0485135] | 260 | if (rc != EOK) {
|
---|
[7c014d1] | 261 | printf("%s: Error waiting on %s (%s)\n", NAME, isvc,
|
---|
[d9fae235] | 262 | str_error(rc));
|
---|
[6d5e378] | 263 | return rc;
|
---|
[0485135] | 264 | }
|
---|
[a35b458] | 265 |
|
---|
[6d5e378] | 266 | /* Wait for the output service to be ready */
|
---|
| 267 | rc = loc_service_get_id(osvc, &service_id, IPC_FLAG_BLOCKING);
|
---|
[0485135] | 268 | if (rc != EOK) {
|
---|
[6d5e378] | 269 | printf("%s: Error waiting on %s (%s)\n", NAME, osvc,
|
---|
[7c014d1] | 270 | str_error(rc));
|
---|
[6d5e378] | 271 | return rc;
|
---|
| 272 | }
|
---|
[a35b458] | 273 |
|
---|
[6d5e378] | 274 | return srv_start(SRV_CONSOLE, isvc, osvc);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[1382446] | 277 | #ifdef CONFIG_WINSYS
|
---|
| 278 |
|
---|
[0b63dc2] | 279 | static errno_t display_server(void)
|
---|
[6d5e378] | 280 | {
|
---|
[0b63dc2] | 281 | return srv_start(SRV_DISPLAY);
|
---|
[6d5e378] | 282 | }
|
---|
| 283 |
|
---|
[06d0c81] | 284 | static int app_start(const char *app, const char *arg)
|
---|
[6d5e378] | 285 | {
|
---|
[0b63dc2] | 286 | printf("%s: Spawning %s\n", NAME, app);
|
---|
[a35b458] | 287 |
|
---|
[6d5e378] | 288 | task_id_t id;
|
---|
[1c635d6] | 289 | task_wait_t wait;
|
---|
[06d0c81] | 290 | errno_t rc = task_spawnl(&id, &wait, app, app, arg, NULL);
|
---|
[7c014d1] | 291 | if (rc != EOK) {
|
---|
[51da086] | 292 | oom_check(rc, app);
|
---|
[0b63dc2] | 293 | printf("%s: Error spawning %s (%s)\n", NAME, app,
|
---|
| 294 | str_error(rc));
|
---|
[6d5e378] | 295 | return -1;
|
---|
[0485135] | 296 | }
|
---|
[a35b458] | 297 |
|
---|
[6d5e378] | 298 | task_exit_t texit;
|
---|
| 299 | int retval;
|
---|
[1c635d6] | 300 | rc = task_wait(&wait, &texit, &retval);
|
---|
[6d5e378] | 301 | if ((rc != EOK) || (texit != TASK_EXIT_NORMAL)) {
|
---|
| 302 | printf("%s: Error retrieving retval from %s (%s)\n", NAME,
|
---|
| 303 | app, str_error(rc));
|
---|
[51da086] | 304 | return rc;
|
---|
[0485135] | 305 | }
|
---|
[a35b458] | 306 |
|
---|
[6d5e378] | 307 | return retval;
|
---|
[47a350f] | 308 | }
|
---|
| 309 |
|
---|
[1382446] | 310 | #endif
|
---|
| 311 |
|
---|
[593e023] | 312 | static void getterm(const char *svc, const char *app, bool msg)
|
---|
[36b8100a] | 313 | {
|
---|
[593e023] | 314 | if (msg) {
|
---|
| 315 | printf("%s: Spawning %s %s %s --msg --wait -- %s\n", NAME,
|
---|
| 316 | APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
|
---|
[a35b458] | 317 |
|
---|
[b7fd2a0] | 318 | errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
|
---|
[593e023] | 319 | LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
|
---|
[51da086] | 320 | if (rc != EOK) {
|
---|
| 321 | oom_check(rc, APP_GETTERM);
|
---|
[593e023] | 322 | printf("%s: Error spawning %s %s %s --msg --wait -- %s\n",
|
---|
| 323 | NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
|
---|
[51da086] | 324 | }
|
---|
[4deb8b5] | 325 | } else {
|
---|
[593e023] | 326 | printf("%s: Spawning %s %s %s --wait -- %s\n", NAME,
|
---|
| 327 | APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
|
---|
[a35b458] | 328 |
|
---|
[b7fd2a0] | 329 | errno_t rc = task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
|
---|
[593e023] | 330 | LOCFS_MOUNT_POINT, "--wait", "--", app, NULL);
|
---|
[51da086] | 331 | if (rc != EOK) {
|
---|
| 332 | oom_check(rc, APP_GETTERM);
|
---|
[593e023] | 333 | printf("%s: Error spawning %s %s %s --wait -- %s\n",
|
---|
| 334 | NAME, APP_GETTERM, svc, LOCFS_MOUNT_POINT, app);
|
---|
[51da086] | 335 | }
|
---|
[0485135] | 336 | }
|
---|
[36b8100a] | 337 | }
|
---|
| 338 |
|
---|
[1ab0852] | 339 | static bool mount_tmpfs(void)
|
---|
[03333bc] | 340 | {
|
---|
[b7fd2a0] | 341 | errno_t rc = vfs_mount_path(TMPFS_MOUNT_POINT, TMPFS_FS_TYPE, "", "", 0, 0);
|
---|
[75701004] | 342 | return mount_report("Temporary file system", TMPFS_MOUNT_POINT,
|
---|
[1ab0852] | 343 | TMPFS_FS_TYPE, NULL, rc);
|
---|
[03333bc] | 344 | }
|
---|
| 345 |
|
---|
[63c1dd5] | 346 | /** Init system volume.
|
---|
| 347 | *
|
---|
| 348 | * See if system volume is configured. If so, try to wait for it to become
|
---|
| 349 | * available. If not, create basic directories for live image omde.
|
---|
| 350 | */
|
---|
| 351 | static errno_t init_sysvol(void)
|
---|
| 352 | {
|
---|
| 353 | vol_t *vol = NULL;
|
---|
| 354 | vol_info_t vinfo;
|
---|
| 355 | volume_id_t *volume_ids = NULL;
|
---|
[04e520e] | 356 | service_id_t *part_ids = NULL;
|
---|
| 357 | vol_part_info_t pinfo;
|
---|
[63c1dd5] | 358 | size_t nvols;
|
---|
[04e520e] | 359 | size_t nparts;
|
---|
| 360 | bool sv_mounted;
|
---|
[63c1dd5] | 361 | size_t i;
|
---|
| 362 | errno_t rc;
|
---|
| 363 | bool found_cfg;
|
---|
| 364 | const char **cp;
|
---|
| 365 |
|
---|
| 366 | rc = vol_create(&vol);
|
---|
| 367 | if (rc != EOK) {
|
---|
| 368 | printf("Error contacting volume service.\n");
|
---|
| 369 | goto error;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | rc = vol_get_volumes(vol, &volume_ids, &nvols);
|
---|
| 373 | if (rc != EOK) {
|
---|
| 374 | printf("Error getting list of volumes.\n");
|
---|
| 375 | goto error;
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | /* XXX This could be handled more efficiently by volsrv itself */
|
---|
| 379 | found_cfg = false;
|
---|
| 380 | for (i = 0; i < nvols; i++) {
|
---|
| 381 | rc = vol_info(vol, volume_ids[i], &vinfo);
|
---|
| 382 | if (rc != EOK) {
|
---|
| 383 | printf("Error getting volume information.\n");
|
---|
| 384 | rc = EIO;
|
---|
| 385 | goto error;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | if (str_cmp(vinfo.path, "/w") == 0) {
|
---|
| 389 | found_cfg = true;
|
---|
| 390 | break;
|
---|
| 391 | }
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | free(volume_ids);
|
---|
[04e520e] | 395 | volume_ids = NULL;
|
---|
[63c1dd5] | 396 |
|
---|
| 397 | if (!found_cfg) {
|
---|
| 398 | /* Prepare directory structure for live image mode */
|
---|
| 399 | printf("%s: Creating live image directory structure.\n", NAME);
|
---|
| 400 | cp = sys_dirs;
|
---|
| 401 | while (*cp != NULL) {
|
---|
| 402 | rc = vfs_link_path(*cp, KIND_DIRECTORY, NULL);
|
---|
| 403 | if (rc != EOK) {
|
---|
| 404 | printf("%s: Error creating directory '%s'.\n",
|
---|
| 405 | NAME, *cp);
|
---|
[04e520e] | 406 | goto error;
|
---|
[63c1dd5] | 407 | }
|
---|
| 408 |
|
---|
| 409 | ++cp;
|
---|
| 410 | }
|
---|
[04e520e] | 411 |
|
---|
| 412 | /* Copy initial configuration files */
|
---|
| 413 | rc = futil_rcopy_contents("/cfg", "/w/cfg");
|
---|
| 414 | if (rc != EOK)
|
---|
| 415 | goto error;
|
---|
[63c1dd5] | 416 | } else {
|
---|
| 417 | printf("%s: System volume is configured.\n", NAME);
|
---|
[04e520e] | 418 |
|
---|
| 419 | /* Wait until system volume is mounted */
|
---|
| 420 | sv_mounted = false;
|
---|
| 421 |
|
---|
| 422 | while (true) {
|
---|
| 423 | rc = vol_get_parts(vol, &part_ids, &nparts);
|
---|
| 424 | if (rc != EOK) {
|
---|
| 425 | printf("Error getting list of volumes.\n");
|
---|
| 426 | goto error;
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | for (i = 0; i < nparts; i++) {
|
---|
| 430 | rc = vol_part_info(vol, part_ids[i], &pinfo);
|
---|
| 431 | if (rc != EOK) {
|
---|
| 432 | printf("Error getting partition "
|
---|
| 433 | "information.\n");
|
---|
| 434 | rc = EIO;
|
---|
| 435 | goto error;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | if (str_cmp(pinfo.cur_mp, "/w") == 0) {
|
---|
| 439 | sv_mounted = true;
|
---|
| 440 | break;
|
---|
| 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | if (sv_mounted)
|
---|
| 445 | break;
|
---|
| 446 |
|
---|
| 447 | free(part_ids);
|
---|
| 448 | part_ids = NULL;
|
---|
| 449 |
|
---|
| 450 | fibril_sleep(1);
|
---|
| 451 | printf("Sleeping(1) for system volume.\n");
|
---|
| 452 | }
|
---|
[63c1dd5] | 453 | }
|
---|
| 454 |
|
---|
[04e520e] | 455 | vol_destroy(vol);
|
---|
[63c1dd5] | 456 | return EOK;
|
---|
| 457 | error:
|
---|
| 458 | vol_destroy(vol);
|
---|
| 459 | if (volume_ids != NULL)
|
---|
| 460 | free(volume_ids);
|
---|
[04e520e] | 461 | if (part_ids != NULL)
|
---|
| 462 | free(part_ids);
|
---|
[63c1dd5] | 463 |
|
---|
| 464 | return rc;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[5106e98] | 467 | int main(int argc, char *argv[])
|
---|
| 468 | {
|
---|
[b7fd2a0] | 469 | errno_t rc;
|
---|
[73d8600] | 470 |
|
---|
[860271d4] | 471 | info_print();
|
---|
[a35b458] | 472 |
|
---|
[36b8100a] | 473 | if (!mount_root(STRING(RDFMT))) {
|
---|
[d9fae235] | 474 | printf("%s: Exiting\n", NAME);
|
---|
[6d5e378] | 475 | return 1;
|
---|
[860271d4] | 476 | }
|
---|
[a35b458] | 477 |
|
---|
[395df52] | 478 | /* Make sure file systems are running. */
|
---|
[6d5e378] | 479 | if (str_cmp(STRING(RDFMT), "tmpfs") != 0)
|
---|
[8fefd8b] | 480 | srv_start("/srv/fs/tmpfs");
|
---|
[395df52] | 481 | if (str_cmp(STRING(RDFMT), "exfat") != 0)
|
---|
[8fefd8b] | 482 | srv_start("/srv/fs/exfat");
|
---|
[395df52] | 483 | if (str_cmp(STRING(RDFMT), "fat") != 0)
|
---|
[8fefd8b] | 484 | srv_start("/srv/fs/fat");
|
---|
| 485 | srv_start("/srv/fs/cdfs");
|
---|
| 486 | srv_start("/srv/fs/mfs");
|
---|
[a35b458] | 487 |
|
---|
[ca05e9b] | 488 | srv_start("/srv/klog");
|
---|
[8fefd8b] | 489 | srv_start("/srv/fs/locfs");
|
---|
[a35b458] | 490 |
|
---|
[15f3c3f] | 491 | if (!mount_locfs()) {
|
---|
[d9fae235] | 492 | printf("%s: Exiting\n", NAME);
|
---|
[6d5e378] | 493 | return 2;
|
---|
[a095d20] | 494 | }
|
---|
[a35b458] | 495 |
|
---|
[1ab0852] | 496 | mount_tmpfs();
|
---|
[a35b458] | 497 |
|
---|
[6d5e378] | 498 | srv_start("/srv/devman");
|
---|
[8fefd8b] | 499 | srv_start("/srv/hid/s3c24xx_uart");
|
---|
| 500 | srv_start("/srv/hid/s3c24xx_ts");
|
---|
[a35b458] | 501 |
|
---|
[8fefd8b] | 502 | srv_start("/srv/bd/vbd");
|
---|
[dc2d582] | 503 | srv_start("/srv/volsrv");
|
---|
[a35b458] | 504 |
|
---|
[dbae3b6] | 505 | init_sysvol();
|
---|
| 506 |
|
---|
| 507 | srv_start("/srv/taskmon");
|
---|
| 508 |
|
---|
[8fefd8b] | 509 | srv_start("/srv/net/loopip");
|
---|
| 510 | srv_start("/srv/net/ethip");
|
---|
| 511 | srv_start("/srv/net/inetsrv");
|
---|
| 512 | srv_start("/srv/net/tcp");
|
---|
| 513 | srv_start("/srv/net/udp");
|
---|
| 514 | srv_start("/srv/net/dnsrsrv");
|
---|
| 515 | srv_start("/srv/net/dhcp");
|
---|
| 516 | srv_start("/srv/net/nconfsrv");
|
---|
[a35b458] | 517 |
|
---|
[6d5e378] | 518 | srv_start("/srv/clipboard");
|
---|
[8fefd8b] | 519 | srv_start("/srv/hid/remcons");
|
---|
[a35b458] | 520 |
|
---|
[8fefd8b] | 521 | srv_start("/srv/hid/input", HID_INPUT);
|
---|
| 522 | srv_start("/srv/hid/output", HID_OUTPUT);
|
---|
| 523 | srv_start("/srv/audio/hound");
|
---|
[a35b458] | 524 |
|
---|
[1382446] | 525 | #ifdef CONFIG_WINSYS
|
---|
[73d8600] | 526 | if (!config_key_exists("console")) {
|
---|
[0b63dc2] | 527 | rc = display_server();
|
---|
[73d8600] | 528 | if (rc == EOK) {
|
---|
[a5c7b865] | 529 | app_start("/app/taskbar", NULL);
|
---|
[06d0c81] | 530 | app_start("/app/terminal", "-topleft");
|
---|
[73d8600] | 531 | }
|
---|
[593e023] | 532 | }
|
---|
[1382446] | 533 | #endif
|
---|
[593e023] | 534 | rc = console(HID_INPUT, HID_OUTPUT);
|
---|
| 535 | if (rc == EOK) {
|
---|
| 536 | getterm("term/vc0", "/app/bdsh", true);
|
---|
| 537 | getterm("term/vc1", "/app/bdsh", false);
|
---|
| 538 | getterm("term/vc2", "/app/bdsh", false);
|
---|
| 539 | getterm("term/vc3", "/app/bdsh", false);
|
---|
| 540 | getterm("term/vc4", "/app/bdsh", false);
|
---|
| 541 | getterm("term/vc5", "/app/bdsh", false);
|
---|
[6d5e378] | 542 | }
|
---|
[a35b458] | 543 |
|
---|
[3eddaff] | 544 | return 0;
|
---|
| 545 | }
|
---|
[b2951e2] | 546 |
|
---|
| 547 | /** @}
|
---|
| 548 | */
|
---|