Reamove grub support.
[unleashed.git] / usr / src / cmd / boot / bootadm / bootadm.h
blob92ed3b03f13410f7b20fc7c7e6215cdf5aae8fc4
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2016 Toomas Soome <tsoome@me.com>.
28 #ifndef _BOOTADM_H
29 #define _BOOTADM_H
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #include <assert.h>
36 #include <libintl.h>
38 #ifndef TEXT_DOMAIN
39 #define TEXT_DOMAIN "SUNW_OST_OSCMD"
40 #endif /* TEXT_DOMAIN */
42 #ifndef lint
43 #define _(x) gettext(x)
44 #else
45 #define _(x) (x)
46 #endif
48 /* Type definitions */
50 /* GRUB menu per-line classification */
51 typedef enum {
52 BAM_INVALID = 0,
53 BAM_EMPTY,
54 BAM_COMMENT,
55 BAM_GLOBAL,
56 BAM_ENTRY,
57 BAM_TITLE
58 } menu_flag_t;
60 /* struct for menu.lst contents */
61 typedef struct line {
62 int lineNum; /* Line number in menu.lst */
63 int entryNum; /* menu boot entry #. ENTRY_INIT if not applicable */
64 char *cmd;
65 char *sep;
66 char *arg;
67 char *line;
68 menu_flag_t flags;
69 struct line *next;
70 struct line *prev;
71 } line_t;
73 typedef enum {
74 BAM_ERROR = -1, /* Must be negative. add_boot_entry() depends on it */
75 BAM_SUCCESS = 0,
76 BAM_WRITE = 2,
77 BAM_MSG, /* Used by upgrade_menu() */
78 BAM_NOCHANGE /* Used by cvt_to_hyper()/cvt_to_metal() */
79 } error_t;
81 /* For multi- or direct-boot */
82 typedef enum {
83 BAM_DIRECT_NOT_SET,
84 BAM_DIRECT_MULTIBOOT,
85 BAM_DIRECT_DBOOT
86 } direct_or_multi_t;
88 /* Is there a hypervisor present? */
89 typedef enum {
90 BAM_HV_UNKNOWN,
91 BAM_HV_NO,
92 BAM_HV_PRESENT
93 } hv_t;
95 /* Is there findroot capability present ? */
96 typedef enum {
97 BAM_FINDROOT_UNKNOWN,
98 BAM_FINDROOT_ABSENT,
99 BAM_FINDROOT_PRESENT
100 } findroot_t;
102 typedef enum {
103 OPT_ABSENT = 0, /* No option */
104 OPT_REQ, /* option required */
105 OPT_OPTIONAL /* option may or may not be present */
106 } option_t;
108 typedef struct {
109 char *subcmd;
110 option_t option;
111 error_t (*handler)();
112 int unpriv; /* is this an unprivileged command */
113 } subcmd_defn_t;
115 typedef enum zfs_mnted {
116 ZFS_MNT_ERROR = -1,
117 LEGACY_MOUNTED = 1,
118 LEGACY_ALREADY,
119 ZFS_MOUNTED,
120 ZFS_ALREADY
121 } zfs_mnted_t;
123 extern int bam_verbose;
124 extern int bam_force;
125 extern direct_or_multi_t bam_direct;
126 extern hv_t bam_is_hv;
127 extern findroot_t bam_is_findroot;
128 extern int bam_debug;
130 extern error_t check_subcmd_and_options(char *, char *, subcmd_defn_t *,
131 error_t (**fp)());
132 extern char *mount_top_dataset(char *pool, zfs_mnted_t *mnted);
133 extern void elide_trailing_slash(const char *, char *, size_t);
134 extern int umount_top_dataset(char *, zfs_mnted_t, char *);
135 extern void *s_calloc(size_t, size_t);
136 extern void *s_realloc(void *, size_t);
137 extern char *s_fgets(char *buf, int n, FILE *fp);
138 extern void bam_error(char *format, ...);
139 extern void bam_exit(int);
140 extern void bam_print(char *, ...);
141 extern void bam_print_stderr(char *format, ...);
142 extern void bam_derror(char *format, ...);
143 extern error_t bam_loader_menu(char *, char *, int, char *[]);
144 extern error_t get_boot_cap(const char *osroot);
145 extern char *get_special(char *);
146 extern char *os_to_grubdisk(char *, int);
147 extern int is_grub(const char *);
148 extern char *s_strdup(char *);
149 extern int is_sparc(void);
150 extern int is_zfs(char *);
151 extern int bootadm_digest(const char *, char **);
153 #define BAM_MAXLINE 8192
155 /* menu.lst comments created by bootadm */
156 #define BAM_BOOTADM_HDR "---------- ADDED BY BOOTADM - DO NOT EDIT ----------"
157 #define BAM_BOOTADM_FTR "---------------------END BOOTADM--------------------"
160 * menu.lst comments create by Live Upgrade. Note that these are the end of
161 * the comment strings - there will be other text before them.
163 #define BAM_LU_HDR " - ADDED BY LIVE UPGRADE - DO NOT EDIT -----"
164 #define BAM_LU_FTR " -------------- END LIVE UPGRADE ------------"
166 #define BAM_OLDDEF "BOOTADM SAVED DEFAULT: "
167 #define BAM_OLD_RC_DEF "BOOTADM RC SAVED DEFAULT: "
169 /* Title used for hv entries */
170 #define NEW_HV_ENTRY "Solaris xVM"
172 /* ZFS boot option */
173 #define ZFS_BOOT "-B $ZFS-BOOTFS"
175 /* multiboot */
176 #define MULTI_BOOT "/platform/i86pc/multiboot"
177 #define MULTI_BOOT_FAILSAFE "/boot/multiboot"
178 #define MULTI_BOOT_FAILSAFE_UNIX "kernel/unix"
179 #define MULTI_BOOT_FAILSAFE_LINE "/boot/multiboot kernel/unix -s"
181 /* directboot kernels */
182 #define DIRECT_BOOT_32 "/platform/i86pc/kernel/unix"
183 #define DIRECT_BOOT_64 "/platform/i86pc/kernel/amd64/unix"
184 #define DIRECT_BOOT_KERNEL "/platform/i86pc/kernel/$ISADIR/unix"
185 #define DIRECT_BOOT_KERNEL_ZFS DIRECT_BOOT_KERNEL " " ZFS_BOOT
186 #define DIRECT_BOOT_PREFIX "/platform/i86pc/"
187 #define KERNEL_PREFIX "/platform/i86pc/"
188 #define AMD_UNIX_SPACE "/amd64/unix "
189 #define UNIX_SPACE "/unix "
191 /* xVM kernels */
192 #define XEN_KERNEL_SUBSTR "xen.gz"
194 /* Boot archives */
195 #define ARCHIVE_PREFIX "/platform/"
196 #define ARCHIVE_SUFFIX "/boot_archive"
197 #define CACHEDIR_SUFFIX "/archive_cache"
198 #define UPDATEDIR_SUFFIX "/updates"
199 #define DIRECT_BOOT_ARCHIVE "/platform/i86pc/$ISADIR/boot_archive"
200 #define DIRECT_BOOT_ARCHIVE_32 "/platform/i86pc/boot_archive"
201 #define DIRECT_BOOT_ARCHIVE_64 "/platform/i86pc/amd64/boot_archive"
202 #define MULTIBOOT_ARCHIVE DIRECT_BOOT_ARCHIVE_32
203 #define CACHEDIR_32 "/platform/i86pc/archive_cache"
204 #define CACHEDIR_64 "/platform/i86pc/amd64/archive_cache"
205 #define UPDATEDIR_32 "/platform/i86pc/updates"
206 #define UPDATEDIR_64 "/platform/i86pc/amd64/updates"
208 /* Hypervisors */
209 #define XEN_64 "/boot/amd64/xen.gz"
210 #define XEN_MENU "/boot/$ISADIR/xen.gz"
211 #define HYPERVISOR_KERNEL "/platform/i86xpv/kernel/$ISADIR/unix"
213 /* Helpers */
214 #define MKISOFS_PATH "/usr/bin/mkisofs"
215 #define DD_PATH_USR "/usr/bin/dd"
216 #define LOCKFS_PATH "/usr/sbin/lockfs"
218 /* A first guess at the number of entries in a menu */
219 #define BAM_ENTRY_NUM 10
221 /* toggle for whether delete_boot_entry prints an error message or not */
222 #define DBE_PRINTERR 0
223 #define DBE_QUIET 1
226 * Debugging defines
228 #define INJECT_ERROR1(x, y) \
230 if (bam_debug) { \
231 char *inj = getenv("_BOOTADM_INJECT"); \
232 if (inj && strcmp(inj, (x)) == 0) { \
233 y; \
238 #define INJECT_ERROR2(x, y, z) \
240 if (bam_debug) { \
241 char *inj = getenv("_BOOTADM_INJECT"); \
242 if (inj && strcmp(inj, (x)) == 0) { \
243 y; \
244 z; \
249 #define BAM_DPRINTF(x) {if (bam_debug) bam_derror x; }
251 #ifdef __cplusplus
253 #endif
255 #endif /* _BOOTADM_H */