1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * 25 * Copyright 2016 Toomas Soome <tsoome@me.com>. 26 */ 27 28 #ifndef _BOOTADM_H 29 #define _BOOTADM_H 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #include <assert.h> 36 37 #ifndef TEXT_DOMAIN 38 #define TEXT_DOMAIN "SUNW_OST_OSCMD" 39 #endif /* TEXT_DOMAIN */ 40 41 /* Type definitions */ 42 43 /* GRUB menu per-line classification */ 44 typedef enum { 45 BAM_INVALID = 0, 46 BAM_EMPTY, 47 BAM_COMMENT, 48 BAM_GLOBAL, 49 BAM_ENTRY, 50 BAM_TITLE 51 } menu_flag_t; 52 53 /* struct for menu.lst contents */ 54 typedef struct line { 55 int lineNum; /* Line number in menu.lst */ 56 int entryNum; /* menu boot entry #. ENTRY_INIT if not applicable */ 57 char *cmd; 58 char *sep; 59 char *arg; 60 char *line; 61 menu_flag_t flags; 62 struct line *next; 63 struct line *prev; 64 } line_t; 65 66 typedef struct entry { 67 struct entry *next; 68 struct entry *prev; 69 line_t *start; 70 line_t *end; 71 int entryNum; 72 uint_t flags; 73 } entry_t; 74 75 /* For flags value in entry_t */ 76 #define BAM_ENTRY_BOOTADM 0x01 /* entry created by bootadm */ 77 #define BAM_ENTRY_LU 0x02 /* entry created by Live Upgrade */ 78 #define BAM_ENTRY_CHAINLOADER 0x04 /* chainloader entry; do not disturb */ 79 #define BAM_ENTRY_ROOT 0x08 /* entry has a root line */ 80 #define BAM_ENTRY_FAILSAFE 0x10 /* failsafe entry */ 81 #define BAM_ENTRY_DBOOT 0x20 /* Is dboot (normal or failsafe) */ 82 #define BAM_ENTRY_32BIT 0x40 /* Is a 32-bit entry */ 83 #define BAM_ENTRY_HV 0x80 /* Is a hypervisor entry */ 84 #define BAM_ENTRY_FINDROOT 0x100 /* entry has a findroot line */ 85 #define BAM_ENTRY_MULTIBOOT 0x200 /* is multiboot (normal or failsafe) */ 86 #define BAM_ENTRY_64BIT 0x400 /* Is a 64-bit entry */ 87 88 #define BAM_ENTRY_UPGFSKERNEL 0x800 /* Upgrade failsafe kernel entry */ 89 #define BAM_ENTRY_UPGFSMODULE 0x1000 /* Upgrade failsafe module entry */ 90 91 #define BAM_ENTRY_LIBBE 0x2000 /* entry created by libbe */ 92 93 typedef struct { 94 line_t *start; 95 line_t *end; 96 line_t *curdefault; /* line containing default */ 97 line_t *olddefault; /* old default line (commented) */ 98 line_t *old_rc_default; /* old default line for bootenv.rc */ 99 entry_t *entries; /* os entries */ 100 } menu_t; 101 102 typedef enum { 103 BAM_ERROR = -1, /* Must be negative. add_boot_entry() depends on it */ 104 BAM_SUCCESS = 0, 105 BAM_WRITE = 2, 106 BAM_MSG, /* Used by upgrade_menu() */ 107 BAM_NOCHANGE /* Used by cvt_to_hyper()/cvt_to_metal() */ 108 } error_t; 109 110 /* 111 * Menu related 112 * menu_cmd_t and menu_cmds must be kept in sync 113 * 114 * The *_DOLLAR_CMD values must be 1 greater than the 115 * respective [KERNEL|MODULE]_CMD values. 116 */ 117 typedef enum { 118 DEFAULT_CMD = 0, 119 TIMEOUT_CMD, 120 TITLE_CMD, 121 ROOT_CMD, 122 KERNEL_CMD, 123 KERNEL_DOLLAR_CMD, /* Must be KERNEL_CMD + 1 */ 124 MODULE_CMD, 125 MODULE_DOLLAR_CMD, /* Must be MODULE_CMD + 1 */ 126 SEP_CMD, 127 COMMENT_CMD, 128 CHAINLOADER_CMD, 129 ARGS_CMD, 130 FINDROOT_CMD, 131 BOOTFS_CMD 132 } menu_cmd_t; 133 134 extern char *menu_cmds[]; 135 136 /* For multi- or direct-boot */ 137 typedef enum { 138 BAM_DIRECT_NOT_SET, 139 BAM_DIRECT_MULTIBOOT, 140 BAM_DIRECT_DBOOT 141 } direct_or_multi_t; 142 143 /* Is there a hypervisor present? */ 144 typedef enum { 145 BAM_HV_UNKNOWN, 146 BAM_HV_NO, 147 BAM_HV_PRESENT 148 } hv_t; 149 150 /* Is there findroot capability present ? */ 151 typedef enum { 152 BAM_FINDROOT_UNKNOWN, 153 BAM_FINDROOT_ABSENT, 154 BAM_FINDROOT_PRESENT 155 } findroot_t; 156 157 extern int bam_verbose; 158 extern int bam_force; 159 extern direct_or_multi_t bam_direct; 160 extern hv_t bam_is_hv; 161 extern findroot_t bam_is_findroot; 162 extern int bam_debug; 163 164 extern void bam_add_line(menu_t *mp, entry_t *entry, line_t *prev, line_t *lp); 165 extern void update_numbering(menu_t *mp); 166 extern error_t set_global(menu_t *, char *, int); 167 extern error_t upgrade_menu(menu_t *, char *, char *); 168 extern error_t cvt_to_hyper(menu_t *, char *, char *); 169 extern error_t cvt_to_metal(menu_t *, char *, char *); 170 extern void *s_calloc(size_t, size_t); 171 extern void *s_realloc(void *, size_t); 172 extern char *s_fgets(char *buf, int n, FILE *fp); 173 extern void bam_error(char *format, ...); 174 extern void bam_exit(int); 175 extern void bam_print(char *, ...); 176 extern void bam_print_stderr(char *format, ...); 177 extern void bam_derror(char *format, ...); 178 extern error_t get_boot_cap(const char *osroot); 179 extern char *get_special(char *); 180 extern char *os_to_grubdisk(char *, int); 181 extern void update_line(line_t *); 182 extern int add_boot_entry(menu_t *, char *, char *, char *, char *, char *, 183 char *); 184 extern error_t delete_boot_entry(menu_t *, int, int); 185 extern int is_grub(const char *); 186 extern char *get_grubsign(char *osroot, char *osdev); 187 extern char *get_grubroot(char *osroot, char *osdev, char *menu_root); 188 extern int root_optional(char *osroot, char *menu_root); 189 extern void unlink_line(menu_t *mp, line_t *lp); 190 extern void line_free(line_t *lp); 191 extern char *s_strdup(char *); 192 extern int is_sparc(void); 193 extern int bootadm_digest(const char *, char **); 194 195 #define BAM_MAXLINE 8192 196 197 /* menu.lst comments created by bootadm */ 198 #define BAM_BOOTADM_HDR "---------- ADDED BY BOOTADM - DO NOT EDIT ----------" 199 #define BAM_BOOTADM_FTR "---------------------END BOOTADM--------------------" 200 201 /* 202 * menu.lst comments create by Live Upgrade. Note that these are the end of 203 * the comment strings - there will be other text before them. 204 */ 205 #define BAM_LU_HDR " - ADDED BY LIVE UPGRADE - DO NOT EDIT -----" 206 #define BAM_LU_FTR " -------------- END LIVE UPGRADE ------------" 207 208 #define BAM_OLDDEF "BOOTADM SAVED DEFAULT: " 209 #define BAM_OLD_RC_DEF "BOOTADM RC SAVED DEFAULT: " 210 211 /* 212 * menu.lst comment created by libbe 213 */ 214 #define BAM_LIBBE_FTR "============ End of LIBBE entry =============" 215 216 /* Title used for failsafe entries */ 217 #define FAILSAFE_TITLE "Solaris failsafe" 218 219 /* Title used for hv entries */ 220 #define NEW_HV_ENTRY "Solaris xVM" 221 222 /* ZFS boot option */ 223 #define ZFS_BOOT "-B $ZFS-BOOTFS" 224 225 /* multiboot */ 226 #define MULTI_BOOT "/platform/i86pc/multiboot" 227 #define MULTI_BOOT_FAILSAFE "/boot/multiboot" 228 #define MULTI_BOOT_FAILSAFE_UNIX "kernel/unix" 229 #define MULTI_BOOT_FAILSAFE_LINE "/boot/multiboot kernel/unix -s" 230 231 /* directboot kernels */ 232 #define DIRECT_BOOT_32 "/platform/i86pc/kernel/unix" 233 #define DIRECT_BOOT_64 "/platform/i86pc/kernel/amd64/unix" 234 #define DIRECT_BOOT_KERNEL "/platform/i86pc/kernel/$ISADIR/unix" 235 #define DIRECT_BOOT_FAILSAFE_32 "/boot/platform/i86pc/kernel/unix" 236 #define DIRECT_BOOT_FAILSAFE_64 "/boot/platform/i86pc/kernel/amd64/unix" 237 #define DIRECT_BOOT_FAILSAFE_KERNEL \ 238 "/boot/platform/i86pc/kernel/$ISADIR/unix" 239 #define DIRECT_BOOT_FAILSAFE_LINE DIRECT_BOOT_FAILSAFE_KERNEL " -s" 240 #define DIRECT_BOOT_KERNEL_ZFS DIRECT_BOOT_KERNEL " " ZFS_BOOT 241 #define DIRECT_BOOT_PREFIX "/platform/i86pc/" 242 #define KERNEL_PREFIX "/platform/i86pc/" 243 #define AMD_UNIX_SPACE "/amd64/unix " 244 #define UNIX_SPACE "/unix " 245 246 /* xVM kernels */ 247 #define XEN_KERNEL_SUBSTR "xen.gz" 248 249 /* Boot archives */ 250 #define ARCHIVE_PREFIX "/platform/" 251 #define ARCHIVE_SUFFIX "/boot_archive" 252 #define CACHEDIR_SUFFIX "/archive_cache" 253 #define UPDATEDIR_SUFFIX "/updates" 254 #define DIRECT_BOOT_ARCHIVE "/platform/i86pc/$ISADIR/boot_archive" 255 #define DIRECT_BOOT_ARCHIVE_32 "/platform/i86pc/boot_archive" 256 #define DIRECT_BOOT_ARCHIVE_64 "/platform/i86pc/amd64/boot_archive" 257 #define MULTIBOOT_ARCHIVE DIRECT_BOOT_ARCHIVE_32 258 #define FAILSAFE_ARCHIVE "/boot/$ISADIR/x86.miniroot-safe" 259 #define FAILSAFE_ARCHIVE_32 "/boot/x86.miniroot-safe" 260 #define FAILSAFE_ARCHIVE_64 "/boot/amd64/x86.miniroot-safe" 261 #define CACHEDIR_32 "/platform/i86pc/archive_cache" 262 #define CACHEDIR_64 "/platform/i86pc/amd64/archive_cache" 263 #define UPDATEDIR_32 "/platform/i86pc/updates" 264 #define UPDATEDIR_64 "/platform/i86pc/amd64/updates" 265 266 /* Hypervisors */ 267 #define XEN_64 "/boot/amd64/xen.gz" 268 #define XEN_MENU "/boot/$ISADIR/xen.gz" 269 #define HYPERVISOR_KERNEL "/platform/i86xpv/kernel/$ISADIR/unix" 270 #define XEN_KERNEL_MODULE_LINE HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL 271 #define XEN_KERNEL_MODULE_LINE_ZFS \ 272 HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL " " ZFS_BOOT 273 274 /* Helpers */ 275 #define MKISOFS_PATH "/usr/bin/mkisofs" 276 #define DD_PATH_USR "/usr/bin/dd" 277 #define LOCKFS_PATH "/usr/sbin/lockfs" 278 279 /* A first guess at the number of entries in a menu */ 280 #define BAM_ENTRY_NUM 10 281 282 /* toggle for whether delete_boot_entry prints an error message or not */ 283 #define DBE_PRINTERR 0 284 #define DBE_QUIET 1 285 286 /* 287 * Debugging defines 288 */ 289 #define INJECT_ERROR1(x, y) \ 290 { \ 291 if (bam_debug) { \ 292 char *inj = getenv("_BOOTADM_INJECT"); \ 293 if (inj && strcmp(inj, (x)) == 0) { \ 294 y; \ 295 } \ 296 } \ 297 } 298 299 #define INJECT_ERROR2(x, y, z) \ 300 { \ 301 if (bam_debug) { \ 302 char *inj = getenv("_BOOTADM_INJECT"); \ 303 if (inj && strcmp(inj, (x)) == 0) { \ 304 y; \ 305 z; \ 306 } \ 307 } \ 308 } 309 310 #define BAM_DPRINTF(x) {if (bam_debug) bam_derror x; } 311 312 #ifdef __cplusplus 313 } 314 #endif 315 316 #endif /* _BOOTADM_H */ 317