dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / boot / bootadm / bootadm.h
blob297a754ef86145e797d82348f3928ffd03a85c25
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_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 "
183 /* Boot archives */
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
193 #define DBE_QUIET 1
196 * Debugging defines
198 #define INJECT_ERROR1(x, y) \
200 if (bam_debug) { \
201 char *inj = getenv("_BOOTADM_INJECT"); \
202 if (inj && strcmp(inj, (x)) == 0) { \
203 y; \
208 #define INJECT_ERROR2(x, y, z) \
210 if (bam_debug) { \
211 char *inj = getenv("_BOOTADM_INJECT"); \
212 if (inj && strcmp(inj, (x)) == 0) { \
213 y; \
214 z; \
219 #define BAM_DPRINTF(x) {if (bam_debug) bam_derror x; }
221 #ifdef __cplusplus
223 #endif
225 #endif /* _BOOTADM_H */