xref: /titanic_50/usr/src/cmd/boot/bootadm/bootadm.h (revision 142c9f13e148d687426ed2d4e8bd93717eeaebbc)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _BOOTADM_H
27 #define	_BOOTADM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef	TEXT_DOMAIN
36 #define	TEXT_DOMAIN	"SUNW_OST_OSCMD"
37 #endif  /* TEXT_DOMAIN */
38 
39 /* Type definitions */
40 
41 /* GRUB menu per-line classification */
42 typedef enum {
43 	BAM_INVALID = 0,
44 	BAM_EMPTY,
45 	BAM_COMMENT,
46 	BAM_GLOBAL,
47 	BAM_ENTRY,
48 	BAM_TITLE
49 } menu_flag_t;
50 
51 /* struct for menu.lst contents */
52 typedef struct line {
53 	int  lineNum;	/* Line number in menu.lst */
54 	int  entryNum;	/* menu boot entry #. ENTRY_INIT if not applicable */
55 	char *cmd;
56 	char *sep;
57 	char *arg;
58 	char *line;
59 	menu_flag_t flags;
60 	struct line *next;
61 	struct line *prev;
62 } line_t;
63 
64 typedef struct entry {
65 	struct entry *next;
66 	struct entry *prev;
67 	line_t *start;
68 	line_t *end;
69 	int	entryNum;
70 	uint8_t	flags;
71 } entry_t;
72 
73 /* For flags value in entry_t */
74 #define	BAM_ENTRY_BOOTADM	0x01	/* entry created by bootadm */
75 #define	BAM_ENTRY_LU		0x02	/* entry created by Live Upgrade */
76 #define	BAM_ENTRY_CHAINLOADER	0x04	/* chainloader entry; do not disturb */
77 #define	BAM_ENTRY_ROOT		0x08	/* entry has a root line */
78 #define	BAM_ENTRY_MINIROOT	0x10	/* entry uses the failsafe miniroot */
79 #define	BAM_ENTRY_DBOOT		0x20	/* Is a dboot entry */
80 #define	BAM_ENTRY_32BIT		0x40	/* Is a 32-bit entry */
81 #define	BAM_ENTRY_HV		0x80	/* Is a hypervisor entry */
82 
83 typedef struct {
84 	line_t	*start;
85 	line_t	*end;
86 	line_t	*curdefault;	/* line containing default */
87 	line_t	*olddefault;	/* old default line (commented) */
88 	line_t	*old_rc_default;	/* old default line for bootenv.rc */
89 	entry_t	*entries;	/* os entries */
90 } menu_t;
91 
92 typedef enum {
93 	BAM_ERROR = -1,	/* Must be negative. add_boot_entry() depends on it */
94 	BAM_SUCCESS = 0,
95 	BAM_WRITE = 2,
96 	BAM_SKIP	/* Used by upgrade_menu() */
97 } error_t;
98 
99 /*
100  * Menu related
101  * menu_cmd_t and menu_cmds must be kept in sync
102  *
103  * The *_DOLLAR_CMD values must be 1 greater than the
104  * respective [KERNEL|MODULE]_CMD values.
105  */
106 typedef enum {
107 	DEFAULT_CMD = 0,
108 	TIMEOUT_CMD,
109 	TITLE_CMD,
110 	ROOT_CMD,
111 	KERNEL_CMD,
112 	KERNEL_DOLLAR_CMD,	/* Must be KERNEL_CMD + 1 */
113 	MODULE_CMD,
114 	MODULE_DOLLAR_CMD,	/* Must be MODULE_CMD + 1 */
115 	SEP_CMD,
116 	COMMENT_CMD,
117 	CHAINLOADER_CMD,
118 	ARGS_CMD
119 } menu_cmd_t;
120 
121 extern char *menu_cmds[];
122 
123 /* For multi- or direct-boot */
124 typedef enum {
125 	BAM_DIRECT_NOT_SET,
126 	BAM_DIRECT_MULTIBOOT,
127 	BAM_DIRECT_DBOOT
128 } direct_or_multi_t;
129 
130 /* Is there a hypervisor present? */
131 typedef enum {
132 	BAM_HV_UNKNOWN,
133 	BAM_HV_NO,
134 	BAM_HV_PRESENT
135 } hv_t;
136 
137 extern int bam_verbose;
138 extern int bam_force;
139 extern direct_or_multi_t bam_direct;
140 extern hv_t bam_is_hv;
141 
142 extern error_t upgrade_menu(menu_t *, char *, char *);
143 extern void *s_calloc(size_t, size_t);
144 extern void *s_realloc(void *, size_t);
145 extern char *s_fgets(char *buf, int n, FILE *fp);
146 extern void bam_error(char *format, ...);
147 extern void bam_print_stderr(char *format, ...);
148 extern error_t dboot_or_multiboot(const char *);
149 extern char *get_special(char *);
150 extern char *os_to_grubdisk(char *, int);
151 extern void update_line(line_t *);
152 extern int add_boot_entry(menu_t *, char *, char *, char *, char *, char *);
153 extern int is_grub(const char *);
154 
155 #define	BAM_MAXLINE	8192
156 
157 /* menu.lst comments created by bootadm */
158 #define	BAM_BOOTADM_HDR	"---------- ADDED BY BOOTADM - DO NOT EDIT ----------"
159 #define	BAM_BOOTADM_FTR	"---------------------END BOOTADM--------------------"
160 
161 /*
162  * menu.lst comments create by Live Upgrade.  Note that these are the end of
163  * the comment strings - there will be other text before them.
164  */
165 #define	BAM_LU_HDR	" - ADDED BY LIVE UPGRADE - DO NOT EDIT  -----"
166 #define	BAM_LU_FTR	" -------------- END LIVE UPGRADE ------------"
167 
168 #define	BAM_OLDDEF	"BOOTADM SAVED DEFAULT: "
169 #define	BAM_OLD_RC_DEF	"BOOTADM RC SAVED DEFAULT: "
170 
171 /* Title used for failsafe entries */
172 #define	FAILSAFE_TITLE	"Solaris failsafe"
173 
174 /* Title used for hv entries */
175 #define	NEW_HV_ENTRY	"Solaris xVM"
176 
177 /* ZFS boot option */
178 #define	ZFS_BOOT	"-B $ZFS-BOOTFS"
179 
180 /* multiboot */
181 #define	MULTI_BOOT	"/platform/i86pc/multiboot"
182 #define	MULTI_BOOT_FAILSAFE	"/boot/multiboot"
183 #define	MULTI_BOOT_FAILSAFE_UNIX	"kernel/unix"
184 #define	MULTI_BOOT_FAILSAFE_LINE	"/boot/multiboot kernel/unix -s"
185 
186 /* directboot kernels */
187 #define	DIRECT_BOOT_32	"/platform/i86pc/kernel/unix"
188 #define	DIRECT_BOOT_64	"/platform/i86pc/kernel/amd64/unix"
189 #define	DIRECT_BOOT_KERNEL	"/platform/i86pc/kernel/$ISADIR/unix"
190 #define	DIRECT_BOOT_FAILSAFE_KERNEL	"/boot/platform/i86pc/kernel/unix"
191 #define	DIRECT_BOOT_FAILSAFE_LINE	DIRECT_BOOT_FAILSAFE_KERNEL " -s"
192 #define	DIRECT_BOOT_KERNEL_ZFS	DIRECT_BOOT_KERNEL " " ZFS_BOOT
193 #define	DIRECT_BOOT_FAILSAFE_LINE_ZFS	DIRECT_BOOT_FAILSAFE_LINE " " ZFS_BOOT
194 
195 /* Boot archives */
196 #define	SUN4U_ARCHIVE		"/platform/sun4u/boot_archive"
197 #define	SUN4V_ARCHIVE		"/platform/sun4v/boot_archive"
198 #define	DIRECT_BOOT_ARCHIVE	"/platform/i86pc/$ISADIR/boot_archive"
199 #define	DIRECT_BOOT_ARCHIVE_32	"/platform/i86pc/boot_archive"
200 #define	DIRECT_BOOT_ARCHIVE_64	"/platform/i86pc/amd64/boot_archive"
201 #define	MULTI_BOOT_ARCHIVE	DIRECT_BOOT_ARCHIVE_32
202 #define	MINIROOT	"/boot/x86.miniroot-safe"
203 
204 /* Hypervisors */
205 #define	XEN_32			"/boot/xen.gz"
206 #define	XEN_64			"/boot/amd64/xen.gz"
207 #define	XEN_MENU		"/boot/$ISADIR/xen.gz"
208 #define	HYPERVISOR_KERNEL	"/platform/i86xpv/kernel/$ISADIR/unix"
209 #define	KERNEL_MODULE_LINE	HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL
210 #define	KERNEL_MODULE_LINE_ZFS	\
211 	HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL " " ZFS_BOOT
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif	/* _BOOTADM_H */
218