|
| 1 | +/* |
| 2 | + * This file is part of clr-boot-manager. |
| 3 | + * |
| 4 | + * Copyright © 2016-2018 Intel Corporation |
| 5 | + * Copyright © 2020 Silke Hofstra |
| 6 | + * |
| 7 | + * clr-boot-manager is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation; either version 2.1 |
| 10 | + * of the License, or (at your option) any later version. |
| 11 | + */ |
| 12 | + |
| 13 | +#define _GNU_SOURCE |
| 14 | + |
| 15 | +#include <stdio.h> |
| 16 | +#include <string.h> |
| 17 | + |
| 18 | +#include "bootman.h" |
| 19 | +#include "cli.h" |
| 20 | +#include "log.h" |
| 21 | + |
| 22 | +bool cbm_command_mount_boot(int argc, char **argv) |
| 23 | +{ |
| 24 | + autofree(char) *root = NULL; |
| 25 | + autofree(BootManager) *manager = NULL; |
| 26 | + bool forced_image = false; |
| 27 | + bool update_efi_vars = false; |
| 28 | + autofree(char) *boot_dir = NULL; |
| 29 | + int did_mount = -1; |
| 30 | + |
| 31 | + if (!cli_default_args_init(&argc, &argv, &root, &forced_image, &update_efi_vars)) { |
| 32 | + return false; |
| 33 | + } |
| 34 | + |
| 35 | + manager = boot_manager_new(); |
| 36 | + if (!manager) { |
| 37 | + DECLARE_OOM(); |
| 38 | + return false; |
| 39 | + } |
| 40 | + |
| 41 | + boot_manager_set_update_efi_vars(manager, update_efi_vars); |
| 42 | + |
| 43 | + if (root) { |
| 44 | + autofree(char) *realp = NULL; |
| 45 | + |
| 46 | + realp = realpath(root, NULL); |
| 47 | + if (!realp) { |
| 48 | + LOG_FATAL("Path specified does not exist: %s", root); |
| 49 | + return false; |
| 50 | + } |
| 51 | + /* Anything not / is image mode */ |
| 52 | + if (!streq(realp, "/")) { |
| 53 | + boot_manager_set_image_mode(manager, true); |
| 54 | + } else { |
| 55 | + boot_manager_set_image_mode(manager, forced_image); |
| 56 | + } |
| 57 | + |
| 58 | + /* CBM will check this again, we just needed to check for |
| 59 | + * image mode.. */ |
| 60 | + if (!boot_manager_set_prefix(manager, root)) { |
| 61 | + return false; |
| 62 | + } |
| 63 | + } else { |
| 64 | + boot_manager_set_image_mode(manager, forced_image); |
| 65 | + /* Default to "/", bail if it doesn't work. */ |
| 66 | + if (!boot_manager_set_prefix(manager, "/")) { |
| 67 | + return false; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /* Let CBM detect and mount the boot directory */ |
| 72 | + did_mount = boot_manager_detect_and_mount_boot(manager, &boot_dir); |
| 73 | + return did_mount >= 0; |
| 74 | +} |
| 75 | + |
| 76 | +/* |
| 77 | + * Editor modelines - https://www.wireshark.org/tools/modelines.html |
| 78 | + * |
| 79 | + * Local variables: |
| 80 | + * c-basic-offset: 8 |
| 81 | + * tab-width: 8 |
| 82 | + * indent-tabs-mode: nil |
| 83 | + * End: |
| 84 | + * |
| 85 | + * vi: set shiftwidth=8 tabstop=8 expandtab: |
| 86 | + * :indentSize=8:tabSize=8:noTabs=true: |
| 87 | + */ |
0 commit comments