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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2016 Toomas Soome <tsoome@me.com>.
39 #define TEXT_DOMAIN "SUNW_OST_OSCMD"
40 #endif /* TEXT_DOMAIN */
43 #define _(x) gettext(x)
48 /* Type definitions */
50 /* GRUB menu per-line classification */
60 /* struct for menu.lst contents */
62 int lineNum
; /* Line number in menu.lst */
63 int entryNum
; /* menu boot entry #. ENTRY_INIT if not applicable */
74 BAM_ERROR
= -1, /* Must be negative. add_boot_entry() depends on it */
77 BAM_MSG
, /* Used by upgrade_menu() */
78 BAM_NOCHANGE
/* Used by cvt_to_hyper()/cvt_to_metal() */
81 /* For multi- or direct-boot */
88 /* Is there a hypervisor present? */
95 /* Is there findroot capability present ? */
103 OPT_ABSENT
= 0, /* No option */
104 OPT_REQ
, /* option required */
105 OPT_OPTIONAL
/* option may or may not be present */
111 error_t (*handler
)();
112 int unpriv
; /* is this an unprivileged command */
115 typedef enum zfs_mnted
{
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
*,
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_zfs(char *);
151 #define BAM_MAXLINE 8192
153 /* menu.lst comments created by bootadm */
154 #define BAM_BOOTADM_HDR "---------- ADDED BY BOOTADM - DO NOT EDIT ----------"
155 #define BAM_BOOTADM_FTR "---------------------END BOOTADM--------------------"
158 * menu.lst comments create by Live Upgrade. Note that these are the end of
159 * the comment strings - there will be other text before them.
161 #define BAM_LU_HDR " - ADDED BY LIVE UPGRADE - DO NOT EDIT -----"
162 #define BAM_LU_FTR " -------------- END LIVE UPGRADE ------------"
164 #define BAM_OLDDEF "BOOTADM SAVED DEFAULT: "
165 #define BAM_OLD_RC_DEF "BOOTADM RC SAVED DEFAULT: "
167 /* Title used for hv entries */
168 #define NEW_HV_ENTRY "Solaris xVM"
170 /* ZFS boot option */
171 #define ZFS_BOOT "-B $ZFS-BOOTFS"
173 /* directboot kernels */
174 #define DIRECT_BOOT_32 "/platform/i86pc/kernel/unix"
175 #define DIRECT_BOOT_64 "/platform/i86pc/kernel/amd64/unix"
176 #define DIRECT_BOOT_KERNEL "/platform/i86pc/kernel/$ISADIR/unix"
177 #define DIRECT_BOOT_KERNEL_ZFS DIRECT_BOOT_KERNEL " " ZFS_BOOT
178 #define DIRECT_BOOT_PREFIX "/platform/i86pc/"
179 #define KERNEL_PREFIX "/platform/i86pc/"
180 #define AMD_UNIX_SPACE "/amd64/unix "
181 #define UNIX_SPACE "/unix "
184 #define ARCHIVE_PREFIX "/platform/"
185 #define ARCHIVE_SUFFIX "/boot_archive"
186 #define CACHEDIR_SUFFIX "/archive_cache"
188 /* A first guess at the number of entries in a menu */
189 #define BAM_ENTRY_NUM 10
191 /* toggle for whether delete_boot_entry prints an error message or not */
192 #define DBE_PRINTERR 0
198 #define INJECT_ERROR1(x, y) \
201 char *inj = getenv("_BOOTADM_INJECT"); \
202 if (inj && strcmp(inj, (x)) == 0) { \
208 #define INJECT_ERROR2(x, y, z) \
211 char *inj = getenv("_BOOTADM_INJECT"); \
212 if (inj && strcmp(inj, (x)) == 0) { \
219 #define BAM_DPRINTF(x) {if (bam_debug) bam_derror x; }
225 #endif /* _BOOTADM_H */