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_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"
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 "
192 #define XEN_KERNEL_SUBSTR "xen.gz"
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"
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"
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
228 #define INJECT_ERROR1(x, y) \
231 char *inj = getenv("_BOOTADM_INJECT"); \
232 if (inj && strcmp(inj, (x)) == 0) { \
238 #define INJECT_ERROR2(x, y, z) \
241 char *inj = getenv("_BOOTADM_INJECT"); \
242 if (inj && strcmp(inj, (x)) == 0) { \
249 #define BAM_DPRINTF(x) {if (bam_debug) bam_derror x; }
255 #endif /* _BOOTADM_H */