xref: /titanic_50/usr/src/cmd/boot/bootadm/bootadm.h (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
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 
26 #ifndef _BOOTADM_H
27 #define	_BOOTADM_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <assert.h>
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 	uint_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_FAILSAFE	0x10	/* failsafe entry  */
79 #define	BAM_ENTRY_DBOOT		0x20	/* Is dboot (normal or failsafe) */
80 #define	BAM_ENTRY_32BIT		0x40	/* Is a 32-bit entry */
81 #define	BAM_ENTRY_HV		0x80	/* Is a hypervisor entry */
82 #define	BAM_ENTRY_FINDROOT	0x100	/* entry has a findroot line */
83 #define	BAM_ENTRY_MULTIBOOT	0x200	/* is multiboot (normal or failsafe) */
84 #define	BAM_ENTRY_64BIT		0x400	/* Is a 64-bit entry */
85 
86 #define	BAM_ENTRY_UPGFSKERNEL	0x800	/* Upgrade failsafe kernel entry */
87 #define	BAM_ENTRY_UPGFSMODULE	0x1000  /* Upgrade failsafe module entry */
88 
89 typedef struct {
90 	line_t	*start;
91 	line_t	*end;
92 	line_t	*curdefault;	/* line containing default */
93 	line_t	*olddefault;	/* old default line (commented) */
94 	line_t	*old_rc_default;	/* old default line for bootenv.rc */
95 	entry_t	*entries;	/* os entries */
96 } menu_t;
97 
98 typedef enum {
99 	BAM_ERROR = -1,	/* Must be negative. add_boot_entry() depends on it */
100 	BAM_SUCCESS = 0,
101 	BAM_WRITE = 2,
102 	BAM_MSG,	/* Used by upgrade_menu() */
103 	BAM_NOCHANGE	/* Used by cvt_to_hyper()/cvt_to_metal() */
104 } error_t;
105 
106 /*
107  * Menu related
108  * menu_cmd_t and menu_cmds must be kept in sync
109  *
110  * The *_DOLLAR_CMD values must be 1 greater than the
111  * respective [KERNEL|MODULE]_CMD values.
112  */
113 typedef enum {
114 	DEFAULT_CMD = 0,
115 	TIMEOUT_CMD,
116 	TITLE_CMD,
117 	ROOT_CMD,
118 	KERNEL_CMD,
119 	KERNEL_DOLLAR_CMD,	/* Must be KERNEL_CMD + 1 */
120 	MODULE_CMD,
121 	MODULE_DOLLAR_CMD,	/* Must be MODULE_CMD + 1 */
122 	SEP_CMD,
123 	COMMENT_CMD,
124 	CHAINLOADER_CMD,
125 	ARGS_CMD,
126 	FINDROOT_CMD,
127 	BOOTFS_CMD
128 } menu_cmd_t;
129 
130 extern char *menu_cmds[];
131 
132 /* For multi- or direct-boot */
133 typedef enum {
134 	BAM_DIRECT_NOT_SET,
135 	BAM_DIRECT_MULTIBOOT,
136 	BAM_DIRECT_DBOOT
137 } direct_or_multi_t;
138 
139 /* Is there a hypervisor present? */
140 typedef enum {
141 	BAM_HV_UNKNOWN,
142 	BAM_HV_NO,
143 	BAM_HV_PRESENT
144 } hv_t;
145 
146 /* Is there findroot capability present ? */
147 typedef enum {
148 	BAM_FINDROOT_UNKNOWN,
149 	BAM_FINDROOT_ABSENT,
150 	BAM_FINDROOT_PRESENT
151 } findroot_t;
152 
153 extern int bam_verbose;
154 extern int bam_force;
155 extern direct_or_multi_t bam_direct;
156 extern hv_t bam_is_hv;
157 extern findroot_t bam_is_findroot;
158 extern int bam_debug;
159 
160 extern void bam_add_line(menu_t *mp, entry_t *entry, line_t *prev, line_t *lp);
161 extern void update_numbering(menu_t *mp);
162 extern error_t set_global(menu_t *, char *, int);
163 extern error_t upgrade_menu(menu_t *, char *, char *);
164 extern error_t cvt_to_hyper(menu_t *, char *, char *);
165 extern error_t cvt_to_metal(menu_t *, char *, char *);
166 extern void *s_calloc(size_t, size_t);
167 extern void *s_realloc(void *, size_t);
168 extern char *s_fgets(char *buf, int n, FILE *fp);
169 extern void bam_error(char *format, ...);
170 extern void bam_exit(int);
171 extern void bam_print(char *, ...);
172 extern void bam_print_stderr(char *format, ...);
173 extern void bam_derror(char *format, ...);
174 extern error_t get_boot_cap(const char *osroot);
175 extern char *get_special(char *);
176 extern char *os_to_grubdisk(char *, int);
177 extern void update_line(line_t *);
178 extern int add_boot_entry(menu_t *, char *, char *, char *, char *, char *,
179     char *);
180 extern error_t delete_boot_entry(menu_t *, int, int);
181 extern int is_grub(const char *);
182 extern char *get_grubsign(char *osroot, char *osdev);
183 extern char *get_grubroot(char *osroot, char *osdev, char *menu_root);
184 extern int root_optional(char *osroot, char *menu_root);
185 extern void unlink_line(menu_t *mp, line_t *lp);
186 extern void line_free(line_t *lp);
187 extern char *s_strdup(char *);
188 extern int is_sparc(void);
189 
190 #define	BAM_MAXLINE	8192
191 
192 /* menu.lst comments created by bootadm */
193 #define	BAM_BOOTADM_HDR	"---------- ADDED BY BOOTADM - DO NOT EDIT ----------"
194 #define	BAM_BOOTADM_FTR	"---------------------END BOOTADM--------------------"
195 
196 /*
197  * menu.lst comments create by Live Upgrade.  Note that these are the end of
198  * the comment strings - there will be other text before them.
199  */
200 #define	BAM_LU_HDR	" - ADDED BY LIVE UPGRADE - DO NOT EDIT  -----"
201 #define	BAM_LU_FTR	" -------------- END LIVE UPGRADE ------------"
202 
203 #define	BAM_OLDDEF	"BOOTADM SAVED DEFAULT: "
204 #define	BAM_OLD_RC_DEF	"BOOTADM RC SAVED DEFAULT: "
205 
206 /* Title used for failsafe entries */
207 #define	FAILSAFE_TITLE	"Solaris failsafe"
208 
209 /* Title used for hv entries */
210 #define	NEW_HV_ENTRY	"Solaris xVM"
211 
212 /* ZFS boot option */
213 #define	ZFS_BOOT	"-B $ZFS-BOOTFS"
214 
215 /* multiboot */
216 #define	MULTI_BOOT	"/platform/i86pc/multiboot"
217 #define	MULTI_BOOT_FAILSAFE	"/boot/multiboot"
218 #define	MULTI_BOOT_FAILSAFE_UNIX	"kernel/unix"
219 #define	MULTI_BOOT_FAILSAFE_LINE	"/boot/multiboot kernel/unix -s"
220 
221 /* directboot kernels */
222 #define	DIRECT_BOOT_32	"/platform/i86pc/kernel/unix"
223 #define	DIRECT_BOOT_64	"/platform/i86pc/kernel/amd64/unix"
224 #define	DIRECT_BOOT_KERNEL	"/platform/i86pc/kernel/$ISADIR/unix"
225 #define	DIRECT_BOOT_FAILSAFE_32	"/boot/platform/i86pc/kernel/unix"
226 #define	DIRECT_BOOT_FAILSAFE_64	"/boot/platform/i86pc/kernel/amd64/unix"
227 #define	DIRECT_BOOT_FAILSAFE_KERNEL \
228 	"/boot/platform/i86pc/kernel/$ISADIR/unix"
229 #define	DIRECT_BOOT_FAILSAFE_LINE	DIRECT_BOOT_FAILSAFE_KERNEL " -s"
230 #define	DIRECT_BOOT_KERNEL_ZFS	DIRECT_BOOT_KERNEL " " ZFS_BOOT
231 #define	DIRECT_BOOT_PREFIX	"/platform/i86pc/"
232 #define	KERNEL_PREFIX	"/platform/i86pc/"
233 #define	AMD_UNIX_SPACE	"/amd64/unix "
234 #define	UNIX_SPACE	"/unix "
235 
236 /* xVM kernels */
237 #define	XEN_KERNEL_SUBSTR "xen.gz"
238 
239 /* Boot archives */
240 #define	ARCHIVE_PREFIX		"/platform/"
241 #define	ARCHIVE_SUFFIX		"/boot_archive"
242 #define	CACHEDIR_SUFFIX		"/archive_cache"
243 #define	UPDATEDIR_SUFFIX	"/updates"
244 #define	DIRECT_BOOT_ARCHIVE	"/platform/i86pc/$ISADIR/boot_archive"
245 #define	DIRECT_BOOT_ARCHIVE_32	"/platform/i86pc/boot_archive"
246 #define	DIRECT_BOOT_ARCHIVE_64	"/platform/i86pc/amd64/boot_archive"
247 #define	MULTIBOOT_ARCHIVE	DIRECT_BOOT_ARCHIVE_32
248 #define	FAILSAFE_ARCHIVE	"/boot/$ISADIR/x86.miniroot-safe"
249 #define	FAILSAFE_ARCHIVE_32	"/boot/x86.miniroot-safe"
250 #define	FAILSAFE_ARCHIVE_64	"/boot/amd64/x86.miniroot-safe"
251 #define	CACHEDIR_32		"/platform/i86pc/archive_cache"
252 #define	CACHEDIR_64		"/platform/i86pc/amd64/archive_cache"
253 #define	UPDATEDIR_32		"/platform/i86pc/updates"
254 #define	UPDATEDIR_64		"/platform/i86pc/amd64/updates"
255 
256 /* Hypervisors */
257 #define	XEN_64			"/boot/amd64/xen.gz"
258 #define	XEN_MENU		"/boot/$ISADIR/xen.gz"
259 #define	HYPERVISOR_KERNEL	"/platform/i86xpv/kernel/$ISADIR/unix"
260 #define	XEN_KERNEL_MODULE_LINE	HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL
261 #define	XEN_KERNEL_MODULE_LINE_ZFS	\
262 	HYPERVISOR_KERNEL " " HYPERVISOR_KERNEL " " ZFS_BOOT
263 
264 /* Helpers */
265 #define	MKISOFS_PATH		"/usr/bin/mkisofs"
266 #define	DD_PATH_USR		"/usr/bin/dd"
267 #define	LOCKFS_PATH		"/usr/sbin/lockfs"
268 
269 /* A first guess at the number of entries in a menu */
270 #define	BAM_ENTRY_NUM		10
271 
272 /* toggle for whether delete_boot_entry prints an error message or not */
273 #define	DBE_PRINTERR		0
274 #define	DBE_QUIET		1
275 
276 /*
277  * Debugging defines
278  */
279 #define	INJECT_ERROR1(x, y)	\
280 { \
281 	if (bam_debug) { \
282 		char *inj = getenv("_BOOTADM_INJECT"); \
283 		if (inj && strcmp(inj, (x)) == 0) {  \
284 			y;	\
285 		} \
286 	} \
287 }
288 
289 #define	INJECT_ERROR2(x, y, z)	\
290 { \
291 	if (bam_debug) { \
292 		char *inj = getenv("_BOOTADM_INJECT"); \
293 		if (inj && strcmp(inj, (x)) == 0) {  \
294 			y;	\
295 			z;	\
296 		} \
297 	} \
298 }
299 
300 #define	BAM_DPRINTF(x)	{if (bam_debug)  bam_derror x; }
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif	/* _BOOTADM_H */
307