xref: /titanic_41/usr/src/cmd/boot/bootadm/bootadm.h (revision 7e6639c297bb2c00e0c6dc8a83143d2201c6b51b)
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 2007 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 
82 typedef struct {
83 	line_t	*start;
84 	line_t	*end;
85 	line_t	*curdefault;	/* line containing default */
86 	line_t	*olddefault;	/* old default line (commented) */
87 	line_t	*old_rc_default;	/* old default line for bootenv.rc */
88 	entry_t	*entries;	/* os entries */
89 } menu_t;
90 
91 typedef enum {
92 	BAM_ERROR = -1,	/* Must be negative. add_boot_entry() depends on it */
93 	BAM_SUCCESS = 0,
94 	BAM_WRITE = 2,
95 	BAM_SKIP	/* Used by upgrade_menu() */
96 } error_t;
97 
98 /*
99  * Menu related
100  * menu_cmd_t and menu_cmds must be kept in sync
101  */
102 typedef enum {
103 	DEFAULT_CMD = 0,
104 	TIMEOUT_CMD,
105 	TITLE_CMD,
106 	ROOT_CMD,
107 	KERNEL_CMD,
108 	KERNEL_DOLLAR_CMD,
109 	MODULE_CMD,
110 	MODULE_DOLLAR_CMD,
111 	SEP_CMD,
112 	COMMENT_CMD,
113 	CHAINLOADER_CMD,
114 	ARGS_CMD
115 } menu_cmd_t;
116 
117 extern char *menu_cmds[];
118 
119 /* For multi- or direct-boot */
120 typedef enum {
121 	BAM_DIRECT_NOT_SET,
122 	BAM_DIRECT_MULTIBOOT,
123 	BAM_DIRECT_DBOOT
124 } direct_or_multi_t;
125 
126 extern int bam_verbose;
127 extern int bam_force;
128 extern direct_or_multi_t bam_direct;
129 
130 extern error_t upgrade_menu(menu_t *, char *, char *);
131 extern void *s_calloc(size_t, size_t);
132 extern void *s_realloc(void *, size_t);
133 extern char *s_fgets(char *buf, int n, FILE *fp);
134 extern void bam_error(char *format, ...);
135 extern void bam_print_stderr(char *format, ...);
136 extern error_t dboot_or_multiboot(const char *);
137 extern char *get_special(char *);
138 extern char *os_to_grubdisk(char *, int);
139 extern void update_line(line_t *);
140 
141 #define	BAM_MAXLINE	8192
142 
143 /* menu.lst comments created by bootadm */
144 #define	BAM_BOOTADM_HDR	"---------- ADDED BY BOOTADM - DO NOT EDIT ----------"
145 #define	BAM_BOOTADM_FTR	"---------------------END BOOTADM--------------------"
146 
147 /*
148  * menu.lst comments create by Live Upgrade.  Note that these are the end of
149  * the comment strings - there will be other text before them.
150  */
151 #define	BAM_LU_HDR	" - ADDED BY LIVE UPGRADE - DO NOT EDIT  -----"
152 #define	BAM_LU_FTR	" -------------- END LIVE UPGRADE ------------"
153 
154 #define	BAM_OLDDEF	"BOOTADM SAVED DEFAULT: "
155 #define	BAM_OLD_RC_DEF	"BOOTADM RC SAVED DEFAULT: "
156 
157 /* Title used for failsafe entries */
158 #define	FAILSAFE_TITLE	"Solaris failsafe"
159 
160 /* multiboot */
161 #define	MULTI_BOOT	"/platform/i86pc/multiboot"
162 #define	MULTI_BOOT_FAILSAFE	"/boot/multiboot"
163 #define	MULTI_BOOT_FAILSAFE_UNIX	"kernel/unix"
164 #define	MULTI_BOOT_FAILSAFE_LINE	"/boot/multiboot kernel/unix -s"
165 
166 /* directboot kernels */
167 #define	DIRECT_BOOT_32	"/platform/i86pc/kernel/unix"
168 #define	DIRECT_BOOT_64	"/platform/i86pc/kernel/amd64/unix"
169 #define	DIRECT_BOOT_KERNEL	"/platform/i86pc/kernel/$ISADIR/unix"
170 #define	DIRECT_BOOT_FAILSAFE_KERNEL	"/boot/platform/i86pc/kernel/unix"
171 #define	DIRECT_BOOT_FAILSAFE_LINE	DIRECT_BOOT_FAILSAFE_KERNEL " -s"
172 
173 /* Boot archives */
174 #define	DIRECT_BOOT_ARCHIVE	"/platform/i86pc/$ISADIR/boot_archive"
175 #define	DIRECT_BOOT_ARCHIVE_32	"/platform/i86pc/boot_archive"
176 #define	DIRECT_BOOT_ARCHIVE_64	"/platform/i86pc/amd64/boot_archive"
177 #define	MULTI_BOOT_ARCHIVE	DIRECT_BOOT_ARCHIVE_32
178 #define	MINIROOT	"/boot/x86.miniroot-safe"
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif	/* _BOOTADM_H */
185