diff options
Diffstat (limited to 'usr/src/cmd')
30 files changed, 4763 insertions, 2723 deletions
diff --git a/usr/src/cmd/Makefile b/usr/src/cmd/Makefile index b018c3ddfa..75d3758865 100644 --- a/usr/src/cmd/Makefile +++ b/usr/src/cmd/Makefile @@ -25,6 +25,7 @@ # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright (c) 2013 DEY Storage Systems, Inc. All rights reserved. # Copyright 2014 Garrett D'Amore <garrett@damore.org> +# Copyright 2016 Toomas Soome <tsoome@me.com> include ../Makefile.master @@ -157,6 +158,7 @@ COMMON_SUBDIRS= \ fdetach \ fdformat \ fdisk \ + ficl \ filesync \ fgrep \ file \ diff --git a/usr/src/cmd/boot/Makefile b/usr/src/cmd/boot/Makefile index c923fe599b..32f8c778d6 100644 --- a/usr/src/cmd/boot/Makefile +++ b/usr/src/cmd/boot/Makefile @@ -18,7 +18,7 @@ # # CDDL HEADER END # -# +# Copyright 2016 Toomas Soome <tsoome@me.com> # Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. # @@ -30,36 +30,36 @@ COMMON_SUBDIRS= \ filelist \ fiocompress \ scripts \ - bootadm + bootadm \ + installboot i386_SUBDIRS= \ installgrub \ mbr \ symdef -sparc_SUBDIRS= \ - installboot +sparc_SUBDIRS= COMMON_LINTSUBDIRS= \ - bootadm + bootadm \ + installboot i386_LINTSUBDIRS= \ fiocompress \ installgrub \ symdef -sparc_LINTSUBDIRS= \ - installboot +sparc_LINTSUBDIRS= COMMON_MSGSUBDIRS= \ bootadm \ - fiocompress + fiocompress \ + installboot i386_MSGSUBDIRS= \ installgrub -sparc_MSGSUBDIRS= \ - installboot +sparc_MSGSUBDIRS= all:= TARGET= all diff --git a/usr/src/cmd/boot/bootadm/Makefile b/usr/src/cmd/boot/bootadm/Makefile index 64616469be..40ad948ba2 100644 --- a/usr/src/cmd/boot/bootadm/Makefile +++ b/usr/src/cmd/boot/bootadm/Makefile @@ -30,22 +30,26 @@ PROG= bootadm SBINLINKS= $(PROG) -OBJS= bootadm.o bootadm_upgrade.o bootadm_hyper.o bootadm_digest.o +OBJS= bootadm.o bootadm_upgrade.o bootadm_hyper.o bootadm_digest.o \ + bootadm_loader.o SRCS = $(OBJS:.o=.c) +POFILES= $(OBJS:%.o=%.po) include ../Makefile.com +POFILE= bootadm_cmd.po .KEEP_STATE: LDLIBS_i386= -lfdisk -LDLIBS += -lpkcs11 -lcryptoutil -lnvpair -lgen -ladm -lefi -lscf -lz -lbe -lzfs $(LDLIBS_$(MACH)) +LDLIBS += -lficl-sys -lpkcs11 -lcryptoutil -lnvpair -lgen -ladm -lefi +LDLIBS += -lscf -lz -lbe -lzfs $(LDLIBS_$(MACH)) # Writing into string literals is incorrect. We need to match gcc's # behavior, which causes us to take SIGSEGV on such a write. CFLAGS += $(XSTRCONST) CPPFLAGS += -D_FILE_OFFSET_BITS=64 -CPPFLAGS += -I../../../uts/common -I../../../common +CPPFLAGS += -I$(SRC)/uts/common -I$(SRC)/common -I$(SRC)/common/ficl C99MODE= $(C99_ENABLE) @@ -61,10 +65,12 @@ $(PROG): $(OBJS) bootadm.h install: all $(ROOTSBINPROG) .WAIT $(ROOTUSRSBINLINKS) -clean: - -$(RM) $(OBJS) +$(POFILE): $(POFILES) + $(RM) $@ + $(CAT) $(POFILES) > $@ -_msg: +clean: + -$(RM) $(OBJS) $(POFILE) $(POFILES) lint: lint_SRCS diff --git a/usr/src/cmd/boot/bootadm/bootadm.c b/usr/src/cmd/boot/bootadm/bootadm.c index a5a1490a72..58c1a825ec 100644 --- a/usr/src/cmd/boot/bootadm/bootadm.c +++ b/usr/src/cmd/boot/bootadm/bootadm.c @@ -70,6 +70,7 @@ #include <sys/lockfs.h> #include <sys/filio.h> #include <libbe.h> +#include <deflt.h> #ifdef i386 #include <libfdisk.h> #endif @@ -87,7 +88,6 @@ #include <locale.h> #include <sys/mkdev.h> -#include "message.h" #include "bootadm.h" #ifndef TEXT_DOMAIN @@ -103,19 +103,6 @@ typedef enum { BAM_INSTALL } subcmd_t; -typedef enum { - OPT_ABSENT = 0, /* No option */ - OPT_REQ, /* option required */ - OPT_OPTIONAL /* option may or may not be present */ -} option_t; - -typedef struct { - char *subcmd; - option_t option; - error_t (*handler)(); - int unpriv; /* is this an unprivileged command */ -} subcmd_defn_t; - #define LINE_INIT 0 /* lineNum initial value */ #define ENTRY_INIT -1 /* entryNum initial value */ #define ALL_ENTRIES -2 /* selects all boot entries */ @@ -139,6 +126,10 @@ typedef struct { #define UFS_SIGNATURE_LIST "/var/run/grub_ufs_signatures" #define ZFS_LEGACY_MNTPT "/tmp/bootadm_mnt_zfs_legacy" +/* BE defaults */ +#define BE_DEFAULTS "/etc/default/be" +#define BE_DFLT_BE_HAS_GRUB "BE_HAS_GRUB=" + #define BOOTADM_RDONLY_TEST "BOOTADM_RDONLY_TEST" /* lock related */ @@ -165,14 +156,6 @@ typedef struct { #define STAGE1 "/boot/grub/stage1" #define STAGE2 "/boot/grub/stage2" -typedef enum zfs_mnted { - ZFS_MNT_ERROR = -1, - LEGACY_MOUNTED = 1, - LEGACY_ALREADY, - ZFS_MOUNTED, - ZFS_ALREADY -} zfs_mnted_t; - /* * Default file attributes */ @@ -228,10 +211,10 @@ int bam_force; int bam_debug; static char *prog; static subcmd_t bam_cmd; -static char *bam_root; -static int bam_rootlen; +char *bam_root; +int bam_rootlen; static int bam_root_readonly; -static int bam_alt_root; +int bam_alt_root; static int bam_extend = 0; static int bam_purge = 0; static char *bam_subcmd; @@ -245,7 +228,7 @@ static int bam_smf_check; static int bam_lock_fd = -1; static int bam_zfs; static int bam_mbr; -static char rootbuf[PATH_MAX] = "/"; +char rootbuf[PATH_MAX] = "/"; static int bam_update_all; static int bam_alt_platform; static char *bam_platform; @@ -289,14 +272,10 @@ static char *expand_path(const char *); static long s_strtol(char *); static int s_fputs(char *, FILE *); -static int is_zfs(char *root); static int is_ufs(char *root); -static int is_pcfs(char *root); static int is_amd64(void); static char *get_machine(void); static void append_to_flist(filelist_t *, char *); -static char *mount_top_dataset(char *pool, zfs_mnted_t *mnted); -static int umount_top_dataset(char *pool, zfs_mnted_t mnted, char *mntpt); static int ufs_add_to_sign_list(char *sign); static error_t synchronize_BE_menu(void); @@ -556,7 +535,13 @@ main(int argc, char *argv[]) switch (bam_cmd) { case BAM_MENU: - ret = bam_menu(bam_subcmd, bam_opt, bam_argc, bam_argv); + if (is_grub(bam_alt_root ? bam_root : "/")) { + ret = bam_menu(bam_subcmd, bam_opt, + bam_argc, bam_argv); + } else { + ret = bam_loader_menu(bam_subcmd, bam_opt, + bam_argc, bam_argv); + } break; case BAM_ARCHIVE: ret = bam_archive(bam_subcmd, bam_opt); @@ -672,7 +657,8 @@ parse_args_internal(int argc, char *argv[]) case 'a': if (bam_cmd) { error = 1; - bam_error(MULT_CMDS, c); + bam_error( + _("multiple commands specified: -%c\n"), c); } bam_cmd = BAM_ARCHIVE; bam_subcmd = optarg; @@ -680,7 +666,8 @@ parse_args_internal(int argc, char *argv[]) case 'd': if (bam_debug) { error = 1; - bam_error(DUP_OPT, c); + bam_error( + _("duplicate options specified: -%c\n"), c); } bam_debug = s_strtol(optarg); break; @@ -693,7 +680,8 @@ parse_args_internal(int argc, char *argv[]) case 'i': if (bam_cmd) { error = 1; - bam_error(MULT_CMDS, c); + bam_error( + _("multiple commands specified: -%c\n"), c); } bam_cmd = BAM_INSTALL; bam_subcmd = optarg; @@ -701,7 +689,8 @@ parse_args_internal(int argc, char *argv[]) case 'm': if (bam_cmd) { error = 1; - bam_error(MULT_CMDS, c); + bam_error( + _("multiple commands specified: -%c\n"), c); } bam_cmd = BAM_MENU; bam_subcmd = optarg; @@ -728,7 +717,8 @@ parse_args_internal(int argc, char *argv[]) case 'o': if (bam_opt) { error = 1; - bam_error(DUP_OPT, c); + bam_error( + _("duplicate options specified: -%c\n"), c); } bam_opt = optarg; break; @@ -741,19 +731,21 @@ parse_args_internal(int argc, char *argv[]) case 'P': if (bam_pool != NULL) { error = 1; - bam_error(DUP_OPT, c); + bam_error( + _("duplicate options specified: -%c\n"), c); } bam_pool = optarg; break; case 'R': if (bam_root) { error = 1; - bam_error(DUP_OPT, c); + bam_error( + _("duplicate options specified: -%c\n"), c); break; } else if (realpath(optarg, rootbuf) == NULL) { error = 1; - bam_error(CANT_RESOLVE, optarg, - strerror(errno)); + bam_error(_("cannot resolve path %s: %s\n"), + optarg, strerror(errno)); break; } bam_alt_root = 1; @@ -767,7 +759,9 @@ parse_args_internal(int argc, char *argv[]) (strcmp(bam_platform, "sun4u") != 0) && (strcmp(bam_platform, "sun4v") != 0)) { error = 1; - bam_error(INVALID_PLAT, bam_platform); + bam_error(_("invalid platform %s - must be " + "one of sun4u, sun4v or i86pc\n"), + bam_platform); } break; case 'X': @@ -781,11 +775,13 @@ parse_args_internal(int argc, char *argv[]) break; case '?': error = 1; - bam_error(BAD_OPT, optopt); + bam_error(_("invalid option or missing option " + "argument: -%c\n"), optopt); break; default : error = 1; - bam_error(BAD_OPT, c); + bam_error(_("invalid option or missing option " + "argument: -%c\n"), c); break; } } @@ -806,7 +802,7 @@ parse_args_internal(int argc, char *argv[]) usage(); bam_exit(0); } - bam_error(NEED_CMD); + bam_error(_("a command option must be specified\n")); error = 1; } @@ -816,7 +812,7 @@ parse_args_internal(int argc, char *argv[]) } if (optind > argc) { - bam_error(INT_ERROR, "parse_args"); + bam_error(_("Internal error: %s\n"), "parse_args"); bam_exit(1); } else if (optind < argc) { bam_argv = &argv[optind]; @@ -838,7 +834,7 @@ parse_args_internal(int argc, char *argv[]) bam_verbose = 1; } -static error_t +error_t check_subcmd_and_options( char *subcmd, char *opt, @@ -848,17 +844,17 @@ check_subcmd_and_options( int i; if (subcmd == NULL) { - bam_error(NEED_SUBCMD); + bam_error(_("this command requires a sub-command\n")); return (BAM_ERROR); } if (strcmp(subcmd, "set_option") == 0) { if (bam_argc == 0 || bam_argv == NULL || bam_argv[0] == NULL) { - bam_error(MISSING_ARG); + bam_error(_("missing argument for sub-command\n")); usage(); return (BAM_ERROR); } else if (bam_argc > 1 || bam_argv[1] != NULL) { - bam_error(TRAILING_ARGS); + bam_error(_("invalid trailing arguments\n")); usage(); return (BAM_ERROR); } @@ -869,7 +865,7 @@ check_subcmd_and_options( */ if (bam_argc > 1 || (bam_argc == 1 && strcmp(bam_argv[0], "fastboot") != 0)) { - bam_error(TRAILING_ARGS); + bam_error(_("invalid trailing arguments\n")); usage(); return (BAM_ERROR); } @@ -881,7 +877,7 @@ check_subcmd_and_options( * Of the remaining subcommands, only "enable_hypervisor" and * "list_setting" take trailing arguments. */ - bam_error(TRAILING_ARGS); + bam_error(_("invalid trailing arguments\n")); usage(); return (BAM_ERROR); } @@ -898,12 +894,12 @@ check_subcmd_and_options( } if (table[i].subcmd == NULL) { - bam_error(INVALID_SUBCMD, subcmd); + bam_error(_("invalid sub-command specified: %s\n"), subcmd); return (BAM_ERROR); } if (table[i].unpriv == 0 && geteuid() != 0) { - bam_error(MUST_BE_ROOT); + bam_error(_("you must be root to run this command\n")); return (BAM_ERROR); } @@ -917,9 +913,11 @@ check_subcmd_and_options( if (table[i].option != OPT_OPTIONAL) { if ((table[i].option == OPT_REQ) ^ (opt != NULL)) { if (opt) - bam_error(NO_OPT_REQ, subcmd); + bam_error(_("this sub-command (%s) does not " + "take options\n"), subcmd); else - bam_error(MISS_OPT, subcmd); + bam_error(_("an option is required for this " + "sub-command: %s\n"), subcmd); return (BAM_ERROR); } } @@ -933,7 +931,7 @@ check_subcmd_and_options( * NOTE: A single "/" is also considered a trailing slash and will * be deleted. */ -static void +void elide_trailing_slash(const char *src, char *dst, size_t dstsize) { size_t dstlen; @@ -955,22 +953,25 @@ is_safe_exec(char *path) struct stat sb; if (lstat(path, &sb) != 0) { - bam_error(STAT_FAIL, path, strerror(errno)); + bam_error(_("stat of file failed: %s: %s\n"), path, + strerror(errno)); return (BAM_ERROR); } if (!S_ISREG(sb.st_mode)) { - bam_error(PATH_EXEC_LINK, path); + bam_error(_("%s is not a regular file, skipping\n"), path); return (BAM_ERROR); } if (sb.st_uid != getuid()) { - bam_error(PATH_EXEC_OWNER, path, getuid()); + bam_error(_("%s is not owned by %d, skipping\n"), + path, getuid()); return (BAM_ERROR); } if (sb.st_mode & S_IWOTH || sb.st_mode & S_IWGRP) { - bam_error(PATH_EXEC_PERMS, path); + bam_error(_("%s is others or group writable, skipping\n"), + path); return (BAM_ERROR); } @@ -1014,7 +1015,7 @@ list_setting(menu_t *mp, char *which, char *setting) ; if (!ent) { - bam_error(NO_MATCH_ENTRY); + bam_error(_("no matching entry found\n")); return (BAM_ERROR); } @@ -1022,9 +1023,9 @@ list_setting(menu_t *mp, char *which, char *setting) for (lp = ent->start; lp != NULL; lp = lp->next) { if ((*setting == NULL) && (lp->flags != BAM_COMMENT)) - bam_print(PRINT, lp->line); + bam_print("%s\n", lp->line); else if (lp->cmd != NULL && strcmp(setting, lp->cmd) == 0) { - bam_print(PRINT, lp->arg); + bam_print("%s\n", lp->arg); found = 1; } @@ -1033,7 +1034,7 @@ list_setting(menu_t *mp, char *which, char *setting) } if (!found) { - bam_error(NO_MATCH_ENTRY); + bam_error(_("no matching entry found\n")); return (BAM_ERROR); } @@ -1069,11 +1070,13 @@ install_bootloader(void) if (bam_alt_root) { if (stat(bam_root, &statbuf) != 0) { - bam_error(STAT_FAIL, bam_root, strerror(errno)); + bam_error(_("stat of file failed: %s: %s\n"), bam_root, + strerror(errno)); goto done; } if ((fp = fopen(MNTTAB, "r")) == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + MNTTAB, strerror(errno)); goto done; } resetmnttab(fp); @@ -1088,7 +1091,8 @@ install_bootloader(void) (void) fclose(fp); if (found == 0) { - bam_error(NOT_IN_MNTTAB, bam_root); + bam_error(_("alternate root %s not in mnttab\n"), + bam_root); goto done; } if (root_ds == NULL) { @@ -1197,7 +1201,8 @@ install_bootloader(void) * get dataset for "/" and fill up the args. */ if ((fp = fopen(MNTTAB, "r")) == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + MNTTAB, strerror(errno)); ret = BAM_ERROR; be_free_list(be_nodes); goto done; @@ -1214,7 +1219,7 @@ install_bootloader(void) (void) fclose(fp); if (found == 0) { - bam_error(NOT_IN_MNTTAB, "/"); + bam_error(_("alternate root %s not in mnttab\n"), "/"); ret = BAM_ERROR; be_free_list(be_nodes); goto done; @@ -1293,7 +1298,8 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) * Menu sub-command only applies to GRUB (i.e. x86) */ if (!is_grub(bam_alt_root ? bam_root : "/")) { - bam_error(NOT_GRUB_BOOT); + bam_error(_("not a GRUB 0.97 based Illumos instance. " + "Operation not supported\n")); return (BAM_ERROR); } @@ -1319,8 +1325,8 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) if (osroot) { /* fixup bam_root so that it points at osroot */ if (realpath(osroot, rootbuf) == NULL) { - bam_error(CANT_RESOLVE, osroot, - strerror(errno)); + bam_error(_("cannot resolve path %s: %s\n"), + osroot, strerror(errno)); return (BAM_ERROR); } bam_alt_root = 1; @@ -1334,16 +1340,16 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) * not the OS root */ if (is_pcfs(bam_root)) { - bam_error(PCFS_ROOT_NOTSUP, bam_root); + bam_error(_("root <%s> on PCFS is not supported\n"), bam_root); return (BAM_ERROR); } if (stat(menu_root, &sb) == -1) { - bam_error(CANNOT_LOCATE_GRUB_MENU); + bam_error(_("cannot find GRUB menu\n")); return (BAM_ERROR); } - BAM_DPRINTF((D_MENU_ROOT, fcn, menu_root)); + BAM_DPRINTF(("%s: menu root is %s\n", fcn, menu_root)); /* * We no longer use the GRUB slice file. If it exists, then @@ -1360,56 +1366,61 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) } if (bam_verbose && stat(path, &sb) == 0) - bam_error(GRUB_SLICE_FILE_EXISTS, path); + bam_error(_("unsupported GRUB slice file (%s) exists - " + "ignoring.\n"), path); if (is_zfs(menu_root)) { assert(strcmp(menu_root, bam_root) == 0); special = get_special(menu_root); INJECT_ERROR1("Z_MENU_GET_SPECIAL", special = NULL); if (special == NULL) { - bam_error(CANT_FIND_SPECIAL, menu_root); + bam_error(_("cant find special file for " + "mount-point %s\n"), menu_root); return (BAM_ERROR); } pool = strtok(special, "/"); INJECT_ERROR1("Z_MENU_GET_POOL", pool = NULL); if (pool == NULL) { free(special); - bam_error(CANT_FIND_POOL, menu_root); + bam_error(_("cant find pool for mount-point %s\n"), + menu_root); return (BAM_ERROR); } - BAM_DPRINTF((D_Z_MENU_GET_POOL_FROM_SPECIAL, fcn, pool)); + BAM_DPRINTF(("%s: derived pool=%s from special\n", fcn, pool)); zmntpt = mount_top_dataset(pool, &zmnted); INJECT_ERROR1("Z_MENU_MOUNT_TOP_DATASET", zmntpt = NULL); if (zmntpt == NULL) { - bam_error(CANT_MOUNT_POOL_DATASET, pool); + bam_error(_("cannot mount pool dataset for pool: %s\n"), + pool); free(special); return (BAM_ERROR); } - BAM_DPRINTF((D_Z_GET_MENU_MOUNT_TOP_DATASET, fcn, zmntpt)); + BAM_DPRINTF(("%s: top dataset mountpoint=%s\n", fcn, zmntpt)); (void) strlcpy(menu_root, zmntpt, sizeof (menu_root)); - BAM_DPRINTF((D_Z_GET_MENU_MENU_ROOT, fcn, menu_root)); + BAM_DPRINTF(("%s: zfs menu_root=%s\n", fcn, menu_root)); } elide_trailing_slash(menu_root, clean_menu_root, sizeof (clean_menu_root)); - BAM_DPRINTF((D_CLEAN_MENU_ROOT, fcn, clean_menu_root)); + BAM_DPRINTF(("%s: cleaned menu root is <%s>\n", fcn, clean_menu_root)); (void) strlcpy(menu_path, clean_menu_root, sizeof (menu_path)); (void) strlcat(menu_path, GRUB_MENU, sizeof (menu_path)); - BAM_DPRINTF((D_MENU_PATH, fcn, menu_path)); + BAM_DPRINTF(("%s: menu path is: %s\n", fcn, menu_path)); /* * If listing the menu, display the menu location */ if (strcmp(subcmd, "list_entry") == 0) - bam_print(GRUB_MENU_PATH, menu_path); + bam_print(_("the location for the active GRUB menu is: %s\n"), + menu_path); if ((menu = menu_read(menu_path)) == NULL) { - bam_error(CANNOT_LOCATE_GRUB_MENU_FILE, menu_path); + bam_error(_("cannot find GRUB menu file: %s\n"), menu_path); free(special); return (BAM_ERROR); @@ -1430,7 +1441,7 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) ret = get_boot_cap(bam_root); if (ret != BAM_SUCCESS) { - BAM_DPRINTF((D_BOOT_GET_CAP_FAILED, fcn)); + BAM_DPRINTF(("%s: Failed to get boot capability\n", fcn)); goto out; } @@ -1449,14 +1460,16 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) ((largc > 1) ? largv[1] : "")); } else if (strcmp(subcmd, "disable_hypervisor") == 0) { if (is_sparc()) { - bam_error(NO_SPARC, subcmd); + bam_error(_("%s operation unsupported on SPARC " + "machines\n"), subcmd); ret = BAM_ERROR; } else { ret = f(menu, bam_root, NULL); } } else if (strcmp(subcmd, "enable_hypervisor") == 0) { if (is_sparc()) { - bam_error(NO_SPARC, subcmd); + bam_error(_("%s operation unsupported on SPARC " + "machines\n"), subcmd); ret = BAM_ERROR; } else { char *extra_args = NULL; @@ -1503,7 +1516,8 @@ bam_menu(char *subcmd, char *opt, int largc, char *largv[]) ret = f(menu, NULL, opt); if (ret == BAM_WRITE) { - BAM_DPRINTF((D_WRITING_MENU_ROOT, fcn, clean_menu_root)); + BAM_DPRINTF(("%s: writing menu to clean-menu-root: <%s>\n", + fcn, clean_menu_root)); ret = menu_write(clean_menu_root, menu); } @@ -1545,7 +1559,7 @@ bam_archive( ret = get_boot_cap(rootbuf); if (ret != BAM_SUCCESS) { - BAM_DPRINTF((D_BOOT_GET_CAP_FAILED, fcn)); + BAM_DPRINTF(("%s: Failed to get boot capability\n", fcn)); return (ret); } @@ -1555,7 +1569,8 @@ bam_archive( * information for each BE. */ if (bam_check && strcmp(subcmd, "update_all") == 0) { - bam_error(CHECK_NOT_SUPPORTED, subcmd); + bam_error(_("the check option is not supported with " + "subcmd: %s\n"), subcmd); return (BAM_ERROR); } @@ -1647,7 +1662,8 @@ bam_lock(void) return; } - bam_error(OPEN_FAIL, BAM_LOCK_FILE, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + BAM_LOCK_FILE, strerror(errno)); bam_exit(1); } @@ -1658,21 +1674,25 @@ bam_lock(void) if (fcntl(bam_lock_fd, F_SETLK, &lock) == -1) { if (errno != EACCES && errno != EAGAIN) { - bam_error(LOCK_FAIL, BAM_LOCK_FILE, strerror(errno)); + bam_error(_("failed to lock file: %s: %s\n"), + BAM_LOCK_FILE, strerror(errno)); (void) close(bam_lock_fd); bam_lock_fd = -1; bam_exit(1); } pid = 0; (void) pread(bam_lock_fd, &pid, sizeof (pid_t), 0); - bam_print(FILE_LOCKED, pid); + bam_print( + _("another instance of bootadm (pid %lu) is running\n"), + pid); lock.l_type = F_WRLCK; lock.l_whence = SEEK_SET; lock.l_start = 0; lock.l_len = 0; if (fcntl(bam_lock_fd, F_SETLKW, &lock) == -1) { - bam_error(LOCK_FAIL, BAM_LOCK_FILE, strerror(errno)); + bam_error(_("failed to lock file: %s: %s\n"), + BAM_LOCK_FILE, strerror(errno)); (void) close(bam_lock_fd); bam_lock_fd = -1; bam_exit(1); @@ -1702,11 +1722,13 @@ bam_unlock(void) unlock.l_len = 0; if (fcntl(bam_lock_fd, F_SETLK, &unlock) == -1) { - bam_error(UNLOCK_FAIL, BAM_LOCK_FILE, strerror(errno)); + bam_error(_("failed to unlock file: %s: %s\n"), + BAM_LOCK_FILE, strerror(errno)); } if (close(bam_lock_fd) == -1) { - bam_error(CLOSE_FAIL, BAM_LOCK_FILE, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + BAM_LOCK_FILE, strerror(errno)); } bam_lock_fd = -1; } @@ -1728,7 +1750,7 @@ list_archive(char *root, char *opt) assert(flistp->head && flistp->tail); for (lp = flistp->head; lp; lp = lp->next) { - bam_print(PRINT, lp->line); + bam_print(_("%s\n"), lp->line); } filelist_free(flistp); @@ -1760,9 +1782,11 @@ list2file(char *root, char *tmp, char *final, line_t *start) if (start == NULL) { /* Empty GRUB menu */ if (stat(path, &sb) != -1) { - bam_print(UNLINK_EMPTY, path); + bam_print(_("file is empty, deleting file: %s\n"), + path); if (unlink(path) != 0) { - bam_error(UNLINK_FAIL, path, strerror(errno)); + bam_error(_("failed to unlink file: %s: %s\n"), + path, strerror(errno)); return (BAM_ERROR); } else { return (BAM_SUCCESS); @@ -1785,14 +1809,16 @@ list2file(char *root, char *tmp, char *final, line_t *start) if ((pw = getpwnam(DEFAULT_DEV_USER)) != NULL) { root_uid = pw->pw_uid; } else { - bam_error(CANT_FIND_USER, + bam_error(_("getpwnam: uid for %s failed, " + "defaulting to %d\n"), DEFAULT_DEV_USER, DEFAULT_DEV_UID); root_uid = (uid_t)DEFAULT_DEV_UID; } if ((gp = getgrnam(DEFAULT_DEV_GROUP)) != NULL) { sys_gid = gp->gr_gid; } else { - bam_error(CANT_FIND_GROUP, + bam_error(_("getgrnam: gid for %s failed, " + "defaulting to %d\n"), DEFAULT_DEV_GROUP, DEFAULT_DEV_GID); sys_gid = (gid_t)DEFAULT_DEV_GID; } @@ -1803,20 +1829,23 @@ list2file(char *root, char *tmp, char *final, line_t *start) /* Truncate tmpfile first */ fp = fopen(tmpfile, "w"); if (fp == NULL) { - bam_error(OPEN_FAIL, tmpfile, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), tmpfile, + strerror(errno)); return (BAM_ERROR); } ret = fclose(fp); INJECT_ERROR1("LIST2FILE_TRUNC_FCLOSE", ret = EOF); if (ret == EOF) { - bam_error(CLOSE_FAIL, tmpfile, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + tmpfile, strerror(errno)); return (BAM_ERROR); } /* Now open it in append mode */ fp = fopen(tmpfile, "a"); if (fp == NULL) { - bam_error(OPEN_FAIL, tmpfile, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), tmpfile, + strerror(errno)); return (BAM_ERROR); } @@ -1824,7 +1853,8 @@ list2file(char *root, char *tmp, char *final, line_t *start) ret = s_fputs(start->line, fp); INJECT_ERROR1("LIST2FILE_FPUTS", ret = EOF); if (ret == EOF) { - bam_error(WRITE_FAIL, tmpfile, strerror(errno)); + bam_error(_("write to file failed: %s: %s\n"), + tmpfile, strerror(errno)); (void) fclose(fp); return (BAM_ERROR); } @@ -1833,7 +1863,8 @@ list2file(char *root, char *tmp, char *final, line_t *start) ret = fclose(fp); INJECT_ERROR1("LIST2FILE_APPEND_FCLOSE", ret = EOF); if (ret == EOF) { - bam_error(CLOSE_FAIL, tmpfile, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + tmpfile, strerror(errno)); return (BAM_ERROR); } @@ -1845,14 +1876,16 @@ list2file(char *root, char *tmp, char *final, line_t *start) ret = chmod(tmpfile, mode); if (ret == -1 && errno != EINVAL && errno != ENOTSUP) { - bam_error(CHMOD_FAIL, tmpfile, strerror(errno)); + bam_error(_("chmod operation on %s failed - %s\n"), + tmpfile, strerror(errno)); return (BAM_ERROR); } ret = chown(tmpfile, root_uid, sys_gid); if (ret == -1 && errno != EINVAL && errno != ENOTSUP) { - bam_error(CHOWN_FAIL, tmpfile, strerror(errno)); + bam_error(_("chgrp operation on %s failed - %s\n"), + tmpfile, strerror(errno)); return (BAM_ERROR); } @@ -1862,11 +1895,12 @@ list2file(char *root, char *tmp, char *final, line_t *start) ret = rename(tmpfile, path); INJECT_ERROR1("LIST2FILE_RENAME", ret = -1); if (ret != 0) { - bam_error(RENAME_FAIL, path, strerror(errno)); + bam_error(_("rename to file failed: %s: %s\n"), path, + strerror(errno)); return (BAM_ERROR); } - BAM_DPRINTF((D_WROTE_FILE, fcn, path)); + BAM_DPRINTF(("%s: wrote file successfully: %s\n", fcn, path)); return (BAM_SUCCESS); } @@ -1889,10 +1923,12 @@ setup_path(char *path) /* best effort attempt, mkdirp will catch the error */ (void) unlink(path); if (bam_verbose) - bam_print(NEED_DIRPATH, path); + bam_print(_("need to create directory " + "path for %s\n"), path); ret = mkdirp(path, DIR_PERMS); if (ret == -1) { - bam_error(MKDIR_FAILED, path, strerror(errno)); + bam_error(_("mkdir of %s failed: %s\n"), + path, strerror(errno)); *p = '/'; return (BAM_ERROR); } @@ -1930,7 +1966,8 @@ setup_file(char *base, const char *path, cachefile *cf) ret = snprintf(cf->path, sizeof (cf->path), "%s/%s", base, strip); if (ret >= sizeof (cf->path)) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } @@ -1940,7 +1977,8 @@ setup_file(char *base, const char *path, cachefile *cf) if (bam_direct == BAM_DIRECT_DBOOT) { if ((cf->out.gzfile = gzopen(cf->path, "wb")) == NULL) { - bam_error(OPEN_FAIL, cf->path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + cf->path, strerror(errno)); return (BAM_ERROR); } (void) gzsetparams(cf->out.gzfile, Z_BEST_SPEED, @@ -1948,7 +1986,8 @@ setup_file(char *base, const char *path, cachefile *cf) } else { if ((cf->out.fdfile = open(cf->path, O_WRONLY | O_CREAT, 0644)) == -1) { - bam_error(OPEN_FAIL, cf->path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + cf->path, strerror(errno)); return (BAM_ERROR); } } @@ -1963,15 +2002,18 @@ cache_write(cachefile cf, char *buf, int size) if (bam_direct == BAM_DIRECT_DBOOT) { if (gzwrite(cf.out.gzfile, buf, size) < 1) { - bam_error(GZ_WRITE_FAIL, gzerror(cf.out.gzfile, &err)); + bam_error(_("failed to write to %s\n"), + gzerror(cf.out.gzfile, &err)); if (err == Z_ERRNO && bam_verbose) { - bam_error(WRITE_FAIL, cf.path, strerror(errno)); + bam_error(_("write to file failed: %s: %s\n"), + cf.path, strerror(errno)); } return (BAM_ERROR); } } else { if (write(cf.out.fdfile, buf, size) < 1) { - bam_error(WRITE_FAIL, cf.path, strerror(errno)); + bam_error(_("write to file failed: %s: %s\n"), + cf.path, strerror(errno)); return (BAM_ERROR); } } @@ -1987,7 +2029,8 @@ cache_close(cachefile cf) if (cf.out.gzfile) { ret = gzclose(cf.out.gzfile); if (ret != Z_OK) { - bam_error(CLOSE_FAIL, cf.path, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + cf.path, strerror(errno)); return (BAM_ERROR); } } @@ -1995,7 +2038,8 @@ cache_close(cachefile cf) if (cf.out.fdfile != -1) { ret = close(cf.out.fdfile); if (ret != 0) { - bam_error(CLOSE_FAIL, cf.path, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + cf.path, strerror(errno)); return (BAM_ERROR); } } @@ -2021,7 +2065,8 @@ dircache_updatefile(const char *path, int what) return (BAM_SUCCESS); if ((infile = fopen(path, "rb")) == NULL) { - bam_error(OPEN_FAIL, path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), path, + strerror(errno)); return (BAM_ERROR); } @@ -2077,7 +2122,8 @@ dircache_updatedir(const char *path, int what, int updt) get_updatedir(what) : get_cachedir(what), strip); if (ret >= sizeof (dpath)) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); set_flag(UPDATE_ERROR); return (BAM_ERROR); } @@ -2124,7 +2170,8 @@ update_dircache(const char *path, int flags) _elfhdr elf; if ((fd = open(path, O_RDONLY)) < 0) { - bam_error(OPEN_FAIL, path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + path, strerror(errno)); set_flag(UPDATE_ERROR); rc = BAM_ERROR; break; @@ -2136,7 +2183,8 @@ update_dircache(const char *path, int flags) * _FILE_OFFSET_BITS is != 32 ... */ if (read(fd, (void *)&elf, sizeof (_elfhdr)) < 0) { - bam_error(READ_FAIL, path, strerror(errno)); + bam_error(_("read failed for file: %s: %s\n"), + path, strerror(errno)); set_flag(UPDATE_ERROR); (void) close(fd); rc = BAM_ERROR; @@ -2167,7 +2215,8 @@ update_dircache(const char *path, int flags) } else if (elf.e_ident[EI_CLASS] == ELFCLASS64) { rc = dircache_updatefile(path, FILE64); } else { - bam_print(NO3264ELF, path); + bam_print(_("WARNING: file %s is neither a " + "32-bit nor a 64-bit ELF\n"), path); /* paranoid */ rc = dircache_updatefile(path, FILE32); if (rc == BAM_SUCCESS) @@ -2241,7 +2290,8 @@ cmpstat( error = nvlist_add_uint64_array(walk_arg.new_nvlp, file + bam_rootlen, filestat, 2); if (error) - bam_error(NVADD_FAIL, file, strerror(error)); + bam_error(_("failed to update stat data for: %s: %s\n"), + file, strerror(error)); } /* @@ -2296,7 +2346,7 @@ cmpstat( */ if (is_flag_on(NEED_CACHE_DIR)) { if (bam_verbose) - bam_print(PARSEABLE_NEW_FILE, file); + bam_print(_(" new %s\n"), file); if (is_flag_on(IS_SPARC_TARGET)) { set_dir_flag(FILE64, NEED_UPDATE); @@ -2305,7 +2355,8 @@ cmpstat( ret = update_dircache(file, flags); if (ret == BAM_ERROR) { - bam_error(UPDT_CACHE_FAIL, file); + bam_error(_("directory cache update failed for %s\n"), + file); return (-1); } @@ -2326,13 +2377,14 @@ cmpstat( } else { ret = update_dircache(file, flags); if (ret == BAM_ERROR) { - bam_error(UPDT_CACHE_FAIL, file); + bam_error(_("directory cache update " + "failed for %s\n"), file); return (-1); } } if (bam_verbose) - bam_print(PARSEABLE_NEW_FILE, file); + bam_print(_(" new %s\n"), file); return (0); } @@ -2376,7 +2428,8 @@ cmpstat( } else { ret = update_dircache(file, flags); if (ret == BAM_ERROR) { - bam_error(UPDT_CACHE_FAIL, file); + bam_error(_("directory cache update failed " + "for %s\n"), file); return (-1); } } @@ -2385,7 +2438,7 @@ cmpstat( if (bam_smf_check) bam_print(" %s\n", file); else - bam_print(PARSEABLE_OUT_DATE, file); + bam_print(_(" changed %s\n"), file); } } @@ -2439,7 +2492,8 @@ set_cache_dir(char *root, int what) "/amd64" : "", CACHEDIR_SUFFIX); if (ret >= sizeof (get_cachedir(what))) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } @@ -2451,11 +2505,12 @@ set_cache_dir(char *root, int what) (void) unlink(get_cachedir(what)); if (bam_verbose) - bam_print(UPDATE_CDIR_MISS, get_cachedir(what)); + bam_print(_("archive cache directory not found: %s\n"), + get_cachedir(what)); ret = mkdir(get_cachedir(what), DIR_PERMS); if (ret < 0) { - bam_error(MKDIR_FAILED, get_cachedir(what), - strerror(errno)); + bam_error(_("mkdir of %s failed: %s\n"), + get_cachedir(what), strerror(errno)); get_cachedir(what)[0] = '\0'; return (ret); } @@ -2490,7 +2545,8 @@ set_update_dir(char *root, int what) ARCHIVE_PREFIX, get_machine(), UPDATEDIR_SUFFIX); if (ret >= sizeof (get_updatedir(what))) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } @@ -2527,13 +2583,14 @@ is_valid_archive(char *root, int what) root, ARCHIVE_PREFIX, get_machine(), ARCHIVE_SUFFIX); if (ret >= sizeof (archive_path)) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } if (stat(archive_path, &sb) != 0) { if (bam_verbose && !bam_check) - bam_print(UPDATE_ARCH_MISS, archive_path); + bam_print(_("archive not found: %s\n"), archive_path); set_dir_flag(what, NEED_UPDATE); set_dir_flag(what, NO_MULTI); return (BAM_SUCCESS); @@ -2554,14 +2611,16 @@ is_valid_archive(char *root, int what) FILE_STAT_TIMESTAMP); if (ret >= sizeof (timestamp_path)) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } if (stat(timestamp_path, ×tamp) != 0 || sb.st_mtime > timestamp.st_mtime) { if (bam_verbose && !bam_check) - bam_print(UPDATE_CACHE_OLD); + bam_print( + _("archive cache is out of sync. Rebuilding.\n")); /* * Don't generate a false positive for the boot-archive service * but trigger an update of the archive cache in @@ -2583,7 +2642,8 @@ is_valid_archive(char *root, int what) if (bam_extend && sb.st_size > BA_SIZE_MAX) { if (bam_verbose && !bam_check) - bam_print(MULTI_SIZE, archive_path, BA_SIZE_MAX); + bam_print(_("archive %s is bigger than %d bytes and " + "will be rebuilt\n"), archive_path, BA_SIZE_MAX); set_dir_flag(what, NO_MULTI); } @@ -2635,7 +2695,8 @@ check_flags_and_files(char *root) ARCHIVE_PREFIX, get_machine(), CACHEDIR_SUFFIX); if (ret >= sizeof (get_cachedir(FILE64))) { - bam_error(PATH_TOO_LONG, rootbuf); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), rootbuf); return (BAM_ERROR); } @@ -2646,8 +2707,8 @@ check_flags_and_files(char *root) walk_arg.sparcfile = fopen(get_cachedir(FILE64), "w"); if (walk_arg.sparcfile == NULL) { - bam_error(OPEN_FAIL, get_cachedir(FILE64), - strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + get_cachedir(FILE64), strerror(errno)); return (BAM_ERROR); } @@ -2675,7 +2736,7 @@ check_flags_and_files(char *root) set_dir_flag(FILE32, NEED_UPDATE); set_dir_flag(FILE64, NEED_UPDATE); if (bam_verbose) - bam_print(UPDATE_FORCE); + bam_print(_("forced update of archive requested\n")); return (BAM_SUCCESS); } @@ -2694,7 +2755,8 @@ read_one_list(char *root, filelist_t *flistp, char *filelist) fp = fopen(path, "r"); if (fp == NULL) { - BAM_DPRINTF((D_FLIST_FAIL, fcn, path, strerror(errno))); + BAM_DPRINTF(("%s: failed to open archive filelist: %s: %s\n", + fcn, path, strerror(errno))); return (BAM_ERROR); } while (s_fgets(buf, sizeof (buf), fp) != NULL) { @@ -2704,7 +2766,8 @@ read_one_list(char *root, filelist_t *flistp, char *filelist) append_to_flist(flistp, buf); } if (fclose(fp) != 0) { - bam_error(CLOSE_FAIL, path, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + path, strerror(errno)); return (BAM_ERROR); } return (BAM_SUCCESS); @@ -2726,7 +2789,7 @@ read_list(char *root, filelist_t *flistp) */ n = snprintf(path, sizeof (path), "%s%s", root, EXTRACT_BOOT_FILELIST); if (n >= sizeof (path)) { - bam_error(NO_FLIST); + bam_error(_("archive filelist is empty\n")); return (BAM_ERROR); } @@ -2765,11 +2828,12 @@ read_list(char *root, filelist_t *flistp) free(platarg); free(rootarg); if (n >= sizeof (cmd)) { - bam_error(NO_FLIST); + bam_error(_("archive filelist is empty\n")); return (BAM_ERROR); } if (exec_cmd(cmd, flistp) != 0) { - BAM_DPRINTF((D_FLIST_FAIL, fcn, path, strerror(errno))); + BAM_DPRINTF(("%s: failed to open archive " + "filelist: %s: %s\n", fcn, path, strerror(errno))); return (BAM_ERROR); } } else { @@ -2783,7 +2847,7 @@ read_list(char *root, filelist_t *flistp) } if (flistp->head == NULL) { - bam_error(NO_FLIST); + bam_error(_("archive filelist is empty\n")); return (BAM_ERROR); } @@ -2802,19 +2866,22 @@ getoldstat(char *root) fd = open(path, O_RDONLY); if (fd == -1) { if (bam_verbose) - bam_print(OPEN_FAIL, path, strerror(errno)); + bam_print(_("failed to open file: %s: %s\n"), + path, strerror(errno)); goto out_err; } if (fstat(fd, &sb) != 0) { - bam_error(STAT_FAIL, path, strerror(errno)); + bam_error(_("stat of file failed: %s: %s\n"), path, + strerror(errno)); goto out_err; } ostat = s_calloc(1, sb.st_size); if (read(fd, ostat, sb.st_size) != sb.st_size) { - bam_error(READ_FAIL, path, strerror(errno)); + bam_error(_("read failed for file: %s: %s\n"), path, + strerror(errno)); free(ostat); goto out_err; } @@ -2828,7 +2895,8 @@ getoldstat(char *root) free(ostat); if (error) { - bam_error(UNPACK_FAIL, path, strerror(error)); + bam_error(_("failed to unpack stat data: %s: %s\n"), + path, strerror(error)); walk_arg.old_nvlp = NULL; goto out_err; } else { @@ -2903,7 +2971,7 @@ check4stale(char *root) int what; if (bam_verbose) - bam_print(PARSEABLE_STALE_FILE, path); + bam_print(_(" stale %s\n"), path); if (is_flag_on(IS_SPARC_TARGET)) { set_dir_flag(FILE64, NEED_UPDATE); @@ -2927,7 +2995,8 @@ create_newstat(void) * Not fatal - we can still create archive */ walk_arg.new_nvlp = NULL; - bam_error(NVALLOC_FAIL, strerror(error)); + bam_error(_("failed to create stat data: %s\n"), + strerror(error)); } } @@ -2954,7 +3023,8 @@ walk_list(char *root, filelist_t *flistp) * Emit verbose message only */ if (bam_verbose) - bam_print(NFTW_FAIL, path, strerror(errno)); + bam_print(_("cannot find: %s: %s\n"), + path, strerror(errno)); } } @@ -2979,8 +3049,10 @@ update_timestamp(char *root) * the user of the performance issue. */ if (creat(timestamp_path, FILE_STAT_MODE) < 0) { - bam_error(OPEN_FAIL, timestamp_path, strerror(errno)); - bam_error(TIMESTAMP_FAIL); + bam_error(_("failed to open file: %s: %s\n"), timestamp_path, + strerror(errno)); + bam_error(_("failed to update the timestamp file, next" + " archive update may experience reduced performance\n")); } } @@ -2999,20 +3071,23 @@ savenew(char *root) error = nvlist_pack(walk_arg.new_nvlp, &nstat, &sz, NV_ENCODE_XDR, 0); if (error) { - bam_error(PACK_FAIL, strerror(error)); + bam_error(_("failed to pack stat data: %s\n"), + strerror(error)); return; } (void) snprintf(path, sizeof (path), "%s%s", root, FILE_STAT_TMP); fd = open(path, O_RDWR|O_CREAT|O_TRUNC, FILE_STAT_MODE); if (fd == -1) { - bam_error(OPEN_FAIL, path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), path, + strerror(errno)); free(nstat); return; } wrote = write(fd, nstat, sz); if (wrote != sz) { - bam_error(WRITE_FAIL, path, strerror(errno)); + bam_error(_("write to file failed: %s: %s\n"), path, + strerror(errno)); (void) close(fd); free(nstat); return; @@ -3022,7 +3097,8 @@ savenew(char *root) (void) snprintf(path2, sizeof (path2), "%s%s", root, FILE_STAT); if (rename(path, path2) != 0) { - bam_error(RENAME_FAIL, path2, strerror(errno)); + bam_error(_("rename to file failed: %s: %s\n"), path2, + strerror(errno)); } } @@ -3126,14 +3202,15 @@ update_required(char *root) /* something went wrong */ if (ret == BAM_ERROR) { - bam_error(CACHE_FAIL); + bam_error(_("Failed to gather cache files, archives " + "generation aborted\n")); return (BAM_ERROR); } if (walk_arg.new_nvlp == NULL) { if (walk_arg.sparcfile != NULL) (void) fclose(walk_arg.sparcfile); - bam_error(NO_NEW_STAT); + bam_error(_("cannot create new stat data\n")); } /* If nothing was updated, discard newstat. */ @@ -3211,7 +3288,7 @@ check_archive(char *dest) if (stat(dest, &sb) != 0 || !S_ISREG(sb.st_mode) || sb.st_size < 10000) { - bam_error(ARCHIVE_BAD, dest); + bam_error(_("archive file %s not generated correctly\n"), dest); (void) unlink(dest); return (BAM_ERROR); } @@ -3292,7 +3369,7 @@ create_sparc_archive(char *archive, char *tempname, char *bootblk, char *list) const char *func = "create_sparc_archive()"; if (access(bootblk, R_OK) == 1) { - bam_error(BOOTBLK_FAIL, bootblk); + bam_error(_("unable to access bootblk file : %s\n"), bootblk); return (BAM_ERROR); } @@ -3303,7 +3380,7 @@ create_sparc_archive(char *archive, char *tempname, char *bootblk, char *list) "-path-list \"%s\" 2>&1", MKISOFS_PATH, MKISO_PARAMS, bootblk, tempname, list); - BAM_DPRINTF((D_CMDLINE, func, cmdline)); + BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); ret = exec_cmd(cmdline, &flist); if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { @@ -3321,7 +3398,7 @@ create_sparc_archive(char *archive, char *tempname, char *bootblk, char *list) " bs=1b oseek=1 count=15 conv=notrunc conv=sync 2>&1", DD_PATH_USR, bootblk, tempname); - BAM_DPRINTF((D_CMDLINE, func, cmdline)); + BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); ret = exec_cmd(cmdline, &flist); if (ret != 0 || check_cmdline(flist) == BAM_ERROR) @@ -3337,7 +3414,7 @@ create_sparc_archive(char *archive, char *tempname, char *bootblk, char *list) out_err: filelist_free(&flist); - bam_error(ARCHIVE_FAIL, cmdline); + bam_error(_("boot-archive creation FAILED, command: '%s'\n"), cmdline); (void) unlink(tempname); return (BAM_ERROR); } @@ -3413,7 +3490,8 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) fd = open(archive, O_RDWR); if (fd == -1) { if (bam_verbose) - bam_error(OPEN_FAIL, archive, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + archive, strerror(errno)); goto out_err; } @@ -3424,13 +3502,15 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) VOLDESC_OFF * CD_BLOCK); if (ret != sizeof (saved_desc)) { if (bam_verbose) - bam_error(READ_FAIL, archive, strerror(errno)); + bam_error(_("read failed for file: %s: %s\n"), + archive, strerror(errno)); goto out_err; } if (memcmp(saved_desc[0].type, "\1CD001", 6)) { if (bam_verbose) - bam_error(SIGN_FAIL, archive); + bam_error(_("iso descriptor signature for %s is " + "invalid\n"), archive); goto out_err; } @@ -3444,12 +3524,13 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) "%s\" \"%s\" 2>&1", MKISOFS_PATH, next_session, archive, MKISO_PARAMS, tempname, update_dir); - BAM_DPRINTF((D_CMDLINE, func, cmdline)); + BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); ret = exec_cmd(cmdline, &flist); if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { if (bam_verbose) { - bam_error(MULTI_FAIL, cmdline); + bam_error(_("Command '%s' failed while generating " + "multisession archive\n"), cmdline); dump_errormsg(flist); } goto out_flist_err; @@ -3459,7 +3540,8 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) newfd = open(tempname, O_RDONLY); if (newfd == -1) { if (bam_verbose) - bam_error(OPEN_FAIL, archive, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + archive, strerror(errno)); goto out_err; } @@ -3467,13 +3549,15 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) VOLDESC_OFF * CD_BLOCK); if (ret != sizeof (saved_desc)) { if (bam_verbose) - bam_error(READ_FAIL, archive, strerror(errno)); + bam_error(_("read failed for file: %s: %s\n"), + archive, strerror(errno)); goto out_err; } if (memcmp(saved_desc[0].type, "\1CD001", 6)) { if (bam_verbose) - bam_error(SIGN_FAIL, archive); + bam_error(_("iso descriptor signature for %s is " + "invalid\n"), archive); goto out_err; } @@ -3496,7 +3580,8 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) ret = pwrite64(fd, saved_desc, DVD_BLOCK, VOLDESC_OFF*CD_BLOCK); if (ret != DVD_BLOCK) { if (bam_verbose) - bam_error(WRITE_FAIL, archive, strerror(errno)); + bam_error(_("write to file failed: %s: %s\n"), + archive, strerror(errno)); goto out_err; } (void) close(newfd); @@ -3509,7 +3594,8 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) ret = close(fd); if (ret != 0) { if (bam_verbose) - bam_error(CLOSE_FAIL, archive, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), + archive, strerror(errno)); return (BAM_ERROR); } fd = -1; @@ -3518,12 +3604,13 @@ extend_iso_archive(char *archive, char *tempname, char *update_dir) "seek=%d conv=sync 2>&1", DD_PATH_USR, tempname, archive, (next_session/16)); - BAM_DPRINTF((D_CMDLINE, func, cmdline)); + BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); ret = exec_cmd(cmdline, &flist); if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { if (bam_verbose) - bam_error(MULTI_FAIL, cmdline); + bam_error(_("Command '%s' failed while generating " + "multisession archive\n"), cmdline); goto out_flist_err; } filelist_free(&flist); @@ -3562,11 +3649,12 @@ create_x86_archive(char *archive, char *tempname, char *update_dir) (void) snprintf(cmdline, sizeof (cmdline), "%s %s -o \"%s\" \"%s\" " "2>&1", MKISOFS_PATH, MKISO_PARAMS, tempname, update_dir); - BAM_DPRINTF((D_CMDLINE, func, cmdline)); + BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); ret = exec_cmd(cmdline, &flist); if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { - bam_error(ARCHIVE_FAIL, cmdline); + bam_error(_("boot-archive creation FAILED, command: '%s'\n"), + cmdline); dump_errormsg(flist); filelist_free(&flist); (void) unlink(tempname); @@ -3670,7 +3758,8 @@ mkisofs_archive(char *root, int what) return (ret); out_path_err: - bam_error(PATH_TOO_LONG, root); + bam_error(_("unable to create path on mountpoint %s, path too long\n"), + root); return (BAM_ERROR); } @@ -3704,7 +3793,8 @@ create_ramdisk(char *root) (void) snprintf(path, sizeof (path), "%s/%s", root, CREATE_RAMDISK); if (stat(path, &sb) != 0) { - bam_error(ARCH_EXEC_MISS, path, strerror(errno)); + bam_error(_("archive creation file not found: %s: %s\n"), + path, strerror(errno)); return (BAM_ERROR); } @@ -3730,7 +3820,8 @@ create_ramdisk(char *root) (void) snprintf(cmdline, len, "%s", path); if (exec_cmd(cmdline, NULL) != 0) { - bam_error(ARCHIVE_FAIL, cmdline); + bam_error(_("boot-archive creation FAILED, command: '%s'\n"), + cmdline); free(cmdline); return (BAM_ERROR); } @@ -3770,7 +3861,8 @@ is_ramdisk(char *root) */ fp = fopen(MNTTAB, "r"); if (fp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + MNTTAB, strerror(errno)); return (0); } @@ -3795,7 +3887,8 @@ is_ramdisk(char *root) if (!found) { if (bam_verbose) - bam_error(NOT_IN_MNTTAB, mntpt); + bam_error(_("alternate root %s not in mnttab\n"), + mntpt); (void) fclose(fp); return (0); } @@ -3803,7 +3896,7 @@ is_ramdisk(char *root) if (strncmp(mnt.mnt_special, RAMDISK_SPECIAL, strlen(RAMDISK_SPECIAL)) == 0) { if (bam_verbose) - bam_error(IS_RAMDISK, bam_root); + bam_error(_("%s is on a ramdisk device\n"), bam_root); (void) fclose(fp); return (1); } @@ -3829,12 +3922,14 @@ is_boot_archive(char *root) INJECT_ERROR1("NOT_ARCHIVE_BASED", error = -1); if (error == -1) { if (bam_verbose) - bam_print(FILE_MISS, path); - BAM_DPRINTF((D_NOT_ARCHIVE_BOOT, fcn, root)); + bam_print(_("file not found: %s\n"), path); + BAM_DPRINTF(("%s: not a boot archive based Solaris " + "instance: %s\n", fcn, root)); return (0); } - BAM_DPRINTF((D_IS_ARCHIVE_BOOT, fcn, root)); + BAM_DPRINTF(("%s: *IS* a boot archive based Solaris instance: %s\n", + fcn, root)); return (1); } @@ -3852,18 +3947,37 @@ is_grub(const char *root) { char path[PATH_MAX]; struct stat sb; + void *defp; + boolean_t grub = B_FALSE; + const char *res = NULL; const char *fcn = "is_grub()"; - (void) snprintf(path, sizeof (path), "%s%s", root, GRUB_STAGE2); - if (stat(path, &sb) == -1) { - BAM_DPRINTF((D_NO_GRUB_DIR, fcn, path)); + /* grub is disabled by default */ + if ((defp = defopen_r(BE_DEFAULTS)) == NULL) { return (0); + } else { + res = defread_r(BE_DFLT_BE_HAS_GRUB, defp); + if (res != NULL && res[0] != '\0') { + if (strcasecmp(res, "true") == 0) + grub = B_TRUE; + } + defclose_r(defp); } - return (1); + if (grub == B_TRUE) { + (void) snprintf(path, sizeof (path), "%s%s", root, GRUB_STAGE2); + if (stat(path, &sb) == -1) { + BAM_DPRINTF(("%s: Missing GRUB directory: %s\n", + fcn, path)); + return (0); + } else + return (1); + } + + return (0); } -static int +int is_zfs(char *root) { struct statvfs vfs; @@ -3873,15 +3987,16 @@ is_zfs(char *root) ret = statvfs(root, &vfs); INJECT_ERROR1("STATVFS_ZFS", ret = 1); if (ret != 0) { - bam_error(STATVFS_FAIL, root, strerror(errno)); + bam_error(_("statvfs failed for %s: %s\n"), root, + strerror(errno)); return (0); } if (strncmp(vfs.f_basetype, "zfs", strlen("zfs")) == 0) { - BAM_DPRINTF((D_IS_ZFS, fcn, root)); + BAM_DPRINTF(("%s: is a ZFS filesystem: %s\n", fcn, root)); return (1); } else { - BAM_DPRINTF((D_IS_NOT_ZFS, fcn, root)); + BAM_DPRINTF(("%s: is *NOT* a ZFS filesystem: %s\n", fcn, root)); return (0); } } @@ -3896,20 +4011,21 @@ is_ufs(char *root) ret = statvfs(root, &vfs); INJECT_ERROR1("STATVFS_UFS", ret = 1); if (ret != 0) { - bam_error(STATVFS_FAIL, root, strerror(errno)); + bam_error(_("statvfs failed for %s: %s\n"), root, + strerror(errno)); return (0); } if (strncmp(vfs.f_basetype, "ufs", strlen("ufs")) == 0) { - BAM_DPRINTF((D_IS_UFS, fcn, root)); + BAM_DPRINTF(("%s: is a UFS filesystem: %s\n", fcn, root)); return (1); } else { - BAM_DPRINTF((D_IS_NOT_UFS, fcn, root)); + BAM_DPRINTF(("%s: is *NOT* a UFS filesystem: %s\n", fcn, root)); return (0); } } -static int +int is_pcfs(char *root) { struct statvfs vfs; @@ -3919,15 +4035,17 @@ is_pcfs(char *root) ret = statvfs(root, &vfs); INJECT_ERROR1("STATVFS_PCFS", ret = 1); if (ret != 0) { - bam_error(STATVFS_FAIL, root, strerror(errno)); + bam_error(_("statvfs failed for %s: %s\n"), root, + strerror(errno)); return (0); } if (strncmp(vfs.f_basetype, "pcfs", strlen("pcfs")) == 0) { - BAM_DPRINTF((D_IS_PCFS, fcn, root)); + BAM_DPRINTF(("%s: is a PCFS filesystem: %s\n", fcn, root)); return (1); } else { - BAM_DPRINTF((D_IS_NOT_PCFS, fcn, root)); + BAM_DPRINTF(("%s: is *NOT* a PCFS filesystem: %s\n", + fcn, root)); return (0); } } @@ -3955,16 +4073,17 @@ is_readonly(char *root) error = errno; INJECT_ERROR2("RDONLY_TEST_ERROR", fd = -1, error = EACCES); if (fd == -1 && error == EROFS) { - BAM_DPRINTF((D_RDONLY_FS, fcn, root)); + BAM_DPRINTF(("%s: is a READONLY filesystem: %s\n", fcn, root)); return (1); } else if (fd == -1) { - bam_error(RDONLY_TEST_ERROR, root, strerror(error)); + bam_error(_("error during read-only test on %s: %s\n"), + root, strerror(error)); } (void) close(fd); (void) unlink(testfile); - BAM_DPRINTF((D_RDWR_FS, fcn, root)); + BAM_DPRINTF(("%s: is a RDWR filesystem: %s\n", fcn, root)); return (0); } @@ -3993,7 +4112,8 @@ update_archive(char *root, char *opt) * If in update_all, emit only if verbose flag is set. */ if (!bam_update_all || bam_verbose) - bam_print(NOT_ARCHIVE_BOOT, root); + bam_print(_("%s: not a boot archive based Solaris " + "instance\n"), root); return (BAM_ERROR); } @@ -4036,7 +4156,8 @@ update_archive(char *root, char *opt) if (is_flag_on(RDONLY_FSCHK)) { bam_check = bam_saved_check; if (ret > 0) - bam_error(RDONLY_FS, root); + bam_error(_("%s filesystem is read-only, " + "skipping archives update\n"), root); if (bam_update_all) return ((ret != 0) ? BAM_ERROR : BAM_SUCCESS); } @@ -4104,38 +4225,41 @@ synchronize_BE_menu(void) int ret; const char *fcn = "synchronize_BE_menu()"; - BAM_DPRINTF((D_FUNC_ENTRY0, fcn)); + BAM_DPRINTF(("%s: entered. No args\n", fcn)); /* Check if findroot enabled LU BE */ if (stat(FINDROOT_INSTALLGRUB, &sb) != 0) { - BAM_DPRINTF((D_NOT_LU_BE, fcn)); + BAM_DPRINTF(("%s: not a Live Upgrade BE\n", fcn)); return (BAM_SUCCESS); } if (stat(LU_MENU_CKSUM, &sb) != 0) { - BAM_DPRINTF((D_NO_CKSUM_FILE, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: checksum file absent: %s\n", + fcn, LU_MENU_CKSUM)); goto menu_sync; } cfp = fopen(LU_MENU_CKSUM, "r"); INJECT_ERROR1("CKSUM_FILE_MISSING", cfp = NULL); if (cfp == NULL) { - bam_error(CANNOT_READ_LU_CKSUM, LU_MENU_CKSUM); + bam_error(_("failed to read GRUB menu checksum file: %s\n"), + LU_MENU_CKSUM); goto menu_sync; } - BAM_DPRINTF((D_CKSUM_FILE_OPENED, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: opened checksum file: %s\n", fcn, LU_MENU_CKSUM)); found = 0; while (s_fgets(cksum_line, sizeof (cksum_line), cfp) != NULL) { INJECT_ERROR1("MULTIPLE_CKSUM", found = 1); if (found) { - bam_error(MULTIPLE_LU_CKSUM, LU_MENU_CKSUM); + bam_error(_("multiple checksums for GRUB menu in " + "checksum file: %s\n"), LU_MENU_CKSUM); (void) fclose(cfp); goto menu_sync; } found = 1; } - BAM_DPRINTF((D_CKSUM_FILE_READ, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: read checksum file: %s\n", fcn, LU_MENU_CKSUM)); old_cksum_str = strtok(cksum_line, " \t"); @@ -4146,17 +4270,19 @@ synchronize_BE_menu(void) INJECT_ERROR1("OLD_SIZE_NULL", old_size_str = NULL); INJECT_ERROR1("OLD_FILE_NULL", old_file = NULL); if (old_cksum_str == NULL || old_size_str == NULL || old_file == NULL) { - bam_error(CANNOT_PARSE_LU_CKSUM, LU_MENU_CKSUM); + bam_error(_("error parsing GRUB menu checksum file: %s\n"), + LU_MENU_CKSUM); goto menu_sync; } - BAM_DPRINTF((D_CKSUM_FILE_PARSED, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: parsed checksum file: %s\n", fcn, LU_MENU_CKSUM)); /* Get checksum of current menu */ pool = find_root_pool(); if (pool) { mntpt = mount_top_dataset(pool, &mnted); if (mntpt == NULL) { - bam_error(FAIL_MNT_TOP_DATASET, pool); + bam_error(_("failed to mount top dataset for %s\n"), + pool); free(pool); return (BAM_ERROR); } @@ -4173,18 +4299,18 @@ synchronize_BE_menu(void) } INJECT_ERROR1("GET_CURR_CKSUM", ret = 1); if (ret != 0) { - bam_error(MENU_CKSUM_FAIL); + bam_error(_("error generating checksum of GRUB menu\n")); return (BAM_ERROR); } - BAM_DPRINTF((D_CKSUM_GEN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: successfully generated checksum\n", fcn)); INJECT_ERROR1("GET_CURR_CKSUM_OUTPUT", flist.head = NULL); if ((flist.head == NULL) || (flist.head != flist.tail)) { - bam_error(BAD_CKSUM); + bam_error(_("bad checksum generated for GRUB menu\n")); filelist_free(&flist); return (BAM_ERROR); } - BAM_DPRINTF((D_CKSUM_GEN_OUTPUT_VALID, fcn)); + BAM_DPRINTF(("%s: generated checksum output valid\n", fcn)); curr_cksum_str = strtok(flist.head->line, " \t"); curr_size_str = strtok(NULL, " \t"); @@ -4195,27 +4321,28 @@ synchronize_BE_menu(void) INJECT_ERROR1("CURR_FILE_NULL", curr_file = NULL); if (curr_cksum_str == NULL || curr_size_str == NULL || curr_file == NULL) { - bam_error(BAD_CKSUM_PARSE); + bam_error(_("error parsing checksum generated " + "for GRUB menu\n")); filelist_free(&flist); return (BAM_ERROR); } - BAM_DPRINTF((D_CKSUM_GEN_PARSED, fcn)); + BAM_DPRINTF(("%s: successfully parsed generated checksum\n", fcn)); if (strcmp(old_cksum_str, curr_cksum_str) == 0 && strcmp(old_size_str, curr_size_str) == 0 && strcmp(old_file, curr_file) == 0) { filelist_free(&flist); - BAM_DPRINTF((D_CKSUM_NO_CHANGE, fcn)); + BAM_DPRINTF(("%s: no change in checksum of GRUB menu\n", fcn)); return (BAM_SUCCESS); } filelist_free(&flist); /* cksum doesn't match - the menu has changed */ - BAM_DPRINTF((D_CKSUM_HAS_CHANGED, fcn)); + BAM_DPRINTF(("%s: checksum of GRUB menu has changed\n", fcn)); menu_sync: - bam_print(PROP_GRUB_MENU); + bam_print(_("propagating updated GRUB menu\n")); (void) snprintf(cmdline, sizeof (cmdline), "/bin/sh -c '. %s > /dev/null; %s %s yes > /dev/null'", @@ -4223,20 +4350,22 @@ menu_sync: ret = exec_cmd(cmdline, NULL); INJECT_ERROR1("PROPAGATE_MENU", ret = 1); if (ret != 0) { - bam_error(MENU_PROP_FAIL); + bam_error(_("error propagating updated GRUB menu\n")); return (BAM_ERROR); } - BAM_DPRINTF((D_PROPAGATED_MENU, fcn)); + BAM_DPRINTF(("%s: successfully propagated GRUB menu\n", fcn)); (void) snprintf(cmdline, sizeof (cmdline), "/bin/cp %s %s > /dev/null", GRUB_MENU, GRUB_BACKUP_MENU); ret = exec_cmd(cmdline, NULL); INJECT_ERROR1("CREATE_BACKUP", ret = 1); if (ret != 0) { - bam_error(MENU_BACKUP_FAIL, GRUB_BACKUP_MENU); + bam_error(_("failed to create backup for GRUB menu: %s\n"), + GRUB_BACKUP_MENU); return (BAM_ERROR); } - BAM_DPRINTF((D_CREATED_BACKUP, fcn, GRUB_BACKUP_MENU)); + BAM_DPRINTF(("%s: successfully created backup GRUB menu: %s\n", + fcn, GRUB_BACKUP_MENU)); (void) snprintf(cmdline, sizeof (cmdline), "/bin/sh -c '. %s > /dev/null; %s %s no > /dev/null'", @@ -4244,20 +4373,24 @@ menu_sync: ret = exec_cmd(cmdline, NULL); INJECT_ERROR1("PROPAGATE_BACKUP", ret = 1); if (ret != 0) { - bam_error(BACKUP_PROP_FAIL, GRUB_BACKUP_MENU); + bam_error(_("error propagating backup GRUB menu: %s\n"), + GRUB_BACKUP_MENU); return (BAM_ERROR); } - BAM_DPRINTF((D_PROPAGATED_BACKUP, fcn, GRUB_BACKUP_MENU)); + BAM_DPRINTF(("%s: successfully propagated backup GRUB menu: %s\n", + fcn, GRUB_BACKUP_MENU)); (void) snprintf(cmdline, sizeof (cmdline), "%s %s > %s", CKSUM, GRUB_MENU, LU_MENU_CKSUM); ret = exec_cmd(cmdline, NULL); INJECT_ERROR1("CREATE_CKSUM_FILE", ret = 1); if (ret != 0) { - bam_error(MENU_CKSUM_WRITE_FAIL, LU_MENU_CKSUM); + bam_error(_("failed to write GRUB menu checksum file: %s\n"), + LU_MENU_CKSUM); return (BAM_ERROR); } - BAM_DPRINTF((D_CREATED_CKSUM_FILE, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: successfully created checksum file: %s\n", + fcn, LU_MENU_CKSUM)); (void) snprintf(cmdline, sizeof (cmdline), "/bin/sh -c '. %s > /dev/null; %s %s no > /dev/null'", @@ -4265,10 +4398,12 @@ menu_sync: ret = exec_cmd(cmdline, NULL); INJECT_ERROR1("PROPAGATE_MENU_CKSUM_FILE", ret = 1); if (ret != 0) { - bam_error(MENU_CKSUM_PROP_FAIL, LU_MENU_CKSUM); + bam_error(_("error propagating GRUB menu checksum file: %s\n"), + LU_MENU_CKSUM); return (BAM_ERROR); } - BAM_DPRINTF((D_PROPAGATED_CKSUM_FILE, fcn, LU_MENU_CKSUM)); + BAM_DPRINTF(("%s: successfully propagated checksum file: %s\n", + fcn, LU_MENU_CKSUM)); return (BAM_SUCCESS); } @@ -4288,7 +4423,8 @@ update_all(char *root, char *opt) if (bam_rootlen != 1 || *root != '/') { elide_trailing_slash(root, multibt, sizeof (multibt)); - bam_error(ALT_ROOT_INVALID, multibt); + bam_error(_("an alternate root (%s) cannot be used with this " + "sub-command\n"), multibt); return (BAM_ERROR); } @@ -4307,7 +4443,8 @@ update_all(char *root, char *opt) */ fp = fopen(MNTTAB, "r"); if (fp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), + MNTTAB, strerror(errno)); ret = BAM_ERROR; goto out; } @@ -4355,7 +4492,8 @@ out: * updates */ if (stat(GRUB_fdisk, &sb) == 0 || stat(GRUB_fdisk_target, &sb) == 0) { - bam_error(FDISK_FILES_FOUND, GRUB_fdisk, GRUB_fdisk_target); + bam_error(_("Deferred FDISK update file(s) found: %s, %s. " + "Not supported.\n"), GRUB_fdisk, GRUB_fdisk_target); } /* @@ -4405,13 +4543,13 @@ boot_entry_new(menu_t *mp, line_t *start, line_t *end) assert(end); ent = s_calloc(1, sizeof (entry_t)); - BAM_DPRINTF((D_ENTRY_NEW, fcn)); + BAM_DPRINTF(("%s: new boot entry alloced\n", fcn)); ent->start = start; ent->end = end; if (mp->entries == NULL) { mp->entries = ent; - BAM_DPRINTF((D_ENTRY_NEW_FIRST, fcn)); + BAM_DPRINTF(("%s: (first) new boot entry created\n", fcn)); return (ent); } @@ -4420,7 +4558,7 @@ boot_entry_new(menu_t *mp, line_t *start, line_t *end) prev = prev->next; prev->next = ent; ent->prev = prev; - BAM_DPRINTF((D_ENTRY_NEW_LINKED, fcn)); + BAM_DPRINTF(("%s: new boot entry linked in\n", fcn)); return (ent); } @@ -4443,12 +4581,12 @@ check_cmd(const char *cmd, const int which, const char *arg, const char *str) int ret; const char *fcn = "check_cmd()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, arg, str)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, arg, str)); if (cmd != NULL) { if ((strcmp(cmd, menu_cmds[which]) != 0) && (strcmp(cmd, menu_cmds[which + 1]) != 0)) { - BAM_DPRINTF((D_CHECK_CMD_CMD_NOMATCH, + BAM_DPRINTF(("%s: command %s does not match %s\n", fcn, cmd, menu_cmds[which])); return (0); } @@ -4457,9 +4595,9 @@ check_cmd(const char *cmd, const int which, const char *arg, const char *str) ret = 0; if (ret) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (ret); @@ -4476,47 +4614,53 @@ kernel_parser(entry_t *entry, char *cmd, char *arg, int linenum) if (strcmp(cmd, menu_cmds[KERNEL_CMD]) != 0 && strcmp(cmd, menu_cmds[KERNEL_DOLLAR_CMD]) != 0) { - BAM_DPRINTF((D_NOT_KERNEL_CMD, fcn, cmd)); + BAM_DPRINTF(("%s: not a kernel command: %s\n", fcn, cmd)); return (BAM_ERROR); } if (strncmp(arg, DIRECT_BOOT_32, sizeof (DIRECT_BOOT_32) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT_32, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT|DBOOT_32 flag: %s\n", + fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_32BIT; } else if (strncmp(arg, DIRECT_BOOT_KERNEL, sizeof (DIRECT_BOOT_KERNEL) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT; } else if (strncmp(arg, DIRECT_BOOT_64, sizeof (DIRECT_BOOT_64) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT_64, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT|DBOOT_64 flag: %s\n", + fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_64BIT; } else if (strncmp(arg, DIRECT_BOOT_FAILSAFE_KERNEL, sizeof (DIRECT_BOOT_FAILSAFE_KERNEL) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT_FAILSAFE, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT|DBOOT_FAILSAFE flag: %s\n", + fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_FAILSAFE; } else if (strncmp(arg, DIRECT_BOOT_FAILSAFE_32, sizeof (DIRECT_BOOT_FAILSAFE_32) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT_FAILSAFE_32, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT|DBOOT_FAILSAFE|DBOOT_32 " + "flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_FAILSAFE | BAM_ENTRY_32BIT; } else if (strncmp(arg, DIRECT_BOOT_FAILSAFE_64, sizeof (DIRECT_BOOT_FAILSAFE_64) - 1) == 0) { - BAM_DPRINTF((D_SET_DBOOT_FAILSAFE_64, fcn, arg)); + BAM_DPRINTF(("%s: setting DBOOT|DBOOT_FAILSAFE|DBOOT_64 " + "flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_FAILSAFE | BAM_ENTRY_64BIT; } else if (strncmp(arg, MULTI_BOOT, sizeof (MULTI_BOOT) - 1) == 0) { - BAM_DPRINTF((D_SET_MULTIBOOT, fcn, arg)); + BAM_DPRINTF(("%s: setting MULTIBOOT flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_MULTIBOOT; } else if (strncmp(arg, MULTI_BOOT_FAILSAFE, sizeof (MULTI_BOOT_FAILSAFE) - 1) == 0) { - BAM_DPRINTF((D_SET_MULTIBOOT_FAILSAFE, fcn, arg)); + BAM_DPRINTF(("%s: setting MULTIBOOT|MULTIBOOT_FAILSAFE " + "flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_MULTIBOOT | BAM_ENTRY_FAILSAFE; } else if (strstr(arg, XEN_KERNEL_SUBSTR)) { - BAM_DPRINTF((D_SET_HV, fcn, arg)); + BAM_DPRINTF(("%s: setting XEN HV flag: %s\n", fcn, arg)); entry->flags |= BAM_ENTRY_HV; } else if (!(entry->flags & (BAM_ENTRY_BOOTADM|BAM_ENTRY_LU))) { - BAM_DPRINTF((D_SET_HAND_KERNEL, fcn, arg)); + BAM_DPRINTF(("%s: is HAND kernel flag: %s\n", fcn, arg)); return (BAM_ERROR); } else if (strncmp(arg, KERNEL_PREFIX, strlen(KERNEL_PREFIX)) == 0 && strstr(arg, UNIX_SPACE)) { @@ -4525,8 +4669,9 @@ kernel_parser(entry_t *entry, char *cmd, char *arg, int linenum) strstr(arg, AMD_UNIX_SPACE)) { entry->flags |= BAM_ENTRY_DBOOT | BAM_ENTRY_64BIT; } else { - BAM_DPRINTF((D_IS_UNKNOWN_KERNEL, fcn, arg)); - bam_error(UNKNOWN_KERNEL_LINE, linenum); + BAM_DPRINTF(("%s: is UNKNOWN kernel entry: %s\n", fcn, arg)); + bam_error(_("kernel command on line %d not recognized.\n"), + linenum); return (BAM_ERROR); } @@ -4544,7 +4689,7 @@ module_parser(entry_t *entry, char *cmd, char *arg, int linenum) if (strcmp(cmd, menu_cmds[MODULE_CMD]) != 0 && strcmp(cmd, menu_cmds[MODULE_DOLLAR_CMD]) != 0) { - BAM_DPRINTF((D_NOT_MODULE_CMD, fcn, cmd)); + BAM_DPRINTF(("%s: not module cmd: %s\n", fcn, cmd)); return (BAM_ERROR); } @@ -4557,16 +4702,17 @@ module_parser(entry_t *entry, char *cmd, char *arg, int linenum) strcmp(arg, FAILSAFE_ARCHIVE_64) == 0 || strcmp(arg, XEN_KERNEL_MODULE_LINE) == 0 || strcmp(arg, XEN_KERNEL_MODULE_LINE_ZFS) == 0) { - BAM_DPRINTF((D_BOOTADM_LU_MODULE, fcn, arg)); + BAM_DPRINTF(("%s: bootadm or LU module cmd: %s\n", fcn, arg)); return (BAM_SUCCESS); } else if (!(entry->flags & BAM_ENTRY_BOOTADM) && !(entry->flags & BAM_ENTRY_LU)) { /* don't emit warning for hand entries */ - BAM_DPRINTF((D_IS_HAND_MODULE, fcn, arg)); + BAM_DPRINTF(("%s: is HAND module: %s\n", fcn, arg)); return (BAM_ERROR); } else { - BAM_DPRINTF((D_IS_UNKNOWN_MODULE, fcn, arg)); - bam_error(UNKNOWN_MODULE_LINE, linenum); + BAM_DPRINTF(("%s: is UNKNOWN module: %s\n", fcn, arg)); + bam_error(_("module command on line %d not recognized.\n"), + linenum); return (BAM_ERROR); } } @@ -4677,12 +4823,14 @@ line_parser(menu_t *mp, char *str, int *lineNum, int *entryNum) prev->entryNum = lp->entryNum; curr_ent = boot_entry_new(mp, prev, lp); curr_ent->flags |= BAM_ENTRY_BOOTADM; - BAM_DPRINTF((D_IS_BOOTADM_ENTRY, fcn, arg)); + BAM_DPRINTF(("%s: is bootadm(1M) entry: %s\n", + fcn, arg)); } else { curr_ent = boot_entry_new(mp, lp, lp); if (in_liveupgrade) { curr_ent->flags |= BAM_ENTRY_LU; - BAM_DPRINTF((D_IS_LU_ENTRY, fcn, arg)); + BAM_DPRINTF(("%s: is LU entry: %s\n", + fcn, arg)); } } curr_ent->entryNum = *entryNum; @@ -4703,17 +4851,18 @@ line_parser(menu_t *mp, char *str, int *lineNum, int *entryNum) if (cmd && arg) { if (strcmp(cmd, menu_cmds[ROOT_CMD]) == 0) { - BAM_DPRINTF((D_IS_ROOT_CMD, fcn, arg)); + BAM_DPRINTF(("%s: setting ROOT: %s\n", + fcn, arg)); curr_ent->flags |= BAM_ENTRY_ROOT; } else if (strcmp(cmd, menu_cmds[FINDROOT_CMD]) == 0) { - BAM_DPRINTF((D_IS_FINDROOT_CMD, fcn, - arg)); + BAM_DPRINTF(("%s: setting " + "FINDROOT: %s\n", fcn, arg)); curr_ent->flags |= BAM_ENTRY_FINDROOT; } else if (strcmp(cmd, menu_cmds[CHAINLOADER_CMD]) == 0) { - BAM_DPRINTF((D_IS_CHAINLOADER_CMD, fcn, - arg)); + BAM_DPRINTF(("%s: setting " + "CHAINLOADER: %s\n", fcn, arg)); curr_ent->flags |= BAM_ENTRY_CHAINLOADER; } else if (kernel_parser(curr_ent, cmd, arg, @@ -4882,7 +5031,8 @@ menu_read(char *menu_path) } if (fclose(fp) == EOF) { - bam_error(CLOSE_FAIL, menu_path, strerror(errno)); + bam_error(_("failed to close file: %s: %s\n"), menu_path, + strerror(errno)); } return (mp); @@ -4908,7 +5058,7 @@ selector(menu_t *mp, char *opt, int *entry, char **title) eq = strchr(opt_dup, '='); if (eq == NULL) { - bam_error(INVALID_OPT, opt); + bam_error(_("invalid option: %s\n"), opt); free(opt_dup); return (BAM_ERROR); } @@ -4918,7 +5068,7 @@ selector(menu_t *mp, char *opt, int *entry, char **title) assert(mp->end); entryNum = s_strtol(eq + 1); if (entryNum < 0 || entryNum > mp->end->entryNum) { - bam_error(INVALID_ENTRY, eq + 1); + bam_error(_("invalid boot entry number: %s\n"), eq + 1); free(opt_dup); return (BAM_ERROR); } @@ -4926,7 +5076,7 @@ selector(menu_t *mp, char *opt, int *entry, char **title) } else if (title && strcmp(opt_dup, menu_cmds[TITLE_CMD]) == 0) { *title = opt + (eq - opt_dup) + 1; } else { - bam_error(INVALID_OPT, opt); + bam_error(_("invalid option: %s\n"), opt); free(opt_dup); return (BAM_ERROR); } @@ -4954,11 +5104,11 @@ list_entry(menu_t *mp, char *menu_path, char *opt) assert(menu_path); /* opt is optional */ - BAM_DPRINTF((D_FUNC_ENTRY2, "list_entry", menu_path, + BAM_DPRINTF(("%s: entered. args: %s %s\n", "list_entry", menu_path, opt ? opt : "<NULL>")); if (mp->start == NULL) { - bam_error(NO_MENU, menu_path); + bam_error(_("menu file not found: %s\n"), menu_path); return (BAM_ERROR); } @@ -4977,13 +5127,13 @@ list_entry(menu_t *mp, char *menu_path, char *opt) if (lp->flags == BAM_COMMENT || lp->flags == BAM_EMPTY) continue; if (opt == NULL && lp->flags == BAM_TITLE) { - bam_print(PRINT_TITLE, lp->entryNum, + bam_print(_("%d %s\n"), lp->entryNum, lp->arg); found = 1; continue; } if (entry != ENTRY_INIT && lp->entryNum == entry) { - bam_print(PRINT, lp->line); + bam_print(_("%s\n"), lp->line); found = 1; continue; } @@ -4996,7 +5146,7 @@ list_entry(menu_t *mp, char *menu_path, char *opt) */ if (title && lp->flags == BAM_TITLE && lp->arg && strncmp(title, lp->arg, strlen(title)) == 0) { - bam_print(PRINT, lp->line); + bam_print(_("%s\n"), lp->line); entry = lp->entryNum; found = 1; continue; @@ -5004,7 +5154,7 @@ list_entry(menu_t *mp, char *menu_path, char *opt) } if (!found) { - bam_error(NO_MATCH_ENTRY); + bam_error(_("no matching entry found\n")); return (BAM_ERROR); } @@ -5031,7 +5181,7 @@ add_boot_entry(menu_t *mp, INJECT_ERROR1("ADD_BOOT_ENTRY_FINDROOT_NULL", findroot = NULL); if (findroot == NULL) { - bam_error(NULL_FINDROOT); + bam_error(_("can't find argument for findroot command\n")); return (BAM_ERROR); } @@ -5039,12 +5189,13 @@ add_boot_entry(menu_t *mp, title = "Solaris"; /* default to Solaris */ } if (kernel == NULL) { - bam_error(SUBOPT_MISS, menu_cmds[KERNEL_CMD]); + bam_error(_("missing suboption: %s\n"), menu_cmds[KERNEL_CMD]); return (BAM_ERROR); } if (module == NULL) { if (bam_direct != BAM_DIRECT_DBOOT) { - bam_error(SUBOPT_MISS, menu_cmds[MODULE_CMD]); + bam_error(_("missing suboption: %s\n"), + menu_cmds[MODULE_CMD]); return (BAM_ERROR); } @@ -5084,7 +5235,8 @@ add_boot_entry(menu_t *mp, (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s", menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], findroot); line_parser(mp, linebuf, &lineNum, &entryNum); - BAM_DPRINTF((D_ADD_FINDROOT_NUM, fcn, lineNum, entryNum)); + BAM_DPRINTF(("%s: findroot added: line#: %d: entry#: %d\n", + fcn, lineNum, entryNum)); if (bootfs != NULL) { (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s", @@ -5150,7 +5302,8 @@ delete_boot_entry(menu_t *mp, int entryNum, int quiet) do { freed = lp; lp = lp->next; /* prev stays the same */ - BAM_DPRINTF((D_FREEING_LINE, fcn, freed->lineNum)); + BAM_DPRINTF(("%s: freeing line: %d\n", + fcn, freed->lineNum)); unlink_line(mp, freed); line_free(freed); } while (freed != ent->end); @@ -5165,7 +5318,7 @@ delete_boot_entry(menu_t *mp, int entryNum, int quiet) mp->entries = ent; if (ent) ent->prev = tmp->prev; - BAM_DPRINTF((D_FREEING_ENTRY, fcn, tmp->entryNum)); + BAM_DPRINTF(("%s: freeing entry: %d\n", fcn, tmp->entryNum)); free(tmp); tmp = NULL; deleted = 1; @@ -5175,7 +5328,7 @@ delete_boot_entry(menu_t *mp, int entryNum, int quiet) if (!deleted && entryNum != ALL_ENTRIES) { if (quiet == DBE_PRINTERR) - bam_error(NO_BOOTADM_MATCH); + bam_error(_("no matching bootadm entry found\n")); return (BAM_ERROR); } @@ -5195,10 +5348,10 @@ delete_all_entries(menu_t *mp, char *dummy, char *opt) assert(dummy == NULL); assert(opt == NULL); - BAM_DPRINTF((D_FUNC_ENTRY0, "delete_all_entries")); + BAM_DPRINTF(("%s: entered. No args\n", "delete_all_entries")); if (mp->start == NULL) { - bam_print(EMPTY_MENU); + bam_print(_("the GRUB menu is empty\n")); return (BAM_SUCCESS); } @@ -5225,7 +5378,8 @@ create_diskmap(char *osroot) ret = snprintf(path, sizeof (path), "%s/%s", osroot, CREATE_DISKMAP); if (ret >= sizeof (path)) { - bam_error(PATH_TOO_LONG, osroot); + bam_error(_("unable to create path on mountpoint %s, " + "path too long\n"), osroot); return (NULL); } if (is_safe_exec(path) == BAM_ERROR) @@ -5238,9 +5392,11 @@ create_diskmap(char *osroot) fp = fopen(GRUBDISK_MAP, "r"); INJECT_ERROR1("DISKMAP_CREATE_FAIL", fp = NULL); if (fp) { - BAM_DPRINTF((D_CREATED_DISKMAP, fcn, GRUBDISK_MAP)); + BAM_DPRINTF(("%s: created diskmap file: %s\n", + fcn, GRUBDISK_MAP)); } else { - BAM_DPRINTF((D_CREATE_DISKMAP_FAIL, fcn, GRUBDISK_MAP)); + BAM_DPRINTF(("%s: FAILED to create diskmap file: %s\n", + fcn, GRUBDISK_MAP)); } } return (fp); @@ -5365,13 +5521,14 @@ get_grubroot(char *osroot, char *osdev, char *menu_root) INJECT_ERROR1("GRUBROOT_INVALID_OSDEV", ctdname = NULL); if (ctdname == NULL) { - bam_error(INVALID_DEV_DSK, osdev); + bam_error(_("not a /dev/[r]dsk name: %s\n"), osdev); return (NULL); } if (menu_root && !menu_on_bootdisk(osroot, menu_root)) { /* menu bears no resemblance to our reality */ - bam_error(CANNOT_GRUBROOT_BOOTDISK, osdev); + bam_error(_("cannot get (hd?,?,?) for menu. menu not on " + "bootdisk: %s\n"), osdev); return (NULL); } @@ -5382,7 +5539,8 @@ get_grubroot(char *osroot, char *osdev, char *menu_root) fp = create_diskmap(osroot); if (fp == NULL) { - bam_error(DISKMAP_FAIL, osroot); + bam_error(_("create_diskmap command failed for OS root: %s.\n"), + osroot); return (NULL); } @@ -5407,14 +5565,16 @@ get_grubroot(char *osroot, char *osdev, char *menu_root) INJECT_ERROR1("GRUBROOT_BIOSDEV_FAIL", found = 0); if (found == 0) { - bam_error(BIOSDEV_SKIP, osdev); + bam_error(_("not using biosdev command for disk: %s.\n"), + osdev); return (NULL); } fdiskpart = get_partition(osdev); INJECT_ERROR1("GRUBROOT_FDISK_FAIL", fdiskpart = PARTNO_NOTFOUND); if (fdiskpart == PARTNO_NOTFOUND) { - bam_error(FDISKPART_FAIL, osdev); + bam_error(_("failed to determine fdisk partition: %s\n"), + osdev); return (NULL); } @@ -5453,14 +5613,15 @@ find_primary_common(char *mntpt, char *fstype) mntpt, GRUBSIGN_DIR); if (stat(signdir, &sb) == -1) { - BAM_DPRINTF((D_NO_SIGNDIR, fcn, signdir)); + BAM_DPRINTF(("%s: no sign dir: %s\n", fcn, signdir)); return (NULL); } dirp = opendir(signdir); INJECT_ERROR1("SIGNDIR_OPENDIR_FAIL", dirp = NULL); if (dirp == NULL) { - bam_error(OPENDIR_FAILED, signdir, strerror(errno)); + bam_error(_("opendir of %s failed: %s\n"), signdir, + strerror(errno)); return (NULL); } @@ -5492,7 +5653,7 @@ find_primary_common(char *mntpt, char *fstype) } } - BAM_DPRINTF((D_EXIST_PRIMARY_SIGNS, fcn, + BAM_DPRINTF(("%s: existing primary signs: zfs=%s ufs=%s lu=%s\n", fcn, zfs ? zfs : "NULL", ufs ? ufs : "NULL", lu ? lu : "NULL")); @@ -5503,11 +5664,13 @@ find_primary_common(char *mntpt, char *fstype) } if (strcmp(fstype, "ufs") == 0 && zfs) { - bam_error(SIGN_FSTYPE_MISMATCH, zfs, "ufs"); + bam_error(_("found mismatched boot signature %s for " + "filesystem type: %s.\n"), zfs, "ufs"); free(zfs); zfs = NULL; } else if (strcmp(fstype, "zfs") == 0 && ufs) { - bam_error(SIGN_FSTYPE_MISMATCH, ufs, "zfs"); + bam_error(_("found mismatched boot signature %s for " + "filesystem type: %s.\n"), ufs, "zfs"); free(ufs); ufs = NULL; } @@ -5516,7 +5679,7 @@ find_primary_common(char *mntpt, char *fstype) /* For now, we let Live Upgrade take care of its signature itself */ if (lu) { - BAM_DPRINTF((D_FREEING_LU_SIGNS, fcn, lu)); + BAM_DPRINTF(("%s: feeing LU sign: %s\n", fcn, lu)); free(lu); lu = NULL; } @@ -5547,9 +5710,11 @@ find_backup_common(char *mntpt, char *fstype) if (bfp == NULL) { error = errno; if (bam_verbose) { - bam_error(OPEN_FAIL, backup, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), + backup, strerror(error)); } - BAM_DPRINTF((D_OPEN_FAIL, fcn, backup, strerror(error))); + BAM_DPRINTF(("%s: failed to open %s: %s\n", + fcn, backup, strerror(error))); return (NULL); } @@ -5576,7 +5741,7 @@ find_backup_common(char *mntpt, char *fstype) } } - BAM_DPRINTF((D_EXIST_BACKUP_SIGNS, fcn, + BAM_DPRINTF(("%s: existing backup signs: zfs=%s ufs=%s lu=%s\n", fcn, zfs ? zfs : "NULL", ufs ? ufs : "NULL", lu ? lu : "NULL")); @@ -5587,11 +5752,13 @@ find_backup_common(char *mntpt, char *fstype) } if (strcmp(fstype, "ufs") == 0 && zfs) { - bam_error(SIGN_FSTYPE_MISMATCH, zfs, "ufs"); + bam_error(_("found mismatched boot signature %s for " + "filesystem type: %s.\n"), zfs, "ufs"); free(zfs); zfs = NULL; } else if (strcmp(fstype, "zfs") == 0 && ufs) { - bam_error(SIGN_FSTYPE_MISMATCH, ufs, "zfs"); + bam_error(_("found mismatched boot signature %s for " + "filesystem type: %s.\n"), ufs, "zfs"); free(ufs); ufs = NULL; } @@ -5600,7 +5767,7 @@ find_backup_common(char *mntpt, char *fstype) /* For now, we let Live Upgrade take care of its signature itself */ if (lu) { - BAM_DPRINTF((D_FREEING_LU_SIGNS, fcn, lu)); + BAM_DPRINTF(("%s: feeing LU sign: %s\n", fcn, lu)); free(lu); lu = NULL; } @@ -5617,9 +5784,10 @@ find_ufs_existing(char *osroot) sign = find_primary_common(osroot, "ufs"); if (sign == NULL) { sign = find_backup_common(osroot, "ufs"); - BAM_DPRINTF((D_EXIST_BACKUP_SIGN, fcn, sign ? sign : "NULL")); + BAM_DPRINTF(("%s: existing backup sign: %s\n", fcn, + sign ? sign : "NULL")); } else { - BAM_DPRINTF((D_EXIST_PRIMARY_SIGN, fcn, sign)); + BAM_DPRINTF(("%s: existing primary sign: %s\n", fcn, sign)); } return (sign); @@ -5635,13 +5803,14 @@ get_mountpoint(char *special, char *fstype) int ret; const char *fcn = "get_mountpoint()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, special, fstype)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, special, fstype)); mntfp = fopen(MNTTAB, "r"); error = errno; INJECT_ERROR1("MNTTAB_ERR_GET_MNTPT", mntfp = NULL); if (mntfp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), + MNTTAB, strerror(error)); return (NULL); } @@ -5652,14 +5821,16 @@ get_mountpoint(char *special, char *fstype) INJECT_ERROR1("GET_MOUNTPOINT_MNTANY", ret = 1); if (ret != 0) { (void) fclose(mntfp); - BAM_DPRINTF((D_NO_MNTPT, fcn, special, fstype)); + BAM_DPRINTF(("%s: no mount-point for special=%s and " + "fstype=%s\n", fcn, special, fstype)); return (NULL); } (void) fclose(mntfp); assert(mp.mnt_mountp); - BAM_DPRINTF((D_GET_MOUNTPOINT_RET, fcn, special, mp.mnt_mountp)); + BAM_DPRINTF(("%s: returning mount-point for special %s: %s\n", + fcn, special, mp.mnt_mountp)); return (s_strdup(mp.mnt_mountp)); } @@ -5680,7 +5851,7 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) int ret; const char *fcn = "mount_legacy_dataset()"; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, pool)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, pool)); *mnted = ZFS_MNT_ERROR; @@ -5691,13 +5862,14 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("Z_MOUNT_LEG_GET_MOUNTED_CMD", ret = 1); if (ret != 0) { - bam_error(ZFS_MNTED_FAILED, pool); + bam_error(_("failed to determine mount status of ZFS " + "pool %s\n"), pool); return (NULL); } INJECT_ERROR1("Z_MOUNT_LEG_GET_MOUNTED_OUT", flist.head = NULL); if ((flist.head == NULL) || (flist.head != flist.tail)) { - bam_error(BAD_ZFS_MNTED, pool); + bam_error(_("ZFS pool %s has bad mount status\n"), pool); filelist_free(&flist); return (NULL); } @@ -5709,7 +5881,8 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) filelist_free(&flist); *mnted = LEGACY_ALREADY; /* get_mountpoint returns a strdup'ed string */ - BAM_DPRINTF((D_Z_MOUNT_TOP_LEG_ALREADY, fcn, pool)); + BAM_DPRINTF(("%s: legacy pool %s already mounted\n", + fcn, pool)); return (get_mountpoint(pool, "zfs")); } @@ -5724,15 +5897,18 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) ret = stat(tmpmnt, &sb); if (ret == -1) { - BAM_DPRINTF((D_Z_MOUNT_TOP_LEG_MNTPT_ABS, fcn, pool, tmpmnt)); + BAM_DPRINTF(("%s: legacy pool %s mount-point %s absent\n", + fcn, pool, tmpmnt)); ret = mkdirp(tmpmnt, DIR_PERMS); INJECT_ERROR1("Z_MOUNT_TOP_LEG_MNTPT_MKDIRP", ret = -1); if (ret == -1) { - bam_error(MKDIR_FAILED, tmpmnt, strerror(errno)); + bam_error(_("mkdir of %s failed: %s\n"), tmpmnt, + strerror(errno)); return (NULL); } } else { - BAM_DPRINTF((D_Z_MOUNT_TOP_LEG_MNTPT_PRES, fcn, pool, tmpmnt)); + BAM_DPRINTF(("%s: legacy pool %s mount-point %s is already " + "present\n", fcn, pool, tmpmnt)); } (void) snprintf(cmd, sizeof (cmd), @@ -5742,13 +5918,14 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("Z_MOUNT_TOP_LEG_MOUNT_CMD", ret = 1); if (ret != 0) { - bam_error(ZFS_MOUNT_FAILED, pool); + bam_error(_("mount of ZFS pool %s failed\n"), pool); (void) rmdir(tmpmnt); return (NULL); } *mnted = LEGACY_MOUNTED; - BAM_DPRINTF((D_Z_MOUNT_TOP_LEG_MOUNTED, fcn, pool, tmpmnt)); + BAM_DPRINTF(("%s: legacy pool %s successfully mounted at %s\n", + fcn, pool, tmpmnt)); return (s_strdup(tmpmnt)); } @@ -5757,7 +5934,7 @@ mount_legacy_dataset(char *pool, zfs_mnted_t *mnted) * Returns: The mountpoint of the top dataset or NULL on error * mnted returns one of the above values defined for zfs_mnted_t */ -static char * +char * mount_top_dataset(char *pool, zfs_mnted_t *mnted) { char cmd[PATH_MAX]; @@ -5770,7 +5947,7 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) *mnted = ZFS_MNT_ERROR; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, pool)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, pool)); /* * First check if the top dataset is a "legacy" dataset @@ -5781,7 +5958,8 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("Z_MOUNT_TOP_GET_MNTPT", ret = 1); if (ret != 0) { - bam_error(ZFS_MNTPT_FAILED, pool); + bam_error(_("failed to determine mount point of ZFS pool %s\n"), + pool); return (NULL); } @@ -5789,14 +5967,14 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) char *legacy = strtok(flist.head->line, " \t\n"); if (legacy && strcmp(legacy, "legacy") == 0) { filelist_free(&flist); - BAM_DPRINTF((D_Z_IS_LEGACY, fcn, pool)); + BAM_DPRINTF(("%s: is legacy, pool=%s\n", fcn, pool)); return (mount_legacy_dataset(pool, mnted)); } } filelist_free(&flist); - BAM_DPRINTF((D_Z_IS_NOT_LEGACY, fcn, pool)); + BAM_DPRINTF(("%s: is *NOT* legacy, pool=%s\n", fcn, pool)); (void) snprintf(cmd, sizeof (cmd), "/sbin/zfs get -Ho value mounted %s", @@ -5805,13 +5983,14 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_GET_MOUNTED", ret = 1); if (ret != 0) { - bam_error(ZFS_MNTED_FAILED, pool); + bam_error(_("failed to determine mount status of ZFS " + "pool %s\n"), pool); return (NULL); } INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_GET_MOUNTED_VAL", flist.head = NULL); if ((flist.head == NULL) || (flist.head != flist.tail)) { - bam_error(BAD_ZFS_MNTED, pool); + bam_error(_("ZFS pool %s has bad mount status\n"), pool); filelist_free(&flist); return (NULL); } @@ -5822,12 +6001,14 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) if (strcmp(is_mounted, "no") != 0) { filelist_free(&flist); *mnted = ZFS_ALREADY; - BAM_DPRINTF((D_Z_MOUNT_TOP_NONLEG_MOUNTED_ALREADY, fcn, pool)); + BAM_DPRINTF(("%s: non-legacy pool %s mounted already\n", + fcn, pool)); goto mounted; } filelist_free(&flist); - BAM_DPRINTF((D_Z_MOUNT_TOP_NONLEG_MOUNTED_NOT_ALREADY, fcn, pool)); + BAM_DPRINTF(("%s: non-legacy pool %s *NOT* already mounted\n", + fcn, pool)); /* top dataset is not mounted. Mount it now */ (void) snprintf(cmd, sizeof (cmd), @@ -5835,11 +6016,11 @@ mount_top_dataset(char *pool, zfs_mnted_t *mnted) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_MOUNT_CMD", ret = 1); if (ret != 0) { - bam_error(ZFS_MOUNT_FAILED, pool); + bam_error(_("mount of ZFS pool %s failed\n"), pool); return (NULL); } *mnted = ZFS_MOUNTED; - BAM_DPRINTF((D_Z_MOUNT_TOP_NONLEG_MOUNTED_NOW, fcn, pool)); + BAM_DPRINTF(("%s: non-legacy pool %s mounted now\n", fcn, pool)); /*FALLTHRU*/ mounted: /* @@ -5852,38 +6033,41 @@ mounted: ret = exec_cmd(cmd, &flist); INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_GET_MNTPT_CMD", ret = 1); if (ret != 0) { - bam_error(ZFS_MNTPT_FAILED, pool); + bam_error(_("failed to determine mount point of ZFS pool %s\n"), + pool); goto error; } INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_GET_MNTPT_OUT", flist.head = NULL); if ((flist.head == NULL) || (flist.head != flist.tail)) { - bam_error(NULL_ZFS_MNTPT, pool); + bam_error(_("ZFS pool %s has no mount-point\n"), pool); goto error; } mntpt = strtok(flist.head->line, " \t\n"); INJECT_ERROR1("Z_MOUNT_TOP_NONLEG_GET_MNTPT_STRTOK", mntpt = "foo"); if (*mntpt != '/') { - bam_error(BAD_ZFS_MNTPT, pool, mntpt); + bam_error(_("ZFS pool %s has bad mount-point %s\n"), + pool, mntpt); goto error; } zmntpt = s_strdup(mntpt); filelist_free(&flist); - BAM_DPRINTF((D_Z_MOUNT_TOP_NONLEG_MNTPT, fcn, pool, zmntpt)); + BAM_DPRINTF(("%s: non-legacy pool %s is mounted at %s\n", + fcn, pool, zmntpt)); return (zmntpt); error: filelist_free(&flist); (void) umount_top_dataset(pool, *mnted, NULL); - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); return (NULL); } -static int +int umount_top_dataset(char *pool, zfs_mnted_t mnted, char *mntpt) { char cmd[PATH_MAX]; @@ -5895,8 +6079,8 @@ umount_top_dataset(char *pool, zfs_mnted_t mnted, char *mntpt) case LEGACY_ALREADY: case ZFS_ALREADY: /* nothing to do */ - BAM_DPRINTF((D_Z_UMOUNT_TOP_ALREADY_NOP, fcn, pool, - mntpt ? mntpt : "NULL")); + BAM_DPRINTF(("%s: pool %s was already mounted at %s, Nothing " + "to umount\n", fcn, pool, mntpt ? mntpt : "NULL")); free(mntpt); return (BAM_SUCCESS); case LEGACY_MOUNTED: @@ -5905,14 +6089,15 @@ umount_top_dataset(char *pool, zfs_mnted_t mnted, char *mntpt) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("Z_UMOUNT_TOP_LEGACY_UMOUNT_FAIL", ret = 1); if (ret != 0) { - bam_error(UMOUNT_FAILED, pool); + bam_error(_("umount of %s failed\n"), pool); free(mntpt); return (BAM_ERROR); } if (mntpt) (void) rmdir(mntpt); free(mntpt); - BAM_DPRINTF((D_Z_UMOUNT_TOP_LEGACY, fcn, pool)); + BAM_DPRINTF(("%s: legacy pool %s was mounted by us, " + "successfully unmounted\n", fcn, pool)); return (BAM_SUCCESS); case ZFS_MOUNTED: free(mntpt); @@ -5921,13 +6106,15 @@ umount_top_dataset(char *pool, zfs_mnted_t mnted, char *mntpt) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("Z_UMOUNT_TOP_NONLEG_UMOUNT_FAIL", ret = 1); if (ret != 0) { - bam_error(UMOUNT_FAILED, pool); + bam_error(_("umount of %s failed\n"), pool); return (BAM_ERROR); } - BAM_DPRINTF((D_Z_UMOUNT_TOP_NONLEG, fcn, pool)); + BAM_DPRINTF(("%s: nonleg pool %s was mounted by us, " + "successfully unmounted\n", fcn, pool)); return (BAM_SUCCESS); default: - bam_error(INT_BAD_MNTSTATE, pool); + bam_error(_("Internal error: bad saved mount state for " + "pool %s\n"), pool); return (BAM_ERROR); } /*NOTREACHED*/ @@ -5952,11 +6139,11 @@ get_pool(char *osdev) INJECT_ERROR1("GET_POOL_OSDEV", osdev = NULL); if (osdev == NULL) { - bam_error(GET_POOL_OSDEV_NULL); + bam_error(_("NULL device: cannot determine pool name\n")); return (NULL); } - BAM_DPRINTF((D_GET_POOL_OSDEV, fcn, osdev)); + BAM_DPRINTF(("%s: osdev arg = %s\n", fcn, osdev)); if (osdev[0] != '/') { (void) strlcpy(buf, osdev, sizeof (buf)); @@ -5964,11 +6151,12 @@ get_pool(char *osdev) if (slash) *slash = '\0'; pool = s_strdup(buf); - BAM_DPRINTF((D_GET_POOL_RET, fcn, pool)); + BAM_DPRINTF(("%s: got pool. pool = %s\n", fcn, pool)); return (pool); } else if (strncmp(osdev, "/dev/dsk/", strlen("/dev/dsk/")) != 0 && strncmp(osdev, "/dev/rdsk/", strlen("/dev/rdsk/")) != 0) { - bam_error(GET_POOL_BAD_OSDEV, osdev); + bam_error(_("invalid device %s: cannot determine pool name\n"), + osdev); return (NULL); } @@ -5983,13 +6171,13 @@ get_pool(char *osdev) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("GET_POOL_FSTYP", ret = 1); if (ret != 0) { - bam_error(FSTYP_A_FAILED, osdev); + bam_error(_("fstyp -a on device %s failed\n"), osdev); return (NULL); } INJECT_ERROR1("GET_POOL_FSTYP_OUT", flist.head = NULL); if ((flist.head == NULL) || (flist.head != flist.tail)) { - bam_error(NULL_FSTYP_A, osdev); + bam_error(_("NULL fstyp -a output for device %s\n"), osdev); filelist_free(&flist); return (NULL); } @@ -5998,7 +6186,7 @@ get_pool(char *osdev) cp = strtok(NULL, "'"); INJECT_ERROR1("GET_POOL_FSTYP_STRTOK", cp = NULL); if (cp == NULL) { - bam_error(BAD_FSTYP_A, osdev); + bam_error(_("bad fstyp -a output for device %s\n"), osdev); filelist_free(&flist); return (NULL); } @@ -6007,7 +6195,7 @@ get_pool(char *osdev) filelist_free(&flist); - BAM_DPRINTF((D_GET_POOL_RET, fcn, pool)); + BAM_DPRINTF(("%s: got pool. pool = %s\n", fcn, pool)); return (pool); } @@ -6024,14 +6212,15 @@ find_zfs_existing(char *osdev) pool = get_pool(osdev); INJECT_ERROR1("ZFS_FIND_EXIST_POOL", pool = NULL); if (pool == NULL) { - bam_error(ZFS_GET_POOL_FAILED, osdev); + bam_error(_("failed to get pool for device: %s\n"), osdev); return (NULL); } mntpt = mount_top_dataset(pool, &mnted); INJECT_ERROR1("ZFS_FIND_EXIST_MOUNT_TOP", mntpt = NULL); if (mntpt == NULL) { - bam_error(ZFS_MOUNT_TOP_DATASET_FAILED, pool); + bam_error(_("failed to mount top dataset for pool: %s\n"), + pool); free(pool); return (NULL); } @@ -6039,9 +6228,10 @@ find_zfs_existing(char *osdev) sign = find_primary_common(mntpt, "zfs"); if (sign == NULL) { sign = find_backup_common(mntpt, "zfs"); - BAM_DPRINTF((D_EXIST_BACKUP_SIGN, fcn, sign ? sign : "NULL")); + BAM_DPRINTF(("%s: existing backup sign: %s\n", fcn, + sign ? sign : "NULL")); } else { - BAM_DPRINTF((D_EXIST_PRIMARY_SIGN, fcn, sign)); + BAM_DPRINTF(("%s: existing primary sign: %s\n", fcn, sign)); } (void) umount_top_dataset(pool, mnted, mntpt); @@ -6058,13 +6248,14 @@ find_existing_sign(char *osroot, char *osdev, char *fstype) INJECT_ERROR1("FIND_EXIST_NOTSUP_FS", fstype = "foofs"); if (strcmp(fstype, "ufs") == 0) { - BAM_DPRINTF((D_CHECK_UFS_EXIST_SIGN, fcn)); + BAM_DPRINTF(("%s: checking for existing UFS sign\n", fcn)); return (find_ufs_existing(osroot)); } else if (strcmp(fstype, "zfs") == 0) { - BAM_DPRINTF((D_CHECK_ZFS_EXIST_SIGN, fcn)); + BAM_DPRINTF(("%s: checking for existing ZFS sign\n", fcn)); return (find_zfs_existing(osdev)); } else { - bam_error(GRUBSIGN_NOTSUP, fstype); + bam_error(_("boot signature not supported for fstype: %s\n"), + fstype); return (NULL); } } @@ -6122,7 +6313,8 @@ cache_mnttab(void) error = errno; INJECT_ERROR1("CACHE_MNTTAB_MNTTAB_ERR", mfp = NULL); if (mfp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), MNTTAB, + strerror(error)); return (NULL); } @@ -6143,8 +6335,8 @@ cache_mnttab(void) mcp->mc_special = s_strdup(ctds); mcp->mc_mntpt = s_strdup(mnt.mnt_mountp); mcp->mc_fstype = s_strdup(mnt.mnt_fstype); - BAM_DPRINTF((D_CACHE_MNTS, fcn, ctds, - mnt.mnt_mountp, mnt.mnt_fstype)); + BAM_DPRINTF(("%s: caching mount: special=%s, mntpt=%s, " + "fstype=%s\n", fcn, ctds, mnt.mnt_mountp, mnt.mnt_fstype)); idx = mhash_fcn(ctds); mcp->mc_next = mhp->mh_hash[idx]; mhp->mh_hash[idx] = mcp; @@ -6191,7 +6383,7 @@ search_hash(mhash_t *mhp, char *special, char **mntpt) INJECT_ERROR1("SEARCH_HASH_FULL_PATH", special = "/foo"); if (strchr(special, '/')) { - bam_error(INVALID_MHASH_KEY, special); + bam_error(_("invalid key for mnttab hash: %s\n"), special); return (MH_ERROR); } @@ -6203,13 +6395,13 @@ search_hash(mhash_t *mhp, char *special, char **mntpt) } if (mcp == NULL) { - BAM_DPRINTF((D_MNTTAB_HASH_NOMATCH, fcn, special)); + BAM_DPRINTF(("%s: no match in cache for: %s\n", fcn, special)); return (MH_NOMATCH); } assert(strcmp(mcp->mc_fstype, "ufs") == 0); *mntpt = mcp->mc_mntpt; - BAM_DPRINTF((D_MNTTAB_HASH_MATCH, fcn, special)); + BAM_DPRINTF(("%s: *MATCH* in cache for: %s\n", fcn, special)); return (MH_MATCH); } @@ -6227,7 +6419,8 @@ check_add_ufs_sign_to_list(FILE *tfp, char *mntpt) sign = find_existing_sign(mntpt, NULL, "ufs"); if (sign == NULL) { /* No existing signature, nothing to add to list */ - BAM_DPRINTF((D_NO_SIGN_TO_LIST, fcn, mntpt)); + BAM_DPRINTF(("%s: no sign on %s to add to signlist\n", + fcn, mntpt)); return (0); } @@ -6237,7 +6430,7 @@ check_add_ufs_sign_to_list(FILE *tfp, char *mntpt) INJECT_ERROR1("UFS_MNTPT_SIGN_NOTUFS", signline = "pool_rpool10\n"); if (strncmp(signline, GRUBSIGN_UFS_PREFIX, strlen(GRUBSIGN_UFS_PREFIX))) { - bam_error(INVALID_UFS_SIGNATURE, sign); + bam_error(_("invalid UFS boot signature %s\n"), sign); free(sign); /* ignore invalid signatures */ return (0); @@ -6247,14 +6440,16 @@ check_add_ufs_sign_to_list(FILE *tfp, char *mntpt) error = errno; INJECT_ERROR1("SIGN_LIST_PUTS_ERROR", len = 0); if (len != strlen(signline)) { - bam_error(SIGN_LIST_FPUTS_ERR, sign, strerror(error)); + bam_error(_("failed to write signature %s to signature " + "list: %s\n"), sign, strerror(error)); free(sign); return (-1); } free(sign); - BAM_DPRINTF((D_SIGN_LIST_PUTS_DONE, fcn, mntpt)); + BAM_DPRINTF(("%s: successfully added sign on %s to signlist\n", + fcn, mntpt)); return (0); } @@ -6291,7 +6486,7 @@ process_slice_common(char *slice, FILE *tfp, mhash_t *mhp, char *tmpmnt) (void) snprintf(path, sizeof (path), "/dev/rdsk/%s", slice); if (stat(path, &sbuf) == -1) { - BAM_DPRINTF((D_SLICE_ENOENT, fcn, path)); + BAM_DPRINTF(("%s: slice does not exist: %s\n", fcn, path)); return (0); } @@ -6302,13 +6497,14 @@ process_slice_common(char *slice, FILE *tfp, mhash_t *mhp, char *tmpmnt) if (exec_cmd(cmd, &flist) != 0) { if (bam_verbose) - bam_print(FSTYP_FAILED, slice); + bam_print(_("fstyp failed for slice: %s\n"), slice); return (0); } if ((flist.head == NULL) || (flist.head != flist.tail)) { if (bam_verbose) - bam_print(FSTYP_BAD, slice); + bam_print(_("bad output from fstyp for slice: %s\n"), + slice); filelist_free(&flist); return (0); } @@ -6316,7 +6512,8 @@ process_slice_common(char *slice, FILE *tfp, mhash_t *mhp, char *tmpmnt) fstype = strtok(flist.head->line, " \t\n"); if (fstype == NULL || strcmp(fstype, "ufs") != 0) { if (bam_verbose) - bam_print(NOT_UFS_SLICE, slice, fstype); + bam_print(_("%s is not a ufs slice: %s\n"), + slice, fstype); filelist_free(&flist); return (0); } @@ -6338,7 +6535,8 @@ process_slice_common(char *slice, FILE *tfp, mhash_t *mhp, char *tmpmnt) if (exec_cmd(cmd, NULL) != 0) { if (bam_verbose) - bam_print(MOUNT_FAILED, blkslice, "ufs"); + bam_print(_("mount of %s (fstype %s) failed\n"), + blkslice, "ufs"); return (0); } @@ -6349,7 +6547,7 @@ process_slice_common(char *slice, FILE *tfp, mhash_t *mhp, char *tmpmnt) tmpmnt); if (exec_cmd(cmd, NULL) != 0) { - bam_print(UMOUNT_FAILED, slice); + bam_print(_("umount of %s failed\n"), slice); return (0); } @@ -6387,7 +6585,8 @@ process_vtoc_slices( (void) snprintf(cp, sizeof (slice) - (len - 1), "%u", idx); if (vtoc->v_part[idx].p_size == 0) { - BAM_DPRINTF((D_VTOC_SIZE_ZERO, fcn, slice)); + BAM_DPRINTF(("%s: VTOC: skipping 0-length slice: %s\n", + fcn, slice)); continue; } @@ -6399,10 +6598,12 @@ process_vtoc_slices( case V_VAR: case V_HOME: case V_ALTSCTR: - BAM_DPRINTF((D_VTOC_NOT_ROOT_TAG, fcn, slice)); + BAM_DPRINTF(("%s: VTOC: unsupported tag, " + "skipping: %s\n", fcn, slice)); continue; default: - BAM_DPRINTF((D_VTOC_ROOT_TAG, fcn, slice)); + BAM_DPRINTF(("%s: VTOC: supported tag, checking: %s\n", + fcn, slice)); break; } @@ -6410,10 +6611,12 @@ process_vtoc_slices( switch (vtoc->v_part[idx].p_flag) { case V_UNMNT: case V_RONLY: - BAM_DPRINTF((D_VTOC_NOT_RDWR_FLAG, fcn, slice)); + BAM_DPRINTF(("%s: VTOC: non-RDWR flag, skipping: %s\n", + fcn, slice)); continue; default: - BAM_DPRINTF((D_VTOC_RDWR_FLAG, fcn, slice)); + BAM_DPRINTF(("%s: VTOC: RDWR flag, checking: %s\n", + fcn, slice)); break; } @@ -6456,7 +6659,8 @@ process_efi_slices( (void) snprintf(cp, sizeof (slice) - (len - 1), "%u", idx); if (efi->efi_parts[idx].p_size == 0) { - BAM_DPRINTF((D_EFI_SIZE_ZERO, fcn, slice)); + BAM_DPRINTF(("%s: EFI: skipping 0-length slice: %s\n", + fcn, slice)); continue; } @@ -6468,10 +6672,12 @@ process_efi_slices( case V_VAR: case V_HOME: case V_ALTSCTR: - BAM_DPRINTF((D_EFI_NOT_ROOT_TAG, fcn, slice)); + BAM_DPRINTF(("%s: EFI: unsupported tag, skipping: %s\n", + fcn, slice)); continue; default: - BAM_DPRINTF((D_EFI_ROOT_TAG, fcn, slice)); + BAM_DPRINTF(("%s: EFI: supported tag, checking: %s\n", + fcn, slice)); break; } @@ -6479,10 +6685,12 @@ process_efi_slices( switch (efi->efi_parts[idx].p_flag) { case V_UNMNT: case V_RONLY: - BAM_DPRINTF((D_EFI_NOT_RDWR_FLAG, fcn, slice)); + BAM_DPRINTF(("%s: EFI: non-RDWR flag, skipping: %s\n", + fcn, slice)); continue; default: - BAM_DPRINTF((D_EFI_RDWR_FLAG, fcn, slice)); + BAM_DPRINTF(("%s: EFI: RDWR flag, checking: %s\n", + fcn, slice)); break; } @@ -6514,13 +6722,14 @@ process_slice0(char *s0, FILE *tfp, mhash_t *mhp, char *tmpmnt) (void) snprintf(s0path, sizeof (s0path), "/dev/rdsk/%s", s0); if (stat(s0path, &sbuf) == -1) { - BAM_DPRINTF((D_SLICE0_ENOENT, fcn, s0path)); + BAM_DPRINTF(("%s: slice 0 does not exist: %s\n", fcn, s0path)); return (0); } fd = open(s0path, O_NONBLOCK|O_RDONLY); if (fd == -1) { - bam_error(OPEN_FAIL, s0path, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), s0path, + strerror(errno)); return (0); } @@ -6528,24 +6737,30 @@ process_slice0(char *s0, FILE *tfp, mhash_t *mhp, char *tmpmnt) retval = ((err = read_vtoc(fd, &vtoc)) >= 0) ? 0 : err; switch (retval) { case VT_EIO: - BAM_DPRINTF((D_VTOC_READ_FAIL, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: failed to read: %s\n", + fcn, s0path)); break; case VT_EINVAL: - BAM_DPRINTF((D_VTOC_INVALID, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: is INVALID: %s\n", + fcn, s0path)); break; case VT_ERROR: - BAM_DPRINTF((D_VTOC_UNKNOWN_ERR, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: unknown error while " + "reading: %s\n", fcn, s0path)); break; case VT_ENOTSUP: e_flag = 1; - BAM_DPRINTF((D_VTOC_NOTSUP, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: not supported: %s\n", + fcn, s0path)); break; case 0: v_flag = 1; - BAM_DPRINTF((D_VTOC_READ_SUCCESS, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: SUCCESS reading: %s\n", + fcn, s0path)); break; default: - BAM_DPRINTF((D_VTOC_UNKNOWN_RETCODE, fcn, s0path)); + BAM_DPRINTF(("%s: VTOC: READ: unknown return " + "code: %s\n", fcn, s0path)); break; } @@ -6555,23 +6770,28 @@ process_slice0(char *s0, FILE *tfp, mhash_t *mhp, char *tmpmnt) retval = ((err = efi_alloc_and_read(fd, &efi)) >= 0) ? 0 : err; switch (retval) { case VT_EIO: - BAM_DPRINTF((D_EFI_READ_FAIL, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: failed to read: %s\n", + fcn, s0path)); break; case VT_EINVAL: - BAM_DPRINTF((D_EFI_INVALID, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: is INVALID: %s\n", fcn, s0path)); break; case VT_ERROR: - BAM_DPRINTF((D_EFI_UNKNOWN_ERR, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: unknown error while " + "reading: %s\n", fcn, s0path)); break; case VT_ENOTSUP: - BAM_DPRINTF((D_EFI_NOTSUP, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: not supported: %s\n", + fcn, s0path)); break; case 0: e_flag = 1; - BAM_DPRINTF((D_EFI_READ_SUCCESS, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: SUCCESS reading: %s\n", + fcn, s0path)); break; default: - BAM_DPRINTF((D_EFI_UNKNOWN_RETCODE, fcn, s0path)); + BAM_DPRINTF(("%s: EFI: READ: unknown return code: %s\n", + fcn, s0path)); break; } } @@ -6585,7 +6805,8 @@ process_slice0(char *s0, FILE *tfp, mhash_t *mhp, char *tmpmnt) retval = process_efi_slices(s0, efi, tfp, mhp, tmpmnt); } else { - BAM_DPRINTF((D_NOT_VTOC_OR_EFI, fcn, s0path)); + BAM_DPRINTF(("%s: disk has neither VTOC nor EFI: %s\n", + fcn, s0path)); return (0); } @@ -6612,7 +6833,8 @@ FindAllUfsSignatures(void) const char *fcn = "FindAllUfsSignatures()"; if (stat(UFS_SIGNATURE_LIST, &sb) != -1) { - bam_print(SIGNATURE_LIST_EXISTS, UFS_SIGNATURE_LIST); + bam_print(_(" - signature list %s exists\n"), + UFS_SIGNATURE_LIST); return (0); } @@ -6621,7 +6843,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("SIGN_LIST_TMP_TRUNC", fd = -1); if (fd == -1) { - bam_error(OPEN_FAIL, UFS_SIGNATURE_LIST".tmp", strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); return (-1); } @@ -6629,8 +6852,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("SIGN_LIST_TMP_CLOSE", ret = -1); if (ret == -1) { - bam_error(CLOSE_FAIL, UFS_SIGNATURE_LIST".tmp", - strerror(error)); + bam_error(_("failed to close file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (-1); } @@ -6639,7 +6862,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("SIGN_LIST_APPEND_FOPEN", tfp = NULL); if (tfp == NULL) { - bam_error(OPEN_FAIL, UFS_SIGNATURE_LIST".tmp", strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (-1); } @@ -6649,7 +6873,7 @@ FindAllUfsSignatures(void) if (mnttab_hash == NULL) { (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST".tmp"); - bam_error(CACHE_MNTTAB_FAIL, fcn); + bam_error(_("%s: failed to cache /etc/mnttab\n"), fcn); return (-1); } @@ -6661,7 +6885,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("MKDIRP_SIGN_MNT", ret = -1); if (ret == -1) { - bam_error(MKDIR_FAILED, tmpmnt, strerror(error)); + bam_error(_("mkdir of %s failed: %s\n"), tmpmnt, + strerror(error)); free_mnttab(mnttab_hash); (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST".tmp"); @@ -6672,7 +6897,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("OPENDIR_DEV_RDSK", dirp = NULL); if (dirp == NULL) { - bam_error(OPENDIR_FAILED, "/dev/rdsk", strerror(error)); + bam_error(_("opendir of %s failed: %s\n"), "/dev/rdsk", + strerror(error)); goto fail; } @@ -6687,7 +6913,8 @@ FindAllUfsSignatures(void) */ len = strlen(dp->d_name); if (dp->d_name[len - 2 ] != 's' || dp->d_name[len - 1] != '0') { - BAM_DPRINTF((D_SKIP_SLICE_NOTZERO, fcn, dp->d_name)); + BAM_DPRINTF(("%s: skipping non-s0 slice: %s\n", + fcn, dp->d_name)); continue; } @@ -6705,8 +6932,8 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("FCLOSE_SIGNLIST_TMP", ret = EOF); if (ret == EOF) { - bam_error(CLOSE_FAIL, UFS_SIGNATURE_LIST".tmp", - strerror(error)); + bam_error(_("failed to close file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (-1); } @@ -6719,7 +6946,7 @@ FindAllUfsSignatures(void) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("SORT_SIGN_LIST", ret = 1); if (ret != 0) { - bam_error(GRUBSIGN_SORT_FAILED); + bam_error(_("error sorting GRUB UFS boot signatures\n")); (void) unlink(UFS_SIGNATURE_LIST".sorted"); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (-1); @@ -6731,16 +6958,18 @@ FindAllUfsSignatures(void) error = errno; INJECT_ERROR1("RENAME_TMP_SIGNLIST", ret = -1); if (ret == -1) { - bam_error(RENAME_FAIL, UFS_SIGNATURE_LIST, strerror(error)); + bam_error(_("rename to file failed: %s: %s\n"), + UFS_SIGNATURE_LIST, strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".sorted"); return (-1); } if (stat(UFS_SIGNATURE_LIST, &sb) == 0 && sb.st_size == 0) { - BAM_DPRINTF((D_ZERO_LEN_SIGNLIST, fcn, UFS_SIGNATURE_LIST)); + BAM_DPRINTF(("%s: generated zero length signlist: %s.\n", + fcn, UFS_SIGNATURE_LIST)); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); fail: @@ -6750,7 +6979,7 @@ fail: (void) rmdir(tmpmnt); (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST".tmp"); - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); return (-1); } @@ -6767,12 +6996,12 @@ create_ufs_sign(void) int error; const char *fcn = "create_ufs_sign()"; - bam_print(SEARCHING_UFS_SIGN); + bam_print(_(" - searching for UFS boot signatures\n")); ret = FindAllUfsSignatures(); INJECT_ERROR1("FIND_ALL_UFS", ret = -1); if (ret == -1) { - bam_error(ERR_FIND_UFS_SIGN); + bam_error(_("search for UFS boot signatures failed\n")); return (NULL); } @@ -6781,12 +7010,13 @@ create_ufs_sign(void) (void) unlink(UFS_SIGNATURE_LIST)); if (stat(UFS_SIGNATURE_LIST, &sb) == -1 || sb.st_uid != 0) { (void) unlink(UFS_SIGNATURE_LIST); - bam_error(UFS_SIGNATURE_LIST_MISS, UFS_SIGNATURE_LIST); + bam_error(_("missing UFS signature list file: %s\n"), + UFS_SIGNATURE_LIST); return (NULL); } if (sb.st_size == 0) { - bam_print(GRUBSIGN_UFS_NONE); + bam_print(_(" - no existing UFS boot signatures\n")); i = 0; goto found; } @@ -6796,8 +7026,8 @@ create_ufs_sign(void) error = errno; INJECT_ERROR1("FOPEN_SIGN_LIST", tfp = NULL); if (tfp == NULL) { - bam_error(UFS_SIGNATURE_LIST_OPENERR, - UFS_SIGNATURE_LIST, strerror(error)); + bam_error(_("error opening UFS boot signature list " + "file %s: %s\n"), UFS_SIGNATURE_LIST, strerror(error)); (void) unlink(UFS_SIGNATURE_LIST); return (NULL); } @@ -6808,7 +7038,7 @@ create_ufs_sign(void) strlen(GRUBSIGN_UFS_PREFIX)) != 0) { (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST); - bam_error(UFS_BADSIGN, tmpsign); + bam_error(_("bad UFS boot signature: %s\n"), tmpsign); return (NULL); } numstr = tmpsign + strlen(GRUBSIGN_UFS_PREFIX); @@ -6816,7 +7046,7 @@ create_ufs_sign(void) if (numstr[0] == '\0' || !isdigit(numstr[0])) { (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST); - bam_error(UFS_BADSIGN, tmpsign); + bam_error(_("bad UFS boot signature: %s\n"), tmpsign); return (NULL); } @@ -6825,12 +7055,13 @@ create_ufs_sign(void) if (signnum < 0) { (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST); - bam_error(UFS_BADSIGN, tmpsign); + bam_error(_("bad UFS boot signature: %s\n"), tmpsign); return (NULL); } if (i != signnum) { - BAM_DPRINTF((D_FOUND_HOLE_SIGNLIST, fcn, i)); + BAM_DPRINTF(("%s: found hole %d in sign list.\n", + fcn, i)); break; } } @@ -6845,11 +7076,11 @@ found: INJECT_ERROR1("UFS_ADD_TO_SIGN_LIST", ret = -1); if (ret == -1) { (void) unlink(UFS_SIGNATURE_LIST); - bam_error(FAILED_ADD_SIGNLIST, tmpsign); + bam_error(_("failed to add sign %s to signlist.\n"), tmpsign); return (NULL); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (s_strdup(tmpsign)); } @@ -6866,7 +7097,7 @@ get_fstype(char *osroot) INJECT_ERROR1("GET_FSTYPE_OSROOT", osroot = NULL); if (osroot == NULL) { - bam_error(GET_FSTYPE_ARGS); + bam_error(_("no OS mountpoint. Cannot determine fstype\n")); return (NULL); } @@ -6874,7 +7105,8 @@ get_fstype(char *osroot) error = errno; INJECT_ERROR1("GET_FSTYPE_FOPEN", mntfp = NULL); if (mntfp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), MNTTAB, + strerror(error)); return (NULL); } @@ -6886,7 +7118,8 @@ get_fstype(char *osroot) ret = getmntany(mntfp, &mp, &mpref); INJECT_ERROR1("GET_FSTYPE_GETMNTANY", ret = 1); if (ret != 0) { - bam_error(MNTTAB_MNTPT_NOT_FOUND, osroot, MNTTAB); + bam_error(_("failed to find OS mountpoint %s in %s\n"), + osroot, MNTTAB); (void) fclose(mntfp); return (NULL); } @@ -6894,11 +7127,11 @@ get_fstype(char *osroot) INJECT_ERROR1("GET_FSTYPE_NULL", mp.mnt_fstype = NULL); if (mp.mnt_fstype == NULL) { - bam_error(MNTTAB_FSTYPE_NULL, osroot); + bam_error(_("NULL fstype found for OS root %s\n"), osroot); return (NULL); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (s_strdup(mp.mnt_fstype)); } @@ -6910,7 +7143,7 @@ create_zfs_sign(char *osdev) char *pool; const char *fcn = "create_zfs_sign()"; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, osdev)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, osdev)); /* * First find the pool name @@ -6918,17 +7151,17 @@ create_zfs_sign(char *osdev) pool = get_pool(osdev); INJECT_ERROR1("CREATE_ZFS_SIGN_GET_POOL", pool = NULL); if (pool == NULL) { - bam_error(GET_POOL_FAILED, osdev); + bam_error(_("failed to get pool name from %s\n"), osdev); return (NULL); } (void) snprintf(tmpsign, sizeof (tmpsign), "pool_%s", pool); - BAM_DPRINTF((D_CREATED_ZFS_SIGN, fcn, tmpsign)); + BAM_DPRINTF(("%s: created ZFS sign: %s\n", fcn, tmpsign)); free(pool); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (s_strdup(tmpsign)); } @@ -6942,17 +7175,19 @@ create_new_sign(char *osdev, char *fstype) INJECT_ERROR1("NEW_SIGN_FSTYPE", fstype = "foofs"); if (strcmp(fstype, "zfs") == 0) { - BAM_DPRINTF((D_CREATE_NEW_ZFS, fcn)); + BAM_DPRINTF(("%s: created new ZFS sign\n", fcn)); sign = create_zfs_sign(osdev); } else if (strcmp(fstype, "ufs") == 0) { - BAM_DPRINTF((D_CREATE_NEW_UFS, fcn)); + BAM_DPRINTF(("%s: created new UFS sign\n", fcn)); sign = create_ufs_sign(); } else { - bam_error(GRUBSIGN_NOTSUP, fstype); + bam_error(_("boot signature not supported for fstype: %s\n"), + fstype); sign = NULL; } - BAM_DPRINTF((D_CREATED_NEW_SIGN, fcn, sign ? sign : "<NULL>")); + BAM_DPRINTF(("%s: created new sign: %s\n", fcn, + sign ? sign : "<NULL>")); return (sign); } @@ -6977,15 +7212,17 @@ set_backup_common(char *mntpt, char *sign) if (bfp != NULL) { while (s_fgets(tmpsign, sizeof (tmpsign), bfp)) { if (strcmp(tmpsign, sign) == 0) { - BAM_DPRINTF((D_FOUND_IN_BACKUP, fcn, sign)); + BAM_DPRINTF(("%s: found sign (%s) in backup.\n", + fcn, sign)); (void) fclose(bfp); return (0); } } (void) fclose(bfp); - BAM_DPRINTF((D_NOT_FOUND_IN_EXIST_BACKUP, fcn, sign)); + BAM_DPRINTF(("%s: backup exists but sign %s not found\n", + fcn, sign)); } else { - BAM_DPRINTF((D_BACKUP_NOT_EXIST, fcn, backup)); + BAM_DPRINTF(("%s: no backup file (%s) found.\n", fcn, backup)); } /* @@ -7001,12 +7238,13 @@ set_backup_common(char *mntpt, char *sign) ret = stat(bdir, &sb); INJECT_ERROR1("SET_BACKUP_STAT", ret = -1); if (ret == -1) { - BAM_DPRINTF((D_BACKUP_DIR_NOEXIST, fcn, bdir)); + BAM_DPRINTF(("%s: backup dir (%s) does not exist.\n", + fcn, bdir)); ret = mkdirp(bdir, DIR_PERMS); error = errno; INJECT_ERROR1("SET_BACKUP_MKDIRP", ret = -1); if (ret == -1) { - bam_error(GRUBSIGN_BACKUP_MKDIRERR, + bam_error(_("mkdirp() of backup dir failed: %s: %s\n"), GRUBSIGN_BACKUP, strerror(error)); free(backup_dup); return (-1); @@ -7022,8 +7260,8 @@ set_backup_common(char *mntpt, char *sign) error = errno; INJECT_ERROR1("SET_BACKUP_FOPEN_A", bfp = NULL); if (bfp == NULL) { - bam_error(GRUBSIGN_BACKUP_OPENERR, - GRUBSIGN_BACKUP, strerror(error)); + bam_error(_("error opening boot signature backup " + "file %s: %s\n"), GRUBSIGN_BACKUP, strerror(error)); return (-1); } @@ -7033,8 +7271,8 @@ set_backup_common(char *mntpt, char *sign) error = errno; INJECT_ERROR1("SET_BACKUP_FPUTS", ret = 0); if (ret != strlen(tmpsign)) { - bam_error(GRUBSIGN_BACKUP_WRITEERR, - GRUBSIGN_BACKUP, strerror(error)); + bam_error(_("error writing boot signature backup " + "file %s: %s\n"), GRUBSIGN_BACKUP, strerror(error)); (void) fclose(bfp); return (-1); } @@ -7042,9 +7280,10 @@ set_backup_common(char *mntpt, char *sign) (void) fclose(bfp); if (bam_verbose) - bam_print(GRUBSIGN_BACKUP_UPDATED, GRUBSIGN_BACKUP); + bam_print(_("updated boot signature backup file %s\n"), + GRUBSIGN_BACKUP); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); } @@ -7054,7 +7293,7 @@ set_backup_ufs(char *osroot, char *sign) { const char *fcn = "set_backup_ufs()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, sign)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, sign)); return (set_backup_common(osroot, sign)); } @@ -7067,19 +7306,19 @@ set_backup_zfs(char *osdev, char *sign) int ret; const char *fcn = "set_backup_zfs()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osdev, sign)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osdev, sign)); pool = get_pool(osdev); INJECT_ERROR1("SET_BACKUP_GET_POOL", pool = NULL); if (pool == NULL) { - bam_error(GET_POOL_FAILED, osdev); + bam_error(_("failed to get pool name from %s\n"), osdev); return (-1); } mntpt = mount_top_dataset(pool, &mnted); INJECT_ERROR1("SET_BACKUP_MOUNT_DATASET", mntpt = NULL); if (mntpt == NULL) { - bam_error(FAIL_MNT_TOP_DATASET, pool); + bam_error(_("failed to mount top dataset for %s\n"), pool); free(pool); return (-1); } @@ -7092,9 +7331,9 @@ set_backup_zfs(char *osdev, char *sign) INJECT_ERROR1("SET_BACKUP_ZFS_FAIL", ret = 1); if (ret == 0) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (ret); @@ -7109,20 +7348,21 @@ set_backup(char *osroot, char *osdev, char *sign, char *fstype) INJECT_ERROR1("SET_BACKUP_FSTYPE", fstype = "foofs"); if (strcmp(fstype, "ufs") == 0) { - BAM_DPRINTF((D_SET_BACKUP_UFS, fcn)); + BAM_DPRINTF(("%s: setting UFS backup sign\n", fcn)); ret = set_backup_ufs(osroot, sign); } else if (strcmp(fstype, "zfs") == 0) { - BAM_DPRINTF((D_SET_BACKUP_ZFS, fcn)); + BAM_DPRINTF(("%s: setting ZFS backup sign\n", fcn)); ret = set_backup_zfs(osdev, sign); } else { - bam_error(GRUBSIGN_NOTSUP, fstype); + bam_error(_("boot signature not supported for fstype: %s\n"), + fstype); ret = -1; } if (ret == 0) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (ret); @@ -7144,22 +7384,25 @@ set_primary_common(char *mntpt, char *sign) if (stat(signfile, &sb) != -1) { if (bam_verbose) - bam_print(PRIMARY_SIGN_EXISTS, sign); + bam_print(_("primary sign %s exists\n"), sign); return (0); } else { - BAM_DPRINTF((D_PRIMARY_NOT_EXIST, fcn, signfile)); + BAM_DPRINTF(("%s: primary sign (%s) does not exist\n", + fcn, signfile)); } (void) snprintf(signdir, sizeof (signdir), "%s/%s", mntpt, GRUBSIGN_DIR); if (stat(signdir, &sb) == -1) { - BAM_DPRINTF((D_PRIMARY_DIR_NOEXIST, fcn, signdir)); + BAM_DPRINTF(("%s: primary signdir (%s) does not exist\n", + fcn, signdir)); ret = mkdirp(signdir, DIR_PERMS); error = errno; INJECT_ERROR1("SET_PRIMARY_MKDIRP", ret = -1); if (ret == -1) { - bam_error(GRUBSIGN_MKDIR_ERR, signdir, strerror(errno)); + bam_error(_("error creating boot signature " + "directory %s: %s\n"), signdir, strerror(errno)); return (-1); } } @@ -7168,7 +7411,8 @@ set_primary_common(char *mntpt, char *sign) error = errno; INJECT_ERROR1("PRIMARY_SIGN_CREAT", fd = -1); if (fd == -1) { - bam_error(GRUBSIGN_PRIMARY_CREATERR, signfile, strerror(error)); + bam_error(_("error creating primary boot signature %s: %s\n"), + signfile, strerror(error)); return (-1); } @@ -7176,15 +7420,17 @@ set_primary_common(char *mntpt, char *sign) error = errno; INJECT_ERROR1("PRIMARY_FSYNC", ret = -1); if (ret != 0) { - bam_error(GRUBSIGN_PRIMARY_SYNCERR, signfile, strerror(error)); + bam_error(_("error syncing primary boot signature %s: %s\n"), + signfile, strerror(error)); } (void) close(fd); if (bam_verbose) - bam_print(GRUBSIGN_CREATED_PRIMARY, signfile); + bam_print(_("created primary GRUB boot signature: %s\n"), + signfile); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); } @@ -7194,7 +7440,7 @@ set_primary_ufs(char *osroot, char *sign) { const char *fcn = "set_primary_ufs()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, sign)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, sign)); return (set_primary_common(osroot, sign)); } @@ -7207,12 +7453,12 @@ set_primary_zfs(char *osdev, char *sign) int ret; const char *fcn = "set_primary_zfs()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osdev, sign)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osdev, sign)); pool = get_pool(osdev); INJECT_ERROR1("SET_PRIMARY_ZFS_GET_POOL", pool = NULL); if (pool == NULL) { - bam_error(GET_POOL_FAILED, osdev); + bam_error(_("failed to get pool name from %s\n"), osdev); return (-1); } @@ -7220,7 +7466,8 @@ set_primary_zfs(char *osdev, char *sign) ret = (strstr(sign, pool) != NULL); INJECT_ERROR1("SET_PRIMARY_ZFS_POOL_SIGN_INCOMPAT", ret = 0); if (ret == 0) { - bam_error(POOL_SIGN_INCOMPAT, pool, sign); + bam_error(_("pool name %s not present in signature %s\n"), + pool, sign); free(pool); return (-1); } @@ -7228,7 +7475,7 @@ set_primary_zfs(char *osdev, char *sign) mntpt = mount_top_dataset(pool, &mnted); INJECT_ERROR1("SET_PRIMARY_ZFS_MOUNT_DATASET", mntpt = NULL); if (mntpt == NULL) { - bam_error(FAIL_MNT_TOP_DATASET, pool); + bam_error(_("failed to mount top dataset for %s\n"), pool); free(pool); return (-1); } @@ -7241,9 +7488,9 @@ set_primary_zfs(char *osdev, char *sign) INJECT_ERROR1("SET_PRIMARY_ZFS_FAIL", ret = 1); if (ret == 0) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (ret); @@ -7257,20 +7504,21 @@ set_primary(char *osroot, char *osdev, char *sign, char *fstype) INJECT_ERROR1("SET_PRIMARY_FSTYPE", fstype = "foofs"); if (strcmp(fstype, "ufs") == 0) { - BAM_DPRINTF((D_SET_PRIMARY_UFS, fcn)); + BAM_DPRINTF(("%s: setting UFS primary sign\n", fcn)); ret = set_primary_ufs(osroot, sign); } else if (strcmp(fstype, "zfs") == 0) { - BAM_DPRINTF((D_SET_PRIMARY_ZFS, fcn)); + BAM_DPRINTF(("%s: setting ZFS primary sign\n", fcn)); ret = set_primary_zfs(osdev, sign); } else { - bam_error(GRUBSIGN_NOTSUP, fstype); + bam_error(_("boot signature not supported for fstype: %s\n"), + fstype); ret = -1; } if (ret == 0) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (ret); @@ -7289,7 +7537,7 @@ ufs_add_to_sign_list(char *sign) INJECT_ERROR1("ADD_TO_SIGN_LIST_NOT_UFS", sign = "pool_rpool5"); if (strncmp(sign, GRUBSIGN_UFS_PREFIX, strlen(GRUBSIGN_UFS_PREFIX)) != 0) { - bam_error(INVALID_UFS_SIGN, sign); + bam_error(_("invalid UFS boot signature %s\n"), sign); (void) unlink(UFS_SIGNATURE_LIST); return (-1); } @@ -7303,8 +7551,8 @@ ufs_add_to_sign_list(char *sign) error = errno; INJECT_ERROR1("ADD_TO_SIGN_LIST_RENAME", ret = -1); if (ret == -1) { - bam_error(RENAME_FAIL, UFS_SIGNATURE_LIST".tmp", - strerror(error)); + bam_error(_("rename to file failed: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST); return (0); } @@ -7313,7 +7561,8 @@ ufs_add_to_sign_list(char *sign) error = errno; INJECT_ERROR1("ADD_TO_SIGN_LIST_FOPEN", tfp = NULL); if (tfp == NULL) { - bam_error(OPEN_FAIL, UFS_SIGNATURE_LIST".tmp", strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (0); } @@ -7324,7 +7573,8 @@ ufs_add_to_sign_list(char *sign) error = errno; INJECT_ERROR1("ADD_TO_SIGN_LIST_FPUTS", ret = 0); if (ret != strlen(signline)) { - bam_error(SIGN_LIST_FPUTS_ERR, sign, strerror(error)); + bam_error(_("failed to write signature %s to signature " + "list: %s\n"), sign, strerror(error)); (void) fclose(tfp); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (0); @@ -7334,8 +7584,8 @@ ufs_add_to_sign_list(char *sign) error = errno; INJECT_ERROR1("ADD_TO_SIGN_LIST_FCLOSE", ret = EOF); if (ret == EOF) { - bam_error(CLOSE_FAIL, UFS_SIGNATURE_LIST".tmp", - strerror(error)); + bam_error(_("failed to close file: %s: %s\n"), + UFS_SIGNATURE_LIST".tmp", strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (0); } @@ -7348,7 +7598,7 @@ ufs_add_to_sign_list(char *sign) ret = exec_cmd(cmd, NULL); INJECT_ERROR1("ADD_TO_SIGN_LIST_SORT", ret = 1); if (ret != 0) { - bam_error(GRUBSIGN_SORT_FAILED); + bam_error(_("error sorting GRUB UFS boot signatures\n")); (void) unlink(UFS_SIGNATURE_LIST".sorted"); (void) unlink(UFS_SIGNATURE_LIST".tmp"); return (0); @@ -7360,12 +7610,13 @@ ufs_add_to_sign_list(char *sign) error = errno; INJECT_ERROR1("ADD_TO_SIGN_LIST_RENAME2", ret = -1); if (ret == -1) { - bam_error(RENAME_FAIL, UFS_SIGNATURE_LIST, strerror(error)); + bam_error(_("rename to file failed: %s: %s\n"), + UFS_SIGNATURE_LIST, strerror(error)); (void) unlink(UFS_SIGNATURE_LIST".sorted"); return (0); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); } @@ -7376,13 +7627,15 @@ set_signature(char *osroot, char *osdev, char *sign, char *fstype) int ret; const char *fcn = "set_signature()"; - BAM_DPRINTF((D_FUNC_ENTRY4, fcn, osroot, osdev, sign, fstype)); + BAM_DPRINTF(("%s: entered. args: %s %s %s %s\n", fcn, + osroot, osdev, sign, fstype)); ret = set_backup(osroot, osdev, sign, fstype); INJECT_ERROR1("SET_SIGNATURE_BACKUP", ret = -1); if (ret == -1) { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); - bam_error(SET_BACKUP_FAILED, sign, osroot, osdev); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); + bam_error(_("failed to set backup sign (%s) for %s: %s\n"), + sign, osroot, osdev); return (-1); } @@ -7390,10 +7643,11 @@ set_signature(char *osroot, char *osdev, char *sign, char *fstype) INJECT_ERROR1("SET_SIGNATURE_PRIMARY", ret = -1); if (ret == 0) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); - bam_error(SET_PRIMARY_FAILED, sign, osroot, osdev); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); + bam_error(_("failed to set primary sign (%s) for %s: %s\n"), + sign, osroot, osdev); } return (ret); @@ -7410,22 +7664,24 @@ get_grubsign(char *osroot, char *osdev) int ret; const char *fcn = "get_grubsign()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, osdev)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, osdev)); fstype = get_fstype(osroot); INJECT_ERROR1("GET_GRUBSIGN_FSTYPE", fstype = NULL); if (fstype == NULL) { - bam_error(GET_FSTYPE_FAILED, osroot); + bam_error(_("failed to get fstype for %s\n"), osroot); return (NULL); } sign = find_existing_sign(osroot, osdev, fstype); INJECT_ERROR1("FIND_EXISTING_SIGN", sign = NULL); if (sign == NULL) { - BAM_DPRINTF((D_GET_GRUBSIGN_NO_EXISTING, fcn, osroot, osdev)); + BAM_DPRINTF(("%s: no existing grubsign for %s: %s\n", + fcn, osroot, osdev)); sign = create_new_sign(osdev, fstype); INJECT_ERROR1("CREATE_NEW_SIGN", sign = NULL); if (sign == NULL) { - bam_error(GRUBSIGN_CREATE_FAIL, osdev); + bam_error(_("failed to create GRUB boot signature for " + "device: %s\n"), osdev); free(fstype); return (NULL); } @@ -7434,7 +7690,8 @@ get_grubsign(char *osroot, char *osdev) ret = set_signature(osroot, osdev, sign, fstype); INJECT_ERROR1("SET_SIGNATURE_FAIL", ret = -1); if (ret == -1) { - bam_error(GRUBSIGN_WRITE_FAIL, osdev); + bam_error(_("failed to write GRUB boot signature for " + "device: %s\n"), osdev); free(sign); free(fstype); (void) unlink(UFS_SIGNATURE_LIST); @@ -7444,12 +7701,14 @@ get_grubsign(char *osroot, char *osdev) free(fstype); if (bam_verbose) - bam_print(GRUBSIGN_FOUND_OR_CREATED, sign, osdev); + bam_print(_("found or created GRUB signature %s for %s\n"), + sign, osdev); fdiskpart = get_partition(osdev); INJECT_ERROR1("GET_GRUBSIGN_FDISK", fdiskpart = PARTNO_NOTFOUND); if (fdiskpart == PARTNO_NOTFOUND) { - bam_error(FDISKPART_FAIL, osdev); + bam_error(_("failed to determine fdisk partition: %s\n"), + osdev); free(sign); return (NULL); } @@ -7471,7 +7730,7 @@ get_grubsign(char *osroot, char *osdev) free(sign); - BAM_DPRINTF((D_GET_GRUBSIGN_SUCCESS, fcn, grubsign)); + BAM_DPRINTF(("%s: successfully created grubsign %s\n", fcn, grubsign)); return (grubsign); } @@ -7490,7 +7749,8 @@ get_title(char *rootdir) fp = fopen(release, "r"); if (fp == NULL) { - bam_error(OPEN_FAIL, release, strerror(errno)); + bam_error(_("failed to open file: %s: %s\n"), release, + strerror(errno)); cp = NULL; goto out; } @@ -7507,7 +7767,7 @@ get_title(char *rootdir) out: cp = cp ? cp : "Oracle Solaris"; - BAM_DPRINTF((D_GET_TITLE, fcn, cp)); + BAM_DPRINTF(("%s: got title: %s\n", fcn, cp)); return (cp); } @@ -7524,7 +7784,7 @@ get_special(char *mountp) INJECT_ERROR1("GET_SPECIAL_MNTPT", mountp = NULL); if (mountp == NULL) { - bam_error(GET_SPECIAL_NULL_MNTPT); + bam_error(_("cannot get special file: NULL mount-point\n")); return (NULL); } @@ -7532,7 +7792,8 @@ get_special(char *mountp) error = errno; INJECT_ERROR1("GET_SPECIAL_MNTTAB_OPEN", mntfp = NULL); if (mntfp == NULL) { - bam_error(OPEN_FAIL, MNTTAB, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), MNTTAB, + strerror(error)); return (NULL); } @@ -7545,12 +7806,13 @@ get_special(char *mountp) INJECT_ERROR1("GET_SPECIAL_MNTTAB_SEARCH", ret = 1); if (ret != 0) { (void) fclose(mntfp); - BAM_DPRINTF((D_GET_SPECIAL_NOT_IN_MNTTAB, fcn, mountp)); + BAM_DPRINTF(("%s: Cannot get special file: mount-point %s " + "not in mnttab\n", fcn, mountp)); return (NULL); } (void) fclose(mntfp); - BAM_DPRINTF((D_GET_SPECIAL, fcn, mp.mnt_special)); + BAM_DPRINTF(("%s: returning special: %s\n", fcn, mp.mnt_special)); return (s_strdup(mp.mnt_special)); } @@ -7564,14 +7826,14 @@ free_physarray(char **physarray, int n) assert(physarray); assert(n); - BAM_DPRINTF((D_FUNC_ENTRY_N1, fcn, n)); + BAM_DPRINTF(("%s: entering args: %d\n", fcn, n)); for (i = 0; i < n; i++) { free(physarray[i]); } free(physarray); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } static int @@ -7591,11 +7853,12 @@ zfs_get_physical(char *special, char ***physarray, int *n) assert(special); - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, special)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, special)); INJECT_ERROR1("INVALID_ZFS_SPECIAL", special = "/foo"); if (special[0] == '/') { - bam_error(INVALID_ZFS_SPECIAL, special); + bam_error(_("invalid device for ZFS filesystem: %s\n"), + special); return (-1); } @@ -7604,7 +7867,8 @@ zfs_get_physical(char *special, char ***physarray, int *n) pool = strtok(sdup, "/"); INJECT_ERROR1("ZFS_GET_PHYS_POOL", pool = NULL); if (pool == NULL) { - bam_error(CANT_FIND_POOL_FROM_SPECIAL, special); + bam_error(_("cannot derive ZFS pool from special: %s\n"), + special); return (-1); } @@ -7613,19 +7877,20 @@ zfs_get_physical(char *special, char ***physarray, int *n) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("ZFS_GET_PHYS_STATUS", ret = 1); if (ret != 0) { - bam_error(ZFS_GET_POOL_STATUS, pool); + bam_error(_("cannot get zpool status for pool: %s\n"), pool); return (-1); } INJECT_ERROR1("ZFS_GET_PHYS_STATUS_OUT", flist.head = NULL); if (flist.head == NULL) { - bam_error(BAD_ZPOOL_STATUS, pool); + bam_error(_("bad zpool status for pool=%s\n"), pool); filelist_free(&flist); return (-1); } for (lp = flist.head; lp; lp = lp->next) { - BAM_DPRINTF((D_STRTOK_ZPOOL_STATUS, fcn, lp->line)); + BAM_DPRINTF(("%s: strtok() zpool status line=%s\n", + fcn, lp->line)); comp1 = strtok(lp->line, " \t"); if (comp1 == NULL) { free(lp->line); @@ -7641,13 +7906,14 @@ zfs_get_physical(char *special, char ***physarray, int *n) if (lp->line == NULL) continue; if (strcmp(lp->line, pool) == 0) { - BAM_DPRINTF((D_FOUND_POOL_IN_ZPOOL_STATUS, fcn, pool)); + BAM_DPRINTF(("%s: found pool name: %s in zpool " + "status\n", fcn, pool)); break; } } if (lp == NULL) { - bam_error(NO_POOL_IN_ZPOOL_STATUS, pool); + bam_error(_("no pool name %s in zpool status\n"), pool); filelist_free(&flist); return (-1); } @@ -7661,11 +7927,13 @@ zfs_get_physical(char *special, char ***physarray, int *n) if (lp->line[0] == '\0' || strcmp(lp->line, "errors:") == 0) break; i++; - BAM_DPRINTF((D_COUNTING_ZFS_PHYS, fcn, i)); + BAM_DPRINTF(("%s: counting phys slices in zpool status: %d\n", + fcn, i)); } if (i == 0) { - bam_error(NO_PHYS_IN_ZPOOL_STATUS, pool); + bam_error(_("no physical device in zpool status for pool=%s\n"), + pool); filelist_free(&flist); return (-1); } @@ -7687,7 +7955,8 @@ zfs_get_physical(char *special, char ***physarray, int *n) } else { (void) strlcpy(dsk, lp->line, sizeof (dsk)); } - BAM_DPRINTF((D_ADDING_ZFS_PHYS, fcn, dsk, pool)); + BAM_DPRINTF(("%s: adding phys slice=%s from pool %s status\n", + fcn, dsk, pool)); (*physarray)[i++] = s_strdup(dsk); } @@ -7695,7 +7964,7 @@ zfs_get_physical(char *special, char ***physarray, int *n) filelist_free(&flist); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); } @@ -7715,23 +7984,23 @@ is_svc_online(char *svc) char *state; const char *fcn = "is_svc_online()"; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, svc)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, svc)); state = smf_get_state(svc); INJECT_ERROR2("GET_SVC_STATE", free(state), state = NULL); if (state == NULL) { - bam_error(GET_SVC_STATE_ERR, svc); + bam_error(_("failed to determine state of service: %s\n"), svc); return (-1); } - BAM_DPRINTF((D_GOT_SVC_STATUS, fcn, svc)); + BAM_DPRINTF(("%s: got status for service: %s\n", fcn, svc)); if (strcmp(state, SCF_STATE_STRING_ONLINE) == 0) { - BAM_DPRINTF((D_SVC_ONLINE, fcn, svc)); + BAM_DPRINTF(("%s: service is online: %s\n", fcn, svc)); free(state); return (1); } - BAM_DPRINTF((D_SVC_NOT_ONLINE, fcn, state, svc)); + BAM_DPRINTF(("%s: service is *NOT* online(%s): %s\n", fcn, state, svc)); free(state); @@ -7747,10 +8016,11 @@ enable_svc(char *svc) ret = is_svc_online(svc); if (ret == -1) { - bam_error(SVC_IS_ONLINE_FAILED, svc); + bam_error(_("failed to determine if service is online: %s\n"), + svc); return (-1); } else if (ret == 1) { - BAM_DPRINTF((D_SVC_ALREADY_ONLINE, fcn, svc)); + BAM_DPRINTF(("%s: service is already online: %s\n", fcn, svc)); return (0); } @@ -7758,11 +8028,11 @@ enable_svc(char *svc) ret = smf_enable_instance(svc, 0); INJECT_ERROR1("ENABLE_SVC_FAILED", ret = -1); if (ret != 0) { - bam_error(ENABLE_SVC_FAILED, svc); + bam_error(_("failed to online service: %s\n"), svc); return (-1); } - BAM_DPRINTF((D_SVC_ONLINE_INITIATED, fcn, svc)); + BAM_DPRINTF(("%s: initiated online of service: %s\n", fcn, svc)); sleeptime = 0; do { @@ -7771,16 +8041,18 @@ enable_svc(char *svc) INJECT_ERROR1("SVC_ONLINE_FAILURE", ret = -1); INJECT_ERROR1("SVC_ONLINE_NOTYET", ret = 0); if (ret == -1) { - bam_error(ERR_SVC_GET_ONLINE, svc); + bam_error(_("failed to get online status for " + "service: %s\n"), svc); return (-1); } else if (ret == 1) { - BAM_DPRINTF((D_SVC_NOW_ONLINE, fcn, svc)); + BAM_DPRINTF(("%s: service is NOW online: %s\n", + fcn, svc)); return (1); } (void) sleep(1); } while (++sleeptime < 60); - bam_error(TIMEOUT_ENABLE_SVC, svc); + bam_error(_("timed out waiting for service to online: %s\n"), svc); return (-1); } @@ -7805,10 +8077,11 @@ ufs_get_physical(char *special, char ***physarray, int *n) assert(special); - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, special)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, special)); if (strncmp(special, "/dev/md/", strlen("/dev/md/")) != 0) { - bam_error(UFS_GET_PHYS_NOT_SVM, special); + bam_error(_("not a SVM metadevice: %s. Cannot derive physical " + "device\n"), special); return (-1); } @@ -7818,15 +8091,18 @@ ufs_get_physical(char *special, char ***physarray, int *n) strlen("/dev/md/rdsk/")) == 0) { shortname = special + strlen("/dev/md/rdsk"); } else { - bam_error(UFS_GET_PHYS_INVALID_SVM, special); + bam_error(_("invalid SVM metadevice name: %s. Cannot derive " + "physical device\n"), special); return (-1); } - BAM_DPRINTF((D_UFS_SVM_SHORT, fcn, special, shortname)); + BAM_DPRINTF(("%s: short SVM name for special=%s is %s\n", + fcn, special, shortname)); svc = "network/rpc/meta:default"; if (enable_svc(svc) == -1) { - bam_error(UFS_SVM_METASTAT_SVC_ERR, svc); + bam_error(_("failed to start service %s for metastat " + "command\n"), svc); } (void) snprintf(cmd, sizeof (cmd), "/sbin/metastat -p %s", shortname); @@ -7834,13 +8110,15 @@ ufs_get_physical(char *special, char ***physarray, int *n) ret = exec_cmd(cmd, &flist); INJECT_ERROR1("UFS_SVM_METASTAT", ret = 1); if (ret != 0) { - bam_error(UFS_SVM_METASTAT_ERR, shortname); + bam_error(_("metastat command failed on SVM metadevice: %s\n"), + shortname); return (-1); } INJECT_ERROR1("UFS_SVM_METASTAT_OUT", flist.head = NULL); if (flist.head == NULL) { - bam_error(BAD_UFS_SVM_METASTAT, shortname); + bam_error(_("bad output from metastat command on SVM " + "metadevice: %s\n"), shortname); filelist_free(&flist); return (-1); } @@ -7852,7 +8130,8 @@ ufs_get_physical(char *special, char ***physarray, int *n) meta = strtok(flist.head->line, " \t"); type = strtok(NULL, " \t"); if (meta == NULL || type == NULL) { - bam_error(ERROR_PARSE_UFS_SVM_METASTAT, shortname); + bam_error(_("error parsing metastat output for SVM " + "metadevice: %s\n"), shortname); filelist_free(&flist); return (-1); } @@ -7860,11 +8139,13 @@ ufs_get_physical(char *special, char ***physarray, int *n) comp1 = strtok(NULL, " \t"); comp2 = strtok(NULL, " \t"); if (comp1 == NULL || comp2 != NULL) { - bam_error(INVALID_UFS_SVM_METASTAT, shortname); + bam_error(_("invalid fields in metastat output for " + "SVM metadevice: %s\n"), shortname); filelist_free(&flist); return (-1); } - BAM_DPRINTF((D_UFS_SVM_ONE_COMP, fcn, comp1, shortname)); + BAM_DPRINTF(("%s: single component %s for metadevice %s\n", + fcn, comp1, shortname)); *physarray = s_calloc(1, sizeof (char *)); (*physarray)[0] = s_strdup(comp1); *n = 1; @@ -7879,7 +8160,8 @@ ufs_get_physical(char *special, char ***physarray, int *n) for (i = 0, lp = flist.head->next; lp; lp = lp->next) { if (strstr(lp->line, "/dev/dsk/") == NULL && strstr(lp->line, "/dev/rdsk/") == NULL) { - bam_error(CANNOT_PARSE_UFS_SVM_METASTAT, shortname); + bam_error(_("cannot parse output of metastat command " + "for metadevice: %s\n"), shortname); filelist_free(&flist); return (-1); } @@ -7898,7 +8180,8 @@ ufs_get_physical(char *special, char ***physarray, int *n) if (comp3 == NULL || comp4 == NULL || (strncmp(comp4, "/dev/dsk/", strlen("/dev/dsk/")) != 0 && strncmp(comp4, "/dev/rdsk/", strlen("/dev/rdsk/")) != 0)) { - bam_error(CANNOT_PARSE_UFS_SVM_SUBMIRROR, shortname); + bam_error(_("cannot parse submirror line in metastat " + "output for metadevice: %s\n"), shortname); filelist_free(&flist); free_physarray(*physarray, *n); return (-1); @@ -7911,7 +8194,7 @@ ufs_get_physical(char *special, char ***physarray, int *n) filelist_free(&flist); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (0); } @@ -7929,21 +8212,23 @@ get_physical(char *menu_root, char ***physarray, int *n) *physarray = NULL; *n = 0; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, menu_root)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, menu_root)); /* First get the device special file from /etc/mnttab */ special = get_special(menu_root); INJECT_ERROR1("GET_PHYSICAL_SPECIAL", special = NULL); if (special == NULL) { - bam_error(GET_SPECIAL_NULL, menu_root); + bam_error(_("cannot get special file for mount-point: %s\n"), + menu_root); return (-1); } /* If already a physical device nothing to do */ if (strncmp(special, "/dev/dsk/", strlen("/dev/dsk/")) == 0 || strncmp(special, "/dev/rdsk/", strlen("/dev/rdsk/")) == 0) { - BAM_DPRINTF((D_GET_PHYSICAL_ALREADY, fcn, menu_root, special)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: got physical device already directly for " + "menu_root=%s special=%s\n", fcn, menu_root, special)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); *physarray = s_calloc(1, sizeof (char *)); (*physarray)[0] = special; *n = 1; @@ -7955,7 +8240,8 @@ get_physical(char *menu_root, char ***physarray, int *n) } else if (is_ufs(menu_root)) { ret = ufs_get_physical(special, physarray, n); } else { - bam_error(GET_PHYSICAL_NOTSUP_FSTYPE, menu_root, special); + bam_error(_("cannot derive physical device for %s (%s), " + "unsupported filesystem\n"), menu_root, special); ret = -1; } @@ -7963,12 +8249,13 @@ get_physical(char *menu_root, char ***physarray, int *n) INJECT_ERROR1("GET_PHYSICAL_RET", ret = -1); if (ret == -1) { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } else { int i; assert (*n > 0); for (i = 0; i < *n; i++) { - BAM_DPRINTF((D_GET_PHYSICAL_RET, fcn, (*physarray)[i])); + BAM_DPRINTF(("%s: returning physical=%s\n", + fcn, (*physarray)[i])); } } @@ -7986,7 +8273,7 @@ is_bootdisk(char *osroot, char *physical) assert(osroot); assert(physical); - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, physical)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, physical)); bootp = strstr(physical, "p0:boot"); if (bootp) @@ -8004,13 +8291,14 @@ is_bootdisk(char *osroot, char *physical) INJECT_ERROR1("IS_BOOTDISK_GRUBROOT", grubroot = NULL); if (grubroot == NULL) { if (bam_verbose) - bam_error(NO_GRUBROOT_FOR_DISK, physical); + bam_error(_("cannot determine BIOS disk ID 'hd?' for " + "disk: %s\n"), physical); return (0); } ret = grubroot[3] == '0'; free(grubroot); - BAM_DPRINTF((D_RETURN_RET, fcn, ret)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, ret)); return (ret); } @@ -8029,12 +8317,13 @@ menu_on_bootdisk(char *osroot, char *menu_root) int on_bootdisk; const char *fcn = "menu_on_bootdisk()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, menu_root)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, menu_root)); ret = get_physical(menu_root, &physarray, &n); INJECT_ERROR1("MENU_ON_BOOTDISK_PHYSICAL", ret = -1); if (ret != 0) { - bam_error(GET_PHYSICAL_MENU_NULL, menu_root); + bam_error(_("cannot get physical device special file for menu " + "root: %s\n"), menu_root); return (0); } @@ -8048,10 +8337,12 @@ menu_on_bootdisk(char *osroot, char *menu_root) strncmp(physarray[i], "/dev/rdsk/", strlen("/dev/rdsk/")) == 0); - BAM_DPRINTF((D_CHECK_ON_BOOTDISK, fcn, physarray[i])); + BAM_DPRINTF(("%s: checking if phys-device=%s is on bootdisk\n", + fcn, physarray[i])); if (is_bootdisk(osroot, physarray[i])) { on_bootdisk = 1; - BAM_DPRINTF((D_IS_ON_BOOTDISK, fcn, physarray[i])); + BAM_DPRINTF(("%s: phys-device=%s *IS* on bootdisk\n", + fcn, physarray[i])); } } @@ -8060,9 +8351,9 @@ menu_on_bootdisk(char *osroot, char *menu_root) INJECT_ERROR1("ON_BOOTDISK_YES", on_bootdisk = 1); INJECT_ERROR1("ON_BOOTDISK_NO", on_bootdisk = 0); if (on_bootdisk) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (on_bootdisk); @@ -8080,22 +8371,22 @@ bam_add_line(menu_t *mp, entry_t *entry, line_t *prev, line_t *lp) lp->next = prev->next; if (prev->next) { - BAM_DPRINTF((D_ADD_LINE_PREV_NEXT, fcn)); + BAM_DPRINTF(("%s: previous next exists\n", fcn)); prev->next->prev = lp; } else { - BAM_DPRINTF((D_ADD_LINE_NOT_PREV_NEXT, fcn)); + BAM_DPRINTF(("%s: previous next does not exist\n", fcn)); } prev->next = lp; lp->prev = prev; if (entry->end == prev) { - BAM_DPRINTF((D_ADD_LINE_LAST_LINE_IN_ENTRY, fcn)); + BAM_DPRINTF(("%s: last line in entry\n", fcn)); entry->end = lp; } if (mp->end == prev) { assert(lp->next == NULL); mp->end = lp; - BAM_DPRINTF((D_ADD_LINE_LAST_LINE_IN_MENU, fcn)); + BAM_DPRINTF(("%s: last line in menu\n", fcn)); } } @@ -8142,10 +8433,12 @@ find_boot_entry( if (title) { if (lp->flags == BAM_TITLE && lp->arg && strcmp(lp->arg, title) == 0) { - BAM_DPRINTF((D_MATCHED_TITLE, fcn, title)); + BAM_DPRINTF(("%s: matched title: %s\n", + fcn, title)); break; } - BAM_DPRINTF((D_NOMATCH_TITLE, fcn, title, lp->arg)); + BAM_DPRINTF(("%s: no match title: %s, %s\n", + fcn, title, lp->arg)); continue; /* check title only */ } @@ -8157,33 +8450,34 @@ find_boot_entry( INJECT_ERROR1("FIND_BOOT_ENTRY_NULL_FINDROOT", findroot = NULL); if (findroot == NULL) { - BAM_DPRINTF((D_NOMATCH_FINDROOT_NULL, - fcn, lp->arg)); + BAM_DPRINTF(("%s: no match line has findroot, " + "we don't: %s\n", fcn, lp->arg)); continue; } /* findroot command found, try match */ if (strcmp(lp->arg, findroot) != 0) { - BAM_DPRINTF((D_NOMATCH_FINDROOT, + BAM_DPRINTF(("%s: no match findroot: %s, %s\n", fcn, findroot, lp->arg)); continue; } - BAM_DPRINTF((D_MATCHED_FINDROOT, fcn, findroot)); + BAM_DPRINTF(("%s: matched findroot: %s\n", + fcn, findroot)); lp = lp->next; /* advance to kernel line */ } else if (lp->cmd != NULL && strcmp(lp->cmd, menu_cmds[ROOT_CMD]) == 0) { INJECT_ERROR1("FIND_BOOT_ENTRY_NULL_ROOT", root = NULL); if (root == NULL) { - BAM_DPRINTF((D_NOMATCH_ROOT_NULL, - fcn, lp->arg)); + BAM_DPRINTF(("%s: no match, line has root, we " + "don't: %s\n", fcn, lp->arg)); continue; } /* root cmd found, try match */ if (strcmp(lp->arg, root) != 0) { - BAM_DPRINTF((D_NOMATCH_ROOT, + BAM_DPRINTF(("%s: no match root: %s, %s\n", fcn, root, lp->arg)); continue; } - BAM_DPRINTF((D_MATCHED_ROOT, fcn, root)); + BAM_DPRINTF(("%s: matched root: %s\n", fcn, root)); lp = lp->next; /* advance to kernel line */ } else { INJECT_ERROR1("FIND_BOOT_ENTRY_ROOT_OPT_NO", @@ -8192,10 +8486,10 @@ find_boot_entry( root_opt = 1); /* no root command, see if root is optional */ if (root_opt == 0) { - BAM_DPRINTF((D_NO_ROOT_OPT, fcn)); + BAM_DPRINTF(("%s: root NOT optional\n", fcn)); continue; } - BAM_DPRINTF((D_ROOT_OPT, fcn)); + BAM_DPRINTF(("%s: root IS optional\n", fcn)); } if (lp == NULL || lp->next == NULL) { @@ -8212,7 +8506,8 @@ find_boot_entry( ent->flags |= BAM_ENTRY_UPGFSKERNEL; } - BAM_DPRINTF((D_KERNEL_MATCH, fcn, kernel, lp->arg)); + BAM_DPRINTF(("%s: kernel match: %s, %s\n", fcn, + kernel, lp->arg)); /* * Check for matching module entry (failsafe or normal). @@ -8225,7 +8520,8 @@ find_boot_entry( (((lp = lp->next) != NULL) && check_cmd(lp->cmd, MODULE_CMD, lp->arg, module))) { /* match found */ - BAM_DPRINTF((D_MODULE_MATCH, fcn, module, lp->arg)); + BAM_DPRINTF(("%s: module match: %s, %s\n", fcn, + module, lp->arg)); break; } @@ -8243,9 +8539,9 @@ find_boot_entry( } if (ent) { - BAM_DPRINTF((D_RETURN_RET, fcn, i)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, i)); } else { - BAM_DPRINTF((D_RETURN_RET, fcn, BAM_ERROR)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, BAM_ERROR)); } return (ent); } @@ -8274,15 +8570,18 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, ent = find_boot_entry(mp, NULL, "multiboot", NULL, root, MULTIBOOT_ARCHIVE, root_opt, &i); if (ent != NULL) { - BAM_DPRINTF((D_UPGRADE_FROM_MULTIBOOT, fcn, root)); + BAM_DPRINTF(("%s: upgrading entry from dboot to " + "multiboot: root = %s\n", fcn, root)); change_kernel = 1; } } else if (ent) { - BAM_DPRINTF((D_FOUND_FINDROOT, fcn, findroot)); + BAM_DPRINTF(("%s: found entry with matching findroot: %s\n", + fcn, findroot)); } if (ent == NULL) { - BAM_DPRINTF((D_ENTRY_NOT_FOUND_CREATING, fcn, findroot)); + BAM_DPRINTF(("%s: boot entry not found in menu. Creating " + "new entry, findroot = %s\n", fcn, findroot)); return (add_boot_entry(mp, title, findroot, kernel, mod_kernel, module, NULL)); } @@ -8296,7 +8595,7 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, free(lp->line); lp->arg = s_strdup(title); lp->line = s_strdup(linebuf); - BAM_DPRINTF((D_CHANGING_TITLE, fcn, title)); + BAM_DPRINTF(("%s: changing title to: %s\n", fcn, title)); tlp = lp; /* title line */ lp = lp->next; /* root line */ @@ -8321,7 +8620,7 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s", menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], findroot); lp->line = s_strdup(linebuf); - BAM_DPRINTF((D_ADDING_FINDROOT_LINE, fcn, findroot)); + BAM_DPRINTF(("%s: adding findroot line: %s\n", fcn, findroot)); /* kernel line */ lp = lp->next; @@ -8348,7 +8647,8 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, lp->arg = s_strdup(strstr(linebuf, "/")); lp->line = s_strdup(linebuf); ent->flags &= ~BAM_ENTRY_UPGFSKERNEL; - BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, lp->prev->cmd)); + BAM_DPRINTF(("%s: adding new kernel$ line: %s\n", + fcn, lp->prev->cmd)); } if (change_kernel) { @@ -8367,7 +8667,8 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, lp->arg = s_strdup(kernel); lp->line = s_strdup(linebuf); lp = lp->next; - BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, kernel)); + BAM_DPRINTF(("%s: adding new kernel$ line: %s\n", + fcn, kernel)); } if (lp->cmd != NULL && strcmp(lp->cmd, menu_cmds[MODULE_CMD]) == 0) { @@ -8381,7 +8682,8 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, lp->arg = s_strdup(module); lp->line = s_strdup(linebuf); lp = lp->next; - BAM_DPRINTF((D_ADDING_MODULE_DOLLAR, fcn, module)); + BAM_DPRINTF(("%s: adding new module$ line: %s\n", + fcn, module)); } } @@ -8402,11 +8704,12 @@ update_boot_entry(menu_t *mp, char *title, char *findroot, char *root, lp->line = s_strdup(linebuf); lp = lp->next; ent->flags &= ~BAM_ENTRY_UPGFSMODULE; - BAM_DPRINTF((D_ADDING_MODULE_DOLLAR, fcn, module)); + BAM_DPRINTF(("%s: adding new module$ line: %s\n", + fcn, module)); } } - BAM_DPRINTF((D_RETURN_RET, fcn, i)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, i)); return (i); } @@ -8421,7 +8724,7 @@ root_optional(char *osroot, char *menu_root) int ret2; const char *fcn = "root_optional()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, menu_root)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, menu_root)); /* * For all filesystems except ZFS, a straight compare of osroot @@ -8433,7 +8736,8 @@ root_optional(char *osroot, char *menu_root) ret2 = is_zfs(menu_root); INJECT_ERROR1("ROOT_OPT_NOT_ZFS", ret1 = 0); if (!ret1 || !ret2) { - BAM_DPRINTF((D_ROOT_OPT_NOT_ZFS, fcn, osroot, menu_root)); + BAM_DPRINTF(("%s: one or more non-ZFS filesystems (%s, %s)\n", + fcn, osroot, menu_root)); root_opt = (strcmp(osroot, menu_root) == 0); goto out; } @@ -8441,24 +8745,28 @@ root_optional(char *osroot, char *menu_root) ospecial = get_special(osroot); INJECT_ERROR1("ROOT_OPTIONAL_OSPECIAL", ospecial = NULL); if (ospecial == NULL) { - bam_error(GET_OSROOT_SPECIAL_ERR, osroot); + bam_error(_("failed to get special file for osroot: %s\n"), + osroot); return (0); } - BAM_DPRINTF((D_ROOT_OPTIONAL_OSPECIAL, fcn, ospecial, osroot)); + BAM_DPRINTF(("%s: ospecial=%s for osroot=%s\n", fcn, ospecial, osroot)); mspecial = get_special(menu_root); INJECT_ERROR1("ROOT_OPTIONAL_MSPECIAL", mspecial = NULL); if (mspecial == NULL) { - bam_error(GET_MENU_ROOT_SPECIAL_ERR, menu_root); + bam_error(_("failed to get special file for menu_root: %s\n"), + menu_root); free(ospecial); return (0); } - BAM_DPRINTF((D_ROOT_OPTIONAL_MSPECIAL, fcn, mspecial, menu_root)); + BAM_DPRINTF(("%s: mspecial=%s for menu_root=%s\n", + fcn, mspecial, menu_root)); slash = strchr(ospecial, '/'); if (slash) *slash = '\0'; - BAM_DPRINTF((D_ROOT_OPTIONAL_FIXED_OSPECIAL, fcn, ospecial, osroot)); + BAM_DPRINTF(("%s: FIXED ospecial=%s for osroot=%s\n", + fcn, ospecial, osroot)); root_opt = (strcmp(ospecial, mspecial) == 0); @@ -8469,9 +8777,9 @@ out: INJECT_ERROR1("ROOT_OPTIONAL_NO", root_opt = 0); INJECT_ERROR1("ROOT_OPTIONAL_YES", root_opt = 1); if (root_opt) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (root_opt); @@ -8498,7 +8806,8 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) assert(osdev); assert(bam_root); - BAM_DPRINTF((D_FUNC_ENTRY3, fcn, menu_root, osdev, bam_root)); + BAM_DPRINTF(("%s: entered. args: %s %s %s\n", fcn, menu_root, osdev, + bam_root)); (void) strlcpy(osroot, bam_root, sizeof (osroot)); @@ -8508,7 +8817,8 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) grubsign = get_grubsign(osroot, osdev); INJECT_ERROR1("GET_GRUBSIGN_FAIL", grubsign = NULL); if (grubsign == NULL) { - bam_error(GET_GRUBSIGN_ERROR, osroot, osdev); + bam_error(_("failed to get grubsign for root: %s, device %s\n"), + osroot, osdev); return (BAM_ERROR); } @@ -8520,11 +8830,11 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) grubroot = get_grubroot(osroot, osdev, menu_root); INJECT_ERROR1("GET_GRUBROOT_FAIL", grubroot = NULL); if (grubroot) { - BAM_DPRINTF((D_GET_GRUBROOT_SUCCESS, - fcn, osroot, osdev, menu_root)); + BAM_DPRINTF(("%s: get_grubroot success. osroot=%s, osdev=%s, " + "menu_root=%s\n", fcn, osroot, osdev, menu_root)); } else { - BAM_DPRINTF((D_GET_GRUBROOT_FAILURE, - fcn, osroot, osdev, menu_root)); + BAM_DPRINTF(("%s: get_grubroot failed. osroot=%s, osdev=%s, " + "menu_root=%s\n", fcn, osroot, osdev, menu_root)); } /* add the entry for normal Solaris */ @@ -8535,22 +8845,24 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) (bam_zfs ? DIRECT_BOOT_KERNEL_ZFS : DIRECT_BOOT_KERNEL), NULL, DIRECT_BOOT_ARCHIVE, root_optional(osroot, menu_root)); - BAM_DPRINTF((D_UPDATED_BOOT_ENTRY, fcn, bam_zfs, grubsign)); + BAM_DPRINTF(("%s: updated boot entry bam_zfs=%d, " + "grubsign = %s\n", fcn, bam_zfs, grubsign)); if ((entry != BAM_ERROR) && (bam_is_hv == BAM_HV_PRESENT)) { (void) update_boot_entry(mp, NEW_HV_ENTRY, grubsign, grubroot, XEN_MENU, bam_zfs ? XEN_KERNEL_MODULE_LINE_ZFS : XEN_KERNEL_MODULE_LINE, DIRECT_BOOT_ARCHIVE, root_optional(osroot, menu_root)); - BAM_DPRINTF((D_UPDATED_HV_ENTRY, - fcn, bam_zfs, grubsign)); + BAM_DPRINTF(("%s: updated HV entry bam_zfs=%d, " + "grubsign = %s\n", fcn, bam_zfs, grubsign)); } } else { entry = update_boot_entry(mp, title, grubsign, grubroot, MULTI_BOOT, NULL, MULTIBOOT_ARCHIVE, root_optional(osroot, menu_root)); - BAM_DPRINTF((D_UPDATED_MULTIBOOT_ENTRY, fcn, grubsign)); + BAM_DPRINTF(("%s: updated MULTIBOOT entry grubsign = %s\n", + fcn, grubsign)); } /* @@ -8589,15 +8901,16 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) (void) update_boot_entry(mp, FAILSAFE_TITLE, grubsign, grubroot, failsafe_kernel, NULL, FAILSAFE_ARCHIVE, root_optional(osroot, menu_root)); - BAM_DPRINTF((D_UPDATED_FAILSAFE_ENTRY, fcn, - failsafe_kernel)); + BAM_DPRINTF(("%s: updated FAILSAFE entry " + "failsafe_kernel = %s\n", fcn, failsafe_kernel)); } } free(grubroot); INJECT_ERROR1("UPDATE_ENTRY_ERROR", entry = BAM_ERROR); if (entry == BAM_ERROR) { - bam_error(FAILED_TO_ADD_BOOT_ENTRY, title, grubsign); + bam_error(_("failed to add boot entry with title=%s, grub " + "signature=%s\n"), title, grubsign); free(grubsign); return (BAM_ERROR); } @@ -8607,9 +8920,9 @@ update_entry(menu_t *mp, char *menu_root, char *osdev) ret = set_global(mp, menu_cmds[DEFAULT_CMD], entry); INJECT_ERROR1("SET_DEFAULT_ERROR", ret = BAM_ERROR); if (ret == BAM_ERROR) { - bam_error(SET_DEFAULT_FAILED, entry); + bam_error(_("failed to set GRUB menu default to %d\n"), entry); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_WRITE); } @@ -8635,9 +8948,10 @@ save_default_entry(menu_t *mp, const char *which) entry = s_strtol(lp->arg); (void) snprintf(linebuf, sizeof (linebuf), "#%s%d", which, entry); - BAM_DPRINTF((D_SAVING_DEFAULT_TO, fcn, linebuf)); + BAM_DPRINTF(("%s: saving default to: %s\n", fcn, linebuf)); line_parser(mp, linebuf, &lineNum, &entryNum); - BAM_DPRINTF((D_SAVED_DEFAULT_TO, fcn, lineNum, entryNum)); + BAM_DPRINTF(("%s: saved default to lineNum=%d, entryNum=%d\n", fcn, + lineNum, entryNum)); } static void @@ -8648,17 +8962,17 @@ restore_default_entry(menu_t *mp, const char *which, line_t *lp) const char *fcn = "restore_default_entry()"; if (lp == NULL) { - BAM_DPRINTF((D_RESTORE_DEFAULT_NULL, fcn)); + BAM_DPRINTF(("%s: NULL saved default\n", fcn)); return; /* nothing to restore */ } - BAM_DPRINTF((D_RESTORE_DEFAULT_STR, fcn, which)); + BAM_DPRINTF(("%s: saved default string: %s\n", fcn, which)); str = lp->arg + strlen(which); entry = s_strtol(str); (void) set_global(mp, menu_cmds[DEFAULT_CMD], entry); - BAM_DPRINTF((D_RESTORED_DEFAULT_TO, fcn, entry)); + BAM_DPRINTF(("%s: restored default to entryNum: %d\n", fcn, entry)); /* delete saved old default line */ unlink_line(mp, lp); @@ -8697,45 +9011,49 @@ update_temp(menu_t *mp, char *dummy, char *opt) assert(dummy == NULL); /* opt can be NULL */ - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, opt ? opt : "<NULL>")); - BAM_DPRINTF((D_BAM_ROOT, fcn, bam_alt_root, bam_root)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, opt ? opt : "<NULL>")); + BAM_DPRINTF(("%s: bam_alt_root: %d, bam_root: %s\n", fcn, + bam_alt_root, bam_root)); if (bam_alt_root || bam_rootlen != 1 || strcmp(bam_root, "/") != 0 || strcmp(rootbuf, "/") != 0) { - bam_error(ALT_ROOT_INVALID, bam_root); + bam_error(_("an alternate root (%s) cannot be used with this " + "sub-command\n"), bam_root); return (BAM_ERROR); } /* If no option, delete exiting reboot menu entry */ if (opt == NULL) { entry_t *ent; - BAM_DPRINTF((D_OPT_NULL, fcn)); + BAM_DPRINTF(("%s: opt is NULL\n", fcn)); ent = find_boot_entry(mp, REBOOT_TITLE, NULL, NULL, NULL, NULL, 0, &entry); if (ent == NULL) { /* not found is ok */ - BAM_DPRINTF((D_TRANSIENT_NOTFOUND, fcn)); + BAM_DPRINTF(("%s: transient entry not found\n", fcn)); return (BAM_SUCCESS); } (void) delete_boot_entry(mp, entry, DBE_PRINTERR); restore_default_entry(mp, BAM_OLDDEF, mp->olddefault); mp->olddefault = NULL; - BAM_DPRINTF((D_RESTORED_DEFAULT, fcn)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: restored old default\n", fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_WRITE); } /* if entry= is specified, set the default entry */ if (strncmp(opt, "entry=", strlen("entry=")) == 0) { int entryNum = s_strtol(opt + strlen("entry=")); - BAM_DPRINTF((D_ENTRY_EQUALS, fcn, opt)); + BAM_DPRINTF(("%s: opt has entry=: %s\n", fcn, opt)); if (selector(mp, opt, &entry, NULL) == BAM_SUCCESS) { /* this is entry=# option */ ret = set_global(mp, menu_cmds[DEFAULT_CMD], entry); - BAM_DPRINTF((D_ENTRY_SET_IS, fcn, entry, ret)); + BAM_DPRINTF(("%s: default set to %d, " + "set_default ret=%d\n", fcn, entry, ret)); return (ret); } else { - bam_error(SET_DEFAULT_FAILED, entryNum); + bam_error(_("failed to set GRUB menu default to %d\n"), + entryNum); return (BAM_ERROR); } } @@ -8747,7 +9065,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) fstype = get_fstype("/"); INJECT_ERROR1("REBOOT_FSTYPE_NULL", fstype = NULL); if (fstype == NULL) { - bam_error(REBOOT_FSTYPE_FAILED); + bam_error(_("failed to determine filesystem type for \"/\". " + "Reboot with \narguments failed.\n")); return (BAM_ERROR); } @@ -8755,7 +9074,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) INJECT_ERROR1("REBOOT_SPECIAL_NULL", osdev = NULL); if (osdev == NULL) { free(fstype); - bam_error(REBOOT_SPECIAL_FAILED); + bam_error(_("failed to find device special file for \"/\". " + "Reboot with \narguments failed.\n")); return (BAM_ERROR); } @@ -8764,7 +9084,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) if (sign == NULL) { free(fstype); free(osdev); - bam_error(REBOOT_SIGN_FAILED); + bam_error(_("failed to find boot signature. Reboot with " + "arguments failed.\n")); return (BAM_ERROR); } @@ -8783,7 +9104,9 @@ update_temp(menu_t *mp, char *dummy, char *opt) INJECT_ERROR1("REBOOT_NOT_DBOOT", bam_direct = BAM_DIRECT_MULTIBOOT); if (bam_direct != BAM_DIRECT_DBOOT) { free(fstype); - bam_error(REBOOT_DIRECT_FAILED); + bam_error(_("the root filesystem is not a dboot Solaris " + "instance. \nThis version of bootadm is not supported " + "on this version of Solaris.\n")); return (BAM_ERROR); } @@ -8794,7 +9117,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) INJECT_ERROR1("REBOOT_GET_KERNEL", ret = BAM_ERROR); if (ret != BAM_SUCCESS) { free(fstype); - bam_error(REBOOT_GET_KERNEL_FAILED); + bam_error(_("reboot with arguments: error querying " + "current boot-file settings\n")); return (BAM_ERROR); } if (kernbuf[0] == '\0') @@ -8810,7 +9134,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) } (void) strlcat(kernbuf, " ", sizeof (kernbuf)); (void) strlcat(kernbuf, opt, sizeof (kernbuf)); - BAM_DPRINTF((D_REBOOT_OPTION, fcn, kernbuf)); + BAM_DPRINTF(("%s: reboot with args, option specified: " + "kern=%s\n", fcn, kernbuf)); } else if (opt[0] == '/') { /* It's a full path, so write it out. */ (void) strlcpy(kernbuf, opt, sizeof (kernbuf)); @@ -8836,7 +9161,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) INJECT_ERROR1("REBOOT_GET_ARGS", ret = BAM_ERROR); if (ret != BAM_SUCCESS) { free(fstype); - bam_error(REBOOT_GET_ARGS_FAILED); + bam_error(_("reboot with arguments: error " + "querying current boot-args settings\n")); return (BAM_ERROR); } @@ -8846,7 +9172,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) sizeof (kernbuf)); } } - BAM_DPRINTF((D_REBOOT_ABSPATH, fcn, kernbuf)); + BAM_DPRINTF(("%s: reboot with args, abspath specified: " + "kern=%s\n", fcn, kernbuf)); } else { /* * It may be a partial path, or it may be a partial @@ -8880,7 +9207,9 @@ update_temp(menu_t *mp, char *dummy, char *opt) ret = BAM_ERROR); if (ret != BAM_SUCCESS) { free(fstype); - bam_error(REBOOT_GET_ARGS_FAILED); + bam_error(_("reboot with arguments: " + "error querying current boot-args " + "settings\n")); return (BAM_ERROR); } @@ -8891,11 +9220,14 @@ update_temp(menu_t *mp, char *dummy, char *opt) args_buf, sizeof (kernbuf)); } } - BAM_DPRINTF((D_REBOOT_RESOLVED_PARTIAL, fcn, kernbuf)); + BAM_DPRINTF(("%s: resolved partial path: %s\n", + fcn, kernbuf)); } else { free(fstype); - bam_error(UNKNOWN_KERNEL, opt); - bam_print_stderr(UNKNOWN_KERNEL_REBOOT); + bam_error(_("unable to expand %s to a full file" + " path.\n"), opt); + bam_print_stderr(_("Rebooting with default kernel " + "and options.\n")); return (BAM_ERROR); } } @@ -8904,7 +9236,8 @@ update_temp(menu_t *mp, char *dummy, char *opt) NULL, NULL, NULL); INJECT_ERROR1("REBOOT_ADD_BOOT_ENTRY", entry = BAM_ERROR); if (entry == BAM_ERROR) { - bam_error(REBOOT_WITH_ARGS_ADD_ENTRY_FAILED); + bam_error(_("Cannot update menu. Cannot reboot with " + "requested arguments\n")); return (BAM_ERROR); } @@ -8912,9 +9245,10 @@ update_temp(menu_t *mp, char *dummy, char *opt) ret = set_global(mp, menu_cmds[DEFAULT_CMD], entry); INJECT_ERROR1("REBOOT_SET_GLOBAL", ret = BAM_ERROR); if (ret == BAM_ERROR) { - bam_error(REBOOT_SET_DEFAULT_FAILED, entry); + bam_error(_("reboot with arguments: setting GRUB menu default " + "to %d failed\n"), entry); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_WRITE); } @@ -8939,7 +9273,7 @@ set_global(menu_t *mp, char *globalcmd, int val) INJECT_ERROR1("SET_GLOBAL_VAL_TOO_BIG", val = 100); if (val < 0 || mp->end == NULL || val > mp->end->entryNum) { (void) snprintf(prefix, sizeof (prefix), "%d", val); - bam_error(INVALID_ENTRY, prefix); + bam_error(_("invalid boot entry number: %s\n"), prefix); return (BAM_ERROR); } } @@ -8953,16 +9287,19 @@ set_global(menu_t *mp, char *globalcmd, int val) INJECT_ERROR1("SET_GLOBAL_NULL_CMD", lp->cmd = NULL); if (lp->cmd == NULL) { - bam_error(NO_CMD, lp->lineNum); + bam_error(_("no command at line %d\n"), lp->lineNum); continue; } if (strcmp(globalcmd, lp->cmd) != 0) continue; - BAM_DPRINTF((D_FOUND_GLOBAL, fcn, globalcmd)); + BAM_DPRINTF(("%s: found matching global command: %s\n", + fcn, globalcmd)); if (found) { - bam_error(DUP_CMD, globalcmd, lp->lineNum, bam_root); + bam_error(_("duplicate command %s at line %d of " + "%sboot/grub/menu.lst\n"), globalcmd, + lp->lineNum, bam_root); } found = lp; } @@ -8985,8 +9322,8 @@ set_global(menu_t *mp, char *globalcmd, int val) lp->line = s_calloc(1, len); (void) snprintf(lp->line, len, "%s%s%d", globalcmd, menu_cmds[SEP_CMD], val); - BAM_DPRINTF((D_SET_GLOBAL_WROTE_NEW, fcn, lp->line)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: wrote new global line: %s\n", fcn, lp->line)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_WRITE); } @@ -9008,8 +9345,8 @@ set_global(menu_t *mp, char *globalcmd, int val) (void) snprintf(found->line, len, "%s%s%s%d", prefix, globalcmd, menu_cmds[SEP_CMD], val); - BAM_DPRINTF((D_SET_GLOBAL_REPLACED, fcn, found->line)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: replaced global line with: %s\n", fcn, found->line)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_WRITE); /* need a write to menu */ } @@ -9034,14 +9371,14 @@ expand_path(const char *partial_path) (void) snprintf(new_path, new_path_len, "/platform/i86pc/%s", partial_path); if (stat(new_path, &sb) == 0) { - BAM_DPRINTF((D_EXPAND_PATH, fcn, new_path)); + BAM_DPRINTF(("%s: expanded path: %s\n", fcn, new_path)); return (new_path); } if (strcmp(partial_path, "kmdb") == 0) { (void) snprintf(new_path, new_path_len, "%s -k", DIRECT_BOOT_KERNEL); - BAM_DPRINTF((D_EXPAND_PATH, fcn, new_path)); + BAM_DPRINTF(("%s: expanded path: %s\n", fcn, new_path)); return (new_path); } @@ -9063,12 +9400,12 @@ expand_path(const char *partial_path) "/platform/i86pc/kernel/%s/$ISADIR/unix", partial_path); } - BAM_DPRINTF((D_EXPAND_PATH, fcn, new_path)); + BAM_DPRINTF(("%s: expanded path: %s\n", fcn, new_path)); return (new_path); } free(new_path); - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); return (NULL); } @@ -9092,14 +9429,15 @@ set_archive_line(entry_t *entryp, line_t *kernelp) INJECT_ERROR1("SET_ARCHIVE_LINE_END_ENTRY", lp = entryp->end); if (lp == entryp->end) { - BAM_DPRINTF((D_ARCHIVE_LINE_NONE, fcn, - entryp->entryNum)); + BAM_DPRINTF(("%s: no module/archive line for entry: " + "%d\n", fcn, entryp->entryNum)); return; } } INJECT_ERROR1("SET_ARCHIVE_LINE_END_MENU", lp = NULL); if (lp == NULL) { - BAM_DPRINTF((D_ARCHIVE_LINE_NONE, fcn, entryp->entryNum)); + BAM_DPRINTF(("%s: no module/archive line for entry: %d\n", + fcn, entryp->entryNum)); return; } @@ -9115,7 +9453,7 @@ set_archive_line(entry_t *entryp, line_t *kernelp) } if (strcmp(lp->arg, new_archive) == 0) { - BAM_DPRINTF((D_ARCHIVE_LINE_NOCHANGE, fcn, lp->arg)); + BAM_DPRINTF(("%s: no change for line: %s\n", fcn, lp->arg)); return; } @@ -9127,7 +9465,7 @@ set_archive_line(entry_t *entryp, line_t *kernelp) free(lp->arg); lp->arg = s_strdup(new_archive); update_line(lp); - BAM_DPRINTF((D_ARCHIVE_LINE_REPLACED, fcn, lp->line)); + BAM_DPRINTF(("%s: replaced for line: %s\n", fcn, lp->line)); } /* @@ -9179,7 +9517,9 @@ get_set_kernel( INJECT_ERROR1("GET_SET_KERNEL_NOT_DBOOT", bam_direct = BAM_DIRECT_MULTIBOOT); if (bam_direct != BAM_DIRECT_DBOOT) { - bam_error(NOT_DBOOT, optnum == KERNEL_CMD ? "kernel" : "args"); + bam_error(_("bootadm set-menu %s may only be run on " + "directboot kernels.\n"), + optnum == KERNEL_CMD ? "kernel" : "args"); return (BAM_ERROR); } @@ -9196,7 +9536,8 @@ get_set_kernel( } if ((entryp != NULL) && ((entryp->flags & (BAM_ENTRY_BOOTADM|BAM_ENTRY_LU)) == 0)) { - bam_error(DEFAULT_NOT_BAM); + bam_error(_("Default /boot/grub/menu.lst entry is not " + "controlled by bootadm. Exiting\n")); return (BAM_ERROR); } } @@ -9214,7 +9555,8 @@ get_set_kernel( } } if (kernelp == NULL) { - bam_error(NO_KERNEL, entryNum); + bam_error(_("no kernel line found in entry %d\n"), + entryNum); return (BAM_ERROR); } @@ -9226,15 +9568,17 @@ get_set_kernel( if (path == NULL) { if (entryp == NULL) { - BAM_DPRINTF((D_GET_SET_KERNEL_NO_RC, fcn)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: no RC entry, nothing to report\n", + fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } assert(kernelp); if (optnum == ARGS_CMD) { if (old_args[0] != '\0') { (void) strlcpy(buf, old_args, bufsize); - BAM_DPRINTF((D_GET_SET_KERNEL_ARGS, fcn, buf)); + BAM_DPRINTF(("%s: read menu boot-args: %s\n", + fcn, buf)); } } else { /* @@ -9246,11 +9590,12 @@ get_set_kernel( *space = '\0'; if (strcmp(kernelp->arg, DIRECT_BOOT_KERNEL) != 0) { (void) strlcpy(buf, kernelp->arg, bufsize); - BAM_DPRINTF((D_GET_SET_KERNEL_KERN, fcn, buf)); + BAM_DPRINTF(("%s: read menu boot-file: %s\n", + fcn, buf)); } *space = old_space; } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } @@ -9262,7 +9607,8 @@ get_set_kernel( (strcmp(path, DIRECT_BOOT_KERNEL) == 0))) { if ((entryp == NULL) || (kernelp == NULL)) { /* No previous entry, it's already the default */ - BAM_DPRINTF((D_GET_SET_KERNEL_ALREADY, fcn)); + BAM_DPRINTF(("%s: no reset, already has default\n", + fcn)); return (BAM_SUCCESS); } @@ -9283,7 +9629,7 @@ get_set_kernel( mp->old_rc_default); mp->old_rc_default = NULL; rv = BAM_WRITE; - BAM_DPRINTF((D_GET_SET_KERNEL_RESTORE_DEFAULT, fcn)); + BAM_DPRINTF(("%s: resetting to default\n", fcn)); goto done; } @@ -9306,8 +9652,8 @@ get_set_kernel( * to update the archive line as well. */ set_archive_line(entryp, kernelp); - BAM_DPRINTF((D_GET_SET_KERNEL_RESET_KERNEL_SET_ARG, - fcn, kernelp->arg)); + BAM_DPRINTF(("%s: reset kernel to default, but " + "retained old args: %s\n", fcn, kernelp->arg)); } else { /* * We're resetting the boot args to nothing, so @@ -9319,8 +9665,8 @@ get_set_kernel( kernelp->arg); free(kernelp->arg); kernelp->arg = new_arg; - BAM_DPRINTF((D_GET_SET_KERNEL_RESET_ARG_SET_KERNEL, - fcn, kernelp->arg)); + BAM_DPRINTF(("%s: reset args to default, but retained " + "old kernel: %s\n", fcn, kernelp->arg)); } rv = BAM_WRITE; goto done; @@ -9332,8 +9678,9 @@ get_set_kernel( if ((optnum == KERNEL_CMD) && (path[0] != '/')) { new_path = expand_path(path); if (new_path == NULL) { - bam_error(UNKNOWN_KERNEL, path); - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + bam_error(_("unable to expand %s to a full file " + "path.\n"), path); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); return (BAM_ERROR); } free_new_path = 1; @@ -9352,7 +9699,9 @@ get_set_kernel( fstype = get_fstype("/"); INJECT_ERROR1("GET_SET_KERNEL_FSTYPE", fstype = NULL); if (fstype == NULL) { - bam_error(BOOTENV_FSTYPE_FAILED); + bam_error(_("cannot determine filesystem type for " + "\"/\".\nCannot generate GRUB menu entry with " + "EEPROM arguments.\n")); rv = BAM_ERROR; goto done; } @@ -9361,7 +9710,9 @@ get_set_kernel( INJECT_ERROR1("GET_SET_KERNEL_SPECIAL", osdev = NULL); if (osdev == NULL) { free(fstype); - bam_error(BOOTENV_SPECIAL_FAILED); + bam_error(_("cannot determine device special file for " + "\"/\".\nCannot generate GRUB menu entry with " + "EEPROM arguments.\n")); rv = BAM_ERROR; goto done; } @@ -9371,7 +9722,9 @@ get_set_kernel( if (sign == NULL) { free(fstype); free(osdev); - bam_error(BOOTENV_SIGN_FAILED); + bam_error(_("cannot determine boot signature for " + "\"/\".\nCannot generate GRUB menu entry with " + "EEPROM arguments.\n")); rv = BAM_ERROR; goto done; } @@ -9390,13 +9743,13 @@ get_set_kernel( new_arg = s_calloc(1, new_str_len); (void) snprintf(new_arg, new_str_len, "%s %s", new_path, ZFS_BOOT); - BAM_DPRINTF((D_GET_SET_KERNEL_NEW_KERN, fcn, + BAM_DPRINTF(("%s: new kernel=%s\n", fcn, new_arg)); entryNum = add_boot_entry(mp, BOOTENV_RC_TITLE, signbuf, new_arg, NULL, NULL, NULL); free(new_arg); } else { - BAM_DPRINTF((D_GET_SET_KERNEL_NEW_KERN, fcn, + BAM_DPRINTF(("%s: new kernel=%s\n", fcn, new_path)); entryNum = add_boot_entry(mp, BOOTENV_RC_TITLE, signbuf, new_path, NULL, NULL, NULL); @@ -9415,7 +9768,7 @@ get_set_kernel( DIRECT_BOOT_KERNEL, path); } - BAM_DPRINTF((D_GET_SET_KERNEL_NEW_ARG, fcn, new_arg)); + BAM_DPRINTF(("%s: new args=%s\n", fcn, new_arg)); entryNum = add_boot_entry(mp, BOOTENV_RC_TITLE, signbuf, new_arg, NULL, DIRECT_BOOT_ARCHIVE, NULL); free(new_arg); @@ -9424,7 +9777,7 @@ get_set_kernel( INJECT_ERROR1("GET_SET_KERNEL_ADD_BOOT_ENTRY", entryNum = BAM_ERROR); if (entryNum == BAM_ERROR) { - bam_error(GET_SET_KERNEL_ADD_BOOT_ENTRY, + bam_error(_("failed to add boot entry: %s\n"), BOOTENV_RC_TITLE); rv = BAM_ERROR; goto done; @@ -9433,7 +9786,8 @@ get_set_kernel( ret = set_global(mp, menu_cmds[DEFAULT_CMD], entryNum); INJECT_ERROR1("GET_SET_KERNEL_SET_GLOBAL", ret = BAM_ERROR); if (ret == BAM_ERROR) { - bam_error(GET_SET_KERNEL_SET_GLOBAL, entryNum); + bam_error(_("failed to set default to: %d\n"), + entryNum); } rv = BAM_WRITE; goto done; @@ -9455,8 +9809,8 @@ get_set_kernel( * the archive line as well. */ set_archive_line(entryp, kernelp); - BAM_DPRINTF((D_GET_SET_KERNEL_REPLACED_KERNEL_SAME_ARG, fcn, - kernelp->arg)); + BAM_DPRINTF(("%s: rc line exists, replaced kernel, same " + "args: %s\n", fcn, kernelp->arg)); } else { new_str_len = old_kernel_len + strlen(path) + 8; new_arg = s_calloc(1, new_str_len); @@ -9465,8 +9819,8 @@ get_set_kernel( (void) strlcat(new_arg, path, new_str_len); free(kernelp->arg); kernelp->arg = new_arg; - BAM_DPRINTF((D_GET_SET_KERNEL_SAME_KERNEL_REPLACED_ARG, fcn, - kernelp->arg)); + BAM_DPRINTF(("%s: rc line exists, same kernel, but new " + "args: %s\n", fcn, kernelp->arg)); } rv = BAM_WRITE; @@ -9476,9 +9830,9 @@ done: if (free_new_path) free(new_path); if (rv == BAM_WRITE) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (rv); } @@ -9487,7 +9841,7 @@ static error_t get_kernel(menu_t *mp, menu_cmd_t optnum, char *buf, size_t bufsize) { const char *fcn = "get_kernel()"; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, menu_cmds[optnum])); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, menu_cmds[optnum])); return (get_set_kernel(mp, optnum, NULL, buf, bufsize)); } @@ -9496,7 +9850,8 @@ set_kernel(menu_t *mp, menu_cmd_t optnum, char *path, char *buf, size_t bufsize) { const char *fcn = "set_kernel()"; assert(path != NULL); - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, menu_cmds[optnum], path)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, + menu_cmds[optnum], path)); return (get_set_kernel(mp, optnum, path, buf, bufsize)); } @@ -9516,7 +9871,7 @@ set_option(menu_t *mp, char *dummy, char *opt) assert(dummy == NULL); /* opt is set from bam_argv[0] and is always non-NULL */ - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, opt)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, opt)); val = strchr(opt, '='); if (val != NULL) { @@ -9532,7 +9887,7 @@ set_option(menu_t *mp, char *dummy, char *opt) } else if (strcmp(opt, menu_cmds[ARGS_CMD]) == 0) { optnum = ARGS_CMD; } else { - bam_error(INVALID_OPTION, opt); + bam_error(_("invalid option: %s\n"), opt); return (BAM_ERROR); } @@ -9541,15 +9896,15 @@ set_option(menu_t *mp, char *dummy, char *opt) * others cause errors */ if ((val == NULL) && (optnum != KERNEL_CMD) && (optnum != ARGS_CMD)) { - bam_error(NO_OPTION_ARG, opt); + bam_error(_("option has no argument: %s\n"), opt); return (BAM_ERROR); } else if (val != NULL) { *val = '='; } if ((optnum == KERNEL_CMD) || (optnum == ARGS_CMD)) { - BAM_DPRINTF((D_SET_OPTION, fcn, menu_cmds[optnum], - val ? val + 1 : "NULL")); + BAM_DPRINTF(("%s: setting %s option to %s\n", + fcn, menu_cmds[optnum], val ? val + 1 : "NULL")); if (val) rv = set_kernel(mp, optnum, val + 1, buf, sizeof (buf)); @@ -9559,14 +9914,15 @@ set_option(menu_t *mp, char *dummy, char *opt) (void) printf("%s\n", buf); } else { optval = s_strtol(val + 1); - BAM_DPRINTF((D_SET_OPTION, fcn, menu_cmds[optnum], val + 1)); + BAM_DPRINTF(("%s: setting %s option to %s\n", fcn, + menu_cmds[optnum], val + 1)); rv = set_global(mp, menu_cmds[optnum], optval); } if (rv == BAM_WRITE || rv == BAM_SUCCESS) { - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (rv); @@ -9589,7 +9945,7 @@ read_globals(menu_t *mp, char *menu_path, char *globalcmd, int quiet) if (mp->start == NULL) { if (!quiet) - bam_error(NO_MENU, menu_path); + bam_error(_("menu file not found: %s\n"), menu_path); return (BAM_ERROR); } @@ -9600,7 +9956,8 @@ read_globals(menu_t *mp, char *menu_path, char *globalcmd, int quiet) if (lp->cmd == NULL) { if (!quiet) - bam_error(NO_CMD, lp->lineNum); + bam_error(_("no command at line %d\n"), + lp->lineNum); continue; } @@ -9609,17 +9966,19 @@ read_globals(menu_t *mp, char *menu_path, char *globalcmd, int quiet) /* Found global. Check for duplicates */ if (done && !quiet) { - bam_error(DUP_CMD, globalcmd, lp->lineNum, bam_root); + bam_error(_("duplicate command %s at line %d of " + "%sboot/grub/menu.lst\n"), globalcmd, + lp->lineNum, bam_root); ret = BAM_ERROR; } arg = lp->arg ? lp->arg : ""; - bam_print(GLOBAL_CMD, globalcmd, arg); + bam_print(_("%s %s\n"), globalcmd, arg); done = 1; } if (!done && bam_verbose) - bam_print(NO_ENTRY, globalcmd); + bam_print(_("no %s entry found\n"), globalcmd); return (ret); } @@ -9629,7 +9988,7 @@ menu_write(char *root, menu_t *mp) { const char *fcn = "menu_write()"; - BAM_DPRINTF((D_MENU_WRITE_ENTER, fcn, root)); + BAM_DPRINTF(("%s: entered menu_write() for root: <%s>\n", fcn, root)); return (list2file(root, MENU_TMP, GRUB_MENU, mp->start)); } @@ -9712,7 +10071,7 @@ exec_cmd(char *cmdline, filelist_t *flistp) * - set IFS to space and tab */ if (*cmdline != '/') { - bam_error(ABS_PATH_REQ, cmdline); + bam_error(_("path is not absolute: %s\n"), cmdline); return (-1); } (void) putenv("IFS= \t"); @@ -9724,7 +10083,7 @@ exec_cmd(char *cmdline, filelist_t *flistp) (void) sigemptyset(&set); (void) sigaddset(&set, SIGCHLD); if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { - bam_error(CANT_UNBLOCK_SIGCHLD, strerror(errno)); + bam_error(_("cannot unblock SIGCHLD: %s\n"), strerror(errno)); return (-1); } @@ -9733,17 +10092,20 @@ exec_cmd(char *cmdline, filelist_t *flistp) */ disp = sigset(SIGCHLD, SIG_DFL); if (disp == SIG_ERR) { - bam_error(FAILED_SIG, strerror(errno)); + bam_error(_("cannot set SIGCHLD disposition: %s\n"), + strerror(errno)); return (-1); } if (disp == SIG_HOLD) { - bam_error(BLOCKED_SIG, cmdline); + bam_error(_("SIGCHLD signal blocked. Cannot exec: %s\n"), + cmdline); return (-1); } ptr = popen(cmdline, "r"); if (ptr == NULL) { - bam_error(POPEN_FAIL, cmdline, strerror(errno)); + bam_error(_("popen failed: %s: %s\n"), cmdline, + strerror(errno)); return (-1); } @@ -9766,7 +10128,7 @@ exec_cmd(char *cmdline, filelist_t *flistp) while (s_fgets(buf, sizeof (buf), ptr) != NULL) { if (flistp == NULL) { /* s_fgets strips newlines, so insert them at the end */ - bam_print(PRINT, buf); + bam_print(_("%s\n"), buf); } else { append_to_flist(flistp, buf); } @@ -9774,14 +10136,16 @@ exec_cmd(char *cmdline, filelist_t *flistp) ret = pclose(ptr); if (ret == -1) { - bam_error(PCLOSE_FAIL, cmdline, strerror(errno)); + bam_error(_("pclose failed: %s: %s\n"), cmdline, + strerror(errno)); return (-1); } if (WIFEXITED(ret)) { return (WEXITSTATUS(ret)); } else { - bam_error(EXEC_FAIL, cmdline, ret); + bam_error(_("command terminated abnormally: %s: %d\n"), + cmdline, ret); return (-1); } } @@ -9834,7 +10198,8 @@ s_fgets(char *buf, int buflen, FILE *fp) if (buf) { n = strlen(buf); if (n == buflen - 1 && buf[n-1] != '\n') - bam_error(TOO_LONG, buflen - 1, buf); + bam_error(_("the following line is too long " + "(> %d chars)\n\t%s\n"), buflen - 1, buf); buf[n-1] = (buf[n-1] == '\n') ? '\0' : buf[n-1]; } @@ -9848,7 +10213,8 @@ s_calloc(size_t nelem, size_t sz) ptr = calloc(nelem, sz); if (ptr == NULL) { - bam_error(NO_MEM, nelem*sz); + bam_error(_("could not allocate memory: size = %u\n"), + nelem*sz); bam_exit(1); } return (ptr); @@ -9859,7 +10225,7 @@ s_realloc(void *ptr, size_t sz) { ptr = realloc(ptr, sz); if (ptr == NULL) { - bam_error(NO_MEM, sz); + bam_error(_("could not allocate memory: size = %u\n"), sz); bam_exit(1); } return (ptr); @@ -9875,7 +10241,8 @@ s_strdup(char *str) ptr = strdup(str); if (ptr == NULL) { - bam_error(NO_MEM, strlen(str) + 1); + bam_error(_("could not allocate memory: size = %u\n"), + strlen(str) + 1); bam_exit(1); } return (ptr); diff --git a/usr/src/cmd/boot/bootadm/bootadm.h b/usr/src/cmd/boot/bootadm/bootadm.h index b59d860e4e..0b63a69310 100644 --- a/usr/src/cmd/boot/bootadm/bootadm.h +++ b/usr/src/cmd/boot/bootadm/bootadm.h @@ -33,11 +33,18 @@ extern "C" { #endif #include <assert.h> +#include <libintl.h> #ifndef TEXT_DOMAIN #define TEXT_DOMAIN "SUNW_OST_OSCMD" #endif /* TEXT_DOMAIN */ +#ifndef lint +#define _(x) gettext(x) +#else +#define _(x) (x) +#endif + /* Type definitions */ /* GRUB menu per-line classification */ @@ -154,6 +161,27 @@ typedef enum { BAM_FINDROOT_PRESENT } findroot_t; +typedef enum { + OPT_ABSENT = 0, /* No option */ + OPT_REQ, /* option required */ + OPT_OPTIONAL /* option may or may not be present */ +} option_t; + +typedef struct { + char *subcmd; + option_t option; + error_t (*handler)(); + int unpriv; /* is this an unprivileged command */ +} subcmd_defn_t; + +typedef enum zfs_mnted { + ZFS_MNT_ERROR = -1, + LEGACY_MOUNTED = 1, + LEGACY_ALREADY, + ZFS_MOUNTED, + ZFS_ALREADY +} zfs_mnted_t; + extern int bam_verbose; extern int bam_force; extern direct_or_multi_t bam_direct; @@ -167,6 +195,11 @@ extern error_t set_global(menu_t *, char *, int); extern error_t upgrade_menu(menu_t *, char *, char *); extern error_t cvt_to_hyper(menu_t *, char *, char *); extern error_t cvt_to_metal(menu_t *, char *, char *); +extern error_t check_subcmd_and_options(char *, char *, subcmd_defn_t *, + error_t (**fp)()); +extern char *mount_top_dataset(char *pool, zfs_mnted_t *mnted); +extern void elide_trailing_slash(const char *, char *, size_t); +extern int umount_top_dataset(char *, zfs_mnted_t, char *); extern void *s_calloc(size_t, size_t); extern void *s_realloc(void *, size_t); extern char *s_fgets(char *buf, int n, FILE *fp); @@ -175,6 +208,7 @@ extern void bam_exit(int); extern void bam_print(char *, ...); extern void bam_print_stderr(char *format, ...); extern void bam_derror(char *format, ...); +extern error_t bam_loader_menu(char *, char *, int, char *[]); extern error_t get_boot_cap(const char *osroot); extern char *get_special(char *); extern char *os_to_grubdisk(char *, int); @@ -190,6 +224,8 @@ extern void unlink_line(menu_t *mp, line_t *lp); extern void line_free(line_t *lp); extern char *s_strdup(char *); extern int is_sparc(void); +extern int is_pcfs(char *); +extern int is_zfs(char *); extern int bootadm_digest(const char *, char **); #define BAM_MAXLINE 8192 diff --git a/usr/src/cmd/boot/bootadm/bootadm_hyper.c b/usr/src/cmd/boot/bootadm/bootadm_hyper.c index 01e7dd3e69..66e0051eae 100644 --- a/usr/src/cmd/boot/bootadm/bootadm_hyper.c +++ b/usr/src/cmd/boot/bootadm/bootadm_hyper.c @@ -20,6 +20,7 @@ */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. */ @@ -32,7 +33,6 @@ #include <ctype.h> #include <sys/types.h> -#include "message.h" #include "bootadm.h" #define HYPER_KERNEL_DIR "/platform/i86xpv/kernel" @@ -82,7 +82,7 @@ append_str(char *orig, char *str, char *delim) len = strlen(orig) + strlen(str) + strlen(delim) + 1; if ((newstr = malloc(len)) == NULL) { - bam_error(NO_MEM, len); + bam_error(_("could not allocate memory: size = %u\n"), len); bam_exit(1); } @@ -116,7 +116,7 @@ modify_path(char *path, char *old_str, char *new_str) len = strlen(path) - strlen(old_str) + strlen(new_str) + 1; if ((newpath = malloc(len)) == NULL) { - bam_error(NO_MEM, len); + bam_error(_("could not allocate memory: size = %u\n"), len); bam_exit(1); } @@ -171,7 +171,8 @@ get_token(char **token, char *str, char *delim) /* found a delimiter, so create a token string */ if ((*token = malloc(len)) == NULL) { - bam_error(NO_MEM, len); + bam_error(_("could not allocate memory: " + "size = %u\n"), len); bam_exit(1); } @@ -520,7 +521,8 @@ cvt_metal_kernel(char *kernstr, char **path) * hypervisor, so error out now. */ if (strstr(*path, XEN_MENU) != NULL) { - bam_error(ALREADY_HYPER); + bam_error(_("default entry already setup for use with the " + "hypervisor!\n")); free(*path); *path = NULL; return (1); @@ -576,7 +578,8 @@ cvt_hyper_kernel(char *kernel) * to run on bare metal, so error out now. */ if (strncmp(token, METAL_KERNEL_DIR, strlen(METAL_KERNEL_DIR)) == 0) { - bam_error(ALREADY_METAL); + bam_error(_("default entry already setup for use with a metal " + "kernel!\n")); free(token); return (-1); } @@ -668,7 +671,8 @@ parse_bootenvrc(char *osroot) /* if we couldn't open the bootenv.rc file, ignore the issue. */ if ((fp = fopen(rcpath, "r")) == NULL) { - BAM_DPRINTF((D_NO_BOOTENVRC, rcpath, strerror(errno))); + BAM_DPRINTF(("could not open %s: %s\n", rcpath, + strerror(errno))); return; } @@ -775,13 +779,14 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) assert(osroot); - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, extra_args)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, extra_args)); /* * First just check to verify osroot is a sane directory. */ if ((osdev = get_special(osroot)) == NULL) { - bam_error(CANT_FIND_SPECIAL, osroot); + bam_error(_("cant find special file for mount-point %s\n"), + osroot); return (BAM_ERROR); } @@ -808,7 +813,8 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) /* couldn't find it, so error out */ if (ent == NULL) { - bam_error(CANT_FIND_DEFAULT, curdef); + bam_error(_("unable to find default boot entry (%d) in " + "menu.lst file.\n"), curdef); goto abort; } @@ -854,7 +860,9 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) &kern_path)) != 0) { if (ret < 0) { ret = BAM_ERROR; - bam_error(KERNEL_NOT_PARSEABLE, curdef); + bam_error(_("kernel$ in default boot " + "entry (%d) missing or not " + "parseable.\n"), curdef); } else ret = BAM_NOCHANGE; @@ -871,17 +879,20 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) * malformed. */ if (findroot == NULL) { - bam_error(FINDROOT_NOT_FOUND, curdef); + bam_error(_("findroot in default boot entry (%d) missing.\n"), + curdef); goto abort; } if (module == NULL) { - bam_error(MODULE_NOT_PARSEABLE, curdef); + bam_error(_("module$ in default boot entry (%d) missing or " + "not parseable.\n"), curdef); goto abort; } if (kern_path == NULL) { - bam_error(KERNEL_NOT_FOUND, curdef); + bam_error(_("kernel$ in default boot entry (%d) missing.\n"), + curdef); goto abort; } @@ -964,8 +975,8 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) if (ent->flags & BAM_ENTRY_BOOTADM) ent->flags &= ~BAM_ENTRY_BOOTADM; - BAM_DPRINTF((D_CVT_CMD_KERN_DOLLAR, fcn, kernel)); - BAM_DPRINTF((D_CVT_CMD_MOD_DOLLAR, fcn, mod_kernel)); + BAM_DPRINTF(("%s: converted kernel cmd to %s\n", fcn, kernel)); + BAM_DPRINTF(("%s: converted module cmd to %s\n", fcn, mod_kernel)); if ((newdef = add_boot_entry(mp, title, findroot, kernel, mod_kernel, module, bootfs)) == BAM_ERROR) @@ -978,7 +989,8 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) if (delete_boot_entry(mp, curdef, DBE_QUIET) == BAM_SUCCESS) newdef--; else - bam_print(NEW_BOOT_ENTRY, title); + bam_print(_("unable to modify default entry; creating new " + "boot entry for %s\n"), title); /* * If we successfully created the new entry, set the default boot @@ -989,7 +1001,9 @@ cvt_to_hyper(menu_t *mp, char *osroot, char *extra_args) abort: if (ret != BAM_NOCHANGE) - bam_error(HYPER_ABORT, ((*osroot == NULL) ? "/" : osroot)); + bam_error(_("error converting GRUB menu entry on %s for use " + "with the hypervisor.\nAborting.\n"), + ((*osroot == NULL) ? "/" : osroot)); return (ret); } @@ -1023,13 +1037,14 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) assert(osroot); - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, "")); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, "")); /* * First just check to verify osroot is a sane directory. */ if ((osdev = get_special(osroot)) == NULL) { - bam_error(CANT_FIND_SPECIAL, osroot); + bam_error(_("cant find special file for mount-point %s\n"), + osroot); return (BAM_ERROR); } @@ -1048,7 +1063,8 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) /* couldn't find it, so error out */ if (ent == NULL) { - bam_error(CANT_FIND_DEFAULT, curdef); + bam_error(_("unable to find default boot entry (%d) in " + "menu.lst file.\n"), curdef); goto abort; } @@ -1091,17 +1107,20 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) * malformed. */ if (findroot == NULL) { - bam_error(FINDROOT_NOT_FOUND, curdef); + bam_error(_("findroot in default boot entry (%d) missing.\n"), + curdef); goto abort; } if (module == NULL) { - bam_error(MODULE_NOT_PARSEABLE, curdef); + bam_error(_("module$ in default boot entry (%d) missing or " + "not parseable.\n"), curdef); goto abort; } if (kern_path == NULL) { - bam_error(KERNEL_NOT_FOUND, curdef); + bam_error(_("kernel$ in default boot entry (%d) missing.\n"), + curdef); goto abort; } @@ -1121,7 +1140,8 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) if ((kernel = malloc(len + zfslen)) == NULL) { free(kern_path); - bam_error(NO_MEM, len + zfslen); + bam_error(_("could not allocate memory: size = %u\n"), + len + zfslen); bam_exit(1); } @@ -1220,8 +1240,8 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) if (ent->flags & BAM_ENTRY_BOOTADM) ent->flags &= ~BAM_ENTRY_BOOTADM; - BAM_DPRINTF((D_CVT_CMD_KERN_DOLLAR, fcn, kernel)); - BAM_DPRINTF((D_CVT_CMD_MOD_DOLLAR, fcn, module)); + BAM_DPRINTF(("%s: converted kernel cmd to %s\n", fcn, kernel)); + BAM_DPRINTF(("%s: converted module cmd to %s\n", fcn, module)); if ((newdef = add_boot_entry(mp, title, findroot, kernel, NULL, barchive_path, bootfs)) == BAM_ERROR) { @@ -1236,7 +1256,8 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) if (delete_boot_entry(mp, curdef, DBE_QUIET) == BAM_SUCCESS) newdef--; else - bam_print(NEW_BOOT_ENTRY, title); + bam_print(_("unable to modify default entry; creating new " + "boot entry for %s\n"), title); free(kernel); @@ -1249,7 +1270,8 @@ cvt_to_metal(menu_t *mp, char *osroot, char *menu_root) abort: if (ret != BAM_NOCHANGE) - bam_error(METAL_ABORT, osroot); + bam_error(_("error converting GRUB menu entry on %s for use " + "with a metal kernel.\nAborting.\n"), osroot); return (ret); } diff --git a/usr/src/cmd/boot/bootadm/bootadm_loader.c b/usr/src/cmd/boot/bootadm/bootadm_loader.c new file mode 100644 index 0000000000..2c7382a11c --- /dev/null +++ b/usr/src/cmd/boot/bootadm/bootadm_loader.c @@ -0,0 +1,1329 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2012 Milan Jurik. All rights reserved. + */ + +/* + * Copyright 2015 Nexenta Systems, Inc. All rights reserved. + * Copyright 2016 Toomas Soome <tsoome@me.com> + */ + +/* + * Loader menu management. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include <errno.h> +#include <limits.h> +#include <alloca.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/queue.h> +#include <libbe.h> +#include <ficl.h> +#include <ficlplatform/emu.h> + +#include "bootadm.h" + +extern int bam_rootlen; +extern int bam_alt_root; +extern char *rootbuf; +extern char *bam_root; + +#define BOOT_DIR "/boot" +#define CONF_DIR BOOT_DIR "/conf.d" +#define MENU BOOT_DIR "/menu.lst" +#define TRANSIENT BOOT_DIR "/transient.conf" +#define XEN_CONFIG CONF_DIR "/xen" + +struct menu_entry { + int entry; + char *title; + char *bootfs; + STAILQ_ENTRY(menu_entry) next; +}; +STAILQ_HEAD(menu_lst, menu_entry); + +static error_t set_option(struct menu_lst *, char *, char *); +static error_t list_entry(struct menu_lst *, char *, char *); +static error_t update_entry(struct menu_lst *, char *, char *); +static error_t update_temp(struct menu_lst *, char *, char *); +static error_t list_setting(struct menu_lst *menu, char *, char *); +static error_t disable_hyper(struct menu_lst *, char *, char *); +static error_t enable_hyper(struct menu_lst *, char *, char *); + +/* Menu related sub commands */ +static subcmd_defn_t menu_subcmds[] = { + "set_option", OPT_ABSENT, set_option, 0, /* PUB */ + "list_entry", OPT_OPTIONAL, list_entry, 1, /* PUB */ + "update_entry", OPT_REQ, update_entry, 0, /* menu */ + "update_temp", OPT_OPTIONAL, update_temp, 0, /* reboot */ + "list_setting", OPT_OPTIONAL, list_setting, 1, /* menu */ + "disable_hypervisor", OPT_ABSENT, disable_hyper, 0, /* menu */ + "enable_hypervisor", OPT_ABSENT, enable_hyper, 0, /* menu */ + NULL, 0, NULL, 0 /* must be last */ +}; + +#define NUM_COLS (4) +struct col_info { + const char *col_name; + size_t width; +}; + +/* + * all columns output format + */ +struct hdr_info { + struct col_info cols[NUM_COLS]; +}; + +static void +print_hdr(struct hdr_info *hdr_info) +{ + boolean_t first = B_TRUE; + size_t i; + + for (i = 0; i < NUM_COLS; i++) { + struct col_info *col_info = &hdr_info->cols[i]; + const char *name = col_info->col_name; + size_t width = col_info->width; + + if (name == NULL) + continue; + + if (first) { + (void) printf("%-*s", width, name); + first = B_FALSE; + } else + (void) printf(" %-*s", width, name); + } + (void) putchar('\n'); +} + +static void +init_hdr_cols(struct hdr_info *hdr) +{ + struct col_info *col = hdr->cols; + size_t i; + + col[0].col_name = _("Index"); + col[1].col_name = _("Default"); + col[2].col_name = _("Dataset"); + col[3].col_name = _("Menu"); + col[4].col_name = NULL; + + for (i = 0; i < NUM_COLS; i++) { + const char *name = col[i].col_name; + col[i].width = 0; + + if (name != NULL) { + wchar_t wname[128]; + size_t sz = mbstowcs(wname, name, sizeof (wname) / + sizeof (wchar_t)); + if (sz > 0) { + int wcsw = wcswidth(wname, sz); + if (wcsw > 0) + col[i].width = wcsw; + else + col[i].width = sz; + } else { + col[i].width = strlen(name); + } + } + } +} + +static void +count_widths(struct hdr_info *hdr, struct menu_lst *menu) +{ + size_t len[NUM_COLS]; + struct menu_entry *entry; + int i; + + for (i = 0; i < NUM_COLS; i++) + len[i] = hdr->cols[i].width + 1; + + STAILQ_FOREACH(entry, menu, next) { + size_t bootfs_len = strlen(entry->bootfs); + if (bootfs_len > len[2]) + len[2] = bootfs_len + 1; + } + + for (i = 0; i < NUM_COLS; i++) + hdr->cols[i].width = len[i]; +} + +static void +print_menu_nodes(boolean_t parsable, struct hdr_info *hdr, + struct menu_lst *menu) +{ + struct menu_entry *entry; + int i = -1; + int rv; + be_node_list_t *be_nodes, *be_node; + + rv = be_list(NULL, &be_nodes); + if (rv != BE_SUCCESS) + return; + + STAILQ_FOREACH(entry, menu, next) { + i++; + for (be_node = be_nodes; be_node; + be_node = be_node->be_next_node) + if (strcmp(be_node->be_root_ds, entry->bootfs) == 0) + break; + + if (parsable) + (void) printf("%d;%s;%s;%s\n", i, + be_node->be_active_on_boot == B_TRUE? "*" : "-", + entry->bootfs, entry->title); + else + (void) printf("%-*d %-*s %-*s %-*s\n", + hdr->cols[0].width, i, + hdr->cols[1].width, + be_node->be_active_on_boot == B_TRUE? "*" : "-", + hdr->cols[2].width, entry->bootfs, + hdr->cols[3].width, entry->title); + } + be_free_list(be_nodes); +} + +static void +print_nodes(boolean_t parsable, struct menu_lst *menu) +{ + struct hdr_info hdr; + + if (!parsable) { + init_hdr_cols(&hdr); + count_widths(&hdr, menu); + print_hdr(&hdr); + } + + print_menu_nodes(parsable, &hdr, menu); +} + +error_t +menu_read(struct menu_lst *menu, char *menu_path) +{ + FILE *fp; + struct menu_entry *mp; + char buf[PATH_MAX]; + char *title; + char *bootfs; + char *ptr; + int i = 0; + int ret = BAM_SUCCESS; + + fp = fopen(menu_path, "r"); + if (fp == NULL) + return (BAM_ERROR); + + /* + * menu.lst entry is on two lines, one for title, one for bootfs + * so we process both lines in succession. + */ + do { + if (fgets(buf, PATH_MAX, fp) == NULL) { + if (!feof(fp)) + ret = BAM_ERROR; + (void) fclose(fp); + return (ret); + } + ptr = strchr(buf, '\n'); + if (ptr != NULL) + *ptr = '\0'; + + ptr = strchr(buf, ' '); + if (ptr == NULL) { + (void) fclose(fp); + return (BAM_ERROR); + } + *ptr++ = '\0'; + if (strcmp(buf, "title") != 0) { + (void) fclose(fp); + return (BAM_ERROR); + } + if ((title = strdup(ptr)) == NULL) { + (void) fclose(fp); + return (BAM_ERROR); + } + + if (fgets(buf, PATH_MAX, fp) == NULL) { + free(title); + (void) fclose(fp); + return (BAM_ERROR); + } + + ptr = strchr(buf, '\n'); + if (ptr != NULL) + *ptr = '\0'; + + ptr = strchr(buf, ' '); + if (ptr == NULL) { + free(title); + (void) fclose(fp); + return (BAM_ERROR); + } + *ptr++ = '\0'; + if (strcmp(buf, "bootfs") != 0) { + free(title); + (void) fclose(fp); + return (BAM_ERROR); + } + if ((bootfs = strdup(ptr)) == NULL) { + free(title); + (void) fclose(fp); + return (BAM_ERROR); + } + if ((mp = malloc(sizeof (struct menu_entry))) == NULL) { + free(title); + free(bootfs); + (void) fclose(fp); + return (BAM_ERROR); + } + mp->entry = i++; + mp->title = title; + mp->bootfs = bootfs; + STAILQ_INSERT_TAIL(menu, mp, next); + } while (feof(fp) == 0); + + (void) fclose(fp); + return (ret); +} + +void +menu_free(struct menu_lst *menu) +{ + struct menu_entry *entry; + STAILQ_FOREACH(entry, menu, next) { + STAILQ_REMOVE_HEAD(menu, next); + free(entry->title); + free(entry->bootfs); + free(entry); + } +} + +error_t +bam_loader_menu(char *subcmd, char *opt, int largc, char *largv[]) +{ + error_t ret; + char menu_path[PATH_MAX]; + char clean_menu_root[PATH_MAX]; + char menu_root[PATH_MAX]; + struct stat sb; + error_t (*f)(struct menu_lst *, char *, char *); + char *special; + char *pool = NULL; + zfs_mnted_t zmnted; + char *zmntpt; + char *osdev; + char *osroot; + const char *fcn = "bam_loader_menu()"; + struct menu_lst menu = {0}; + + STAILQ_INIT(&menu); + + /* + * Check arguments + */ + ret = check_subcmd_and_options(subcmd, opt, menu_subcmds, &f); + if (ret == BAM_ERROR) { + return (BAM_ERROR); + } + + assert(bam_root); + + (void) strlcpy(menu_root, bam_root, sizeof (menu_root)); + osdev = osroot = NULL; + + if (strcmp(subcmd, "update_entry") == 0) { + assert(opt); + + osdev = strtok(opt, ","); + assert(osdev); + osroot = strtok(NULL, ","); + if (osroot) { + /* fixup bam_root so that it points at osroot */ + if (realpath(osroot, rootbuf) == NULL) { + bam_error(_("cannot resolve path %s: %s\n"), + osroot, strerror(errno)); + return (BAM_ERROR); + } + bam_alt_root = 1; + bam_root = rootbuf; + bam_rootlen = strlen(rootbuf); + } + } + + if (stat(menu_root, &sb) == -1) { + bam_error(_("cannot find menu\n")); + return (BAM_ERROR); + } + + if (!is_zfs(menu_root)) { + bam_error(_("only ZFS root is supported\n")); + return (BAM_ERROR); + } + + assert(strcmp(menu_root, bam_root) == 0); + special = get_special(menu_root); + INJECT_ERROR1("Z_MENU_GET_SPECIAL", special = NULL); + if (special == NULL) { + bam_error(_("cant find special file for mount-point %s\n"), + menu_root); + return (BAM_ERROR); + } + pool = strtok(special, "/"); + INJECT_ERROR1("Z_MENU_GET_POOL", pool = NULL); + if (pool == NULL) { + free(special); + bam_error(_("cant find pool for mount-point %s\n"), menu_root); + return (BAM_ERROR); + } + BAM_DPRINTF(("%s: derived pool=%s from special\n", fcn, pool)); + + zmntpt = mount_top_dataset(pool, &zmnted); + INJECT_ERROR1("Z_MENU_MOUNT_TOP_DATASET", zmntpt = NULL); + if (zmntpt == NULL) { + bam_error(_("cannot mount pool dataset for pool: %s\n"), pool); + free(special); + return (BAM_ERROR); + } + BAM_DPRINTF(("%s: top dataset mountpoint=%s\n", fcn, zmntpt)); + + (void) strlcpy(menu_root, zmntpt, sizeof (menu_root)); + BAM_DPRINTF(("%s: zfs menu_root=%s\n", fcn, menu_root)); + + elide_trailing_slash(menu_root, clean_menu_root, + sizeof (clean_menu_root)); + + BAM_DPRINTF(("%s: cleaned menu root is <%s>\n", fcn, clean_menu_root)); + + (void) strlcpy(menu_path, clean_menu_root, sizeof (menu_path)); + (void) strlcat(menu_path, MENU, sizeof (menu_path)); + + BAM_DPRINTF(("%s: menu path is: %s\n", fcn, menu_path)); + + /* + * update_entry is special case, its used by installer + * and needs to create menu.lst file for loader + */ + if (menu_read(&menu, menu_path) == BAM_ERROR && + strcmp(subcmd, "update_entry") != 0) { + bam_error(_("cannot find menu file: %s\n"), menu_path); + if (special != NULL) + free(special); + return (BAM_ERROR); + } + + /* + * If listing the menu, display the menu location + */ + if (strcmp(subcmd, "list_entry") == 0) + bam_print(_("the location for the active menu is: %s\n"), + menu_path); + + /* + * We already checked the following case in + * check_subcmd_and_suboptions() above. Complete the + * final step now. + */ + if (strcmp(subcmd, "set_option") == 0) { + assert(largc == 1 && largv[0] && largv[1] == NULL); + opt = largv[0]; + } else if ((strcmp(subcmd, "enable_hypervisor") != 0) && + (strcmp(subcmd, "list_setting") != 0)) { + assert(largc == 0 && largv == NULL); + } + + /* + * Once the sub-cmd handler has run + * only the line field is guaranteed to have valid values + */ + if (strcmp(subcmd, "update_entry") == 0) { + ret = f(&menu, menu_root, osdev); + } else if (strcmp(subcmd, "upgrade") == 0) { + ret = f(&menu, bam_root, menu_root); + } else if (strcmp(subcmd, "list_entry") == 0) { + ret = f(&menu, menu_path, opt); + } else if (strcmp(subcmd, "list_setting") == 0) { + ret = f(&menu, ((largc > 0) ? largv[0] : ""), + ((largc > 1) ? largv[1] : "")); + } else if (strcmp(subcmd, "disable_hypervisor") == 0) { + if (is_sparc()) { + bam_error(_("%s operation unsupported on SPARC " + "machines\n"), subcmd); + ret = BAM_ERROR; + } else { + ret = f(&menu, bam_root, NULL); + } + } else if (strcmp(subcmd, "enable_hypervisor") == 0) { + if (is_sparc()) { + bam_error(_("%s operation unsupported on SPARC " + "machines\n"), subcmd); + ret = BAM_ERROR; + } else { + char *extra_args = NULL; + + /* + * Compress all arguments passed in the largv[] array + * into one string that can then be appended to the + * end of the kernel$ string the routine to enable the + * hypervisor will build. + * + * This allows the caller to supply arbitrary unparsed + * arguments, such as dom0 memory settings or APIC + * options. + * + * This concatenation will be done without ANY syntax + * checking whatsoever, so it's the responsibility of + * the caller to make sure the arguments are valid and + * do not duplicate arguments the conversion routines + * may create. + */ + if (largc > 0) { + int extra_len, i; + + for (extra_len = 0, i = 0; i < largc; i++) + extra_len += strlen(largv[i]); + + /* + * Allocate space for argument strings, + * intervening spaces and terminating NULL. + */ + extra_args = alloca(extra_len + largc); + + (void) strcpy(extra_args, largv[0]); + + for (i = 1; i < largc; i++) { + (void) strcat(extra_args, " "); + (void) strcat(extra_args, largv[i]); + } + } + + ret = f(&menu, bam_root, extra_args); + } + } else + ret = f(&menu, NULL, opt); + + if (ret == BAM_WRITE) { + BAM_DPRINTF(("%s: writing menu to clean-menu-root: <%s>\n", + fcn, clean_menu_root)); + /* ret = menu_write(clean_menu_root, menu); */ + } + + INJECT_ERROR1("POOL_SET", pool = "/pooldata"); + assert((is_zfs(menu_root)) ^ (pool == NULL)); + if (pool) { + (void) umount_top_dataset(pool, zmnted, zmntpt); + free(special); + } + + menu_free(&menu); + return (ret); +} + +/* + * To suppress output from ficl. We do not want to see messages + * from interpreting loader config. + */ + +/*ARGSUSED*/ +static void +ficlTextOutSilent(ficlCallback *cb, char *text) +{ +} + +/*ARGSUSED*/ +static error_t +set_option(struct menu_lst *menu, char *dummy, char *opt) +{ + char path[PATH_MAX]; + char *val; + char *rest; + int optval; + struct menu_entry *entry; + nvlist_t *be_attrs; + FILE *fp; + int rv, ret = BAM_SUCCESS; + + assert(menu); + assert(opt); + assert(dummy == NULL); + + val = strchr(opt, '='); + if (val != NULL) { + *val++ = '\0'; + } + + if (strcmp(opt, "default") == 0) { + errno = 0; + optval = strtol(val, &rest, 10); + if (errno != 0 || *rest != '\0') { + bam_error(_("invalid boot entry number: %s\n"), val); + return (BAM_ERROR); + } + STAILQ_FOREACH(entry, menu, next) { + if (entry->entry == optval) + break; + } + if (entry == NULL) { + bam_error(_("invalid boot entry number: %s\n"), val); + return (BAM_ERROR); + } + if (nvlist_alloc(&be_attrs, NV_UNIQUE_NAME, 0) != 0) { + bam_error(_("out of memory\n")); + return (BAM_ERROR); + } + if (nvlist_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, + entry->title) != 0) { + bam_error(_("out of memory\n")); + nvlist_free(be_attrs); + return (BAM_ERROR); + } + ret = be_activate(be_attrs); + nvlist_free(be_attrs); + if (ret != 0) + ret = BAM_ERROR; + return (ret); + } else if (strcmp(opt, "timeout") == 0) { + errno = 0; + optval = strtol(val, &rest, 10); + if (errno != 0 || *rest != '\0') { + bam_error(_("invalid timeout: %s\n"), val); + return (BAM_ERROR); + } + + (void) snprintf(path, PATH_MAX, "%s" CONF_DIR "/timeout", + bam_root); + + fp = fopen(path, "w"); + if (fp == NULL) { + bam_error(_("failed to open file: %s: %s\n"), + path, strerror(errno)); + return (BAM_ERROR); + } + /* + * timeout=-1 is to disable auto boot in illumos, but + * loader needs "NO" to disable auto boot. + */ + if (optval == -1) + rv = fprintf(fp, "autoboot_delay=\"NO\"\n"); + else + rv = fprintf(fp, "autoboot_delay=\"%d\"\n", optval); + + if (rv < 0) { + bam_error(_("write to file failed: %s: %s\n"), + path, strerror(errno)); + (void) fclose(fp); + ret = BAM_ERROR; + } else + rv = fclose(fp); + + if (rv < 0) { + bam_error(_("failed to close file: %s: %s\n"), + path, strerror(errno)); + ret = BAM_ERROR; + } + if (ret == BAM_ERROR) + (void) unlink(path); + + return (BAM_SUCCESS); + } + + bam_error(_("invalid option: %s\n"), opt); + return (BAM_ERROR); +} + +static int +bam_mount_be(struct menu_entry *entry, char **dir) +{ + nvlist_t *be_attrs = NULL; + const char *tmpdir = getenv("TMPDIR"); + const char *tmpname = "bam.XXXXXX"; + be_node_list_t *be_node, *be_nodes = NULL; + int ret; + + *dir = NULL; + if (tmpdir == NULL) + tmpdir = "/tmp"; + + ret = asprintf(dir, "%s/%s", tmpdir, tmpname); + if (ret < 0) { + return (BE_ERR_NOMEM); + } + *dir = mkdtemp(*dir); + + if (nvlist_alloc(&be_attrs, NV_UNIQUE_NAME, 0) != 0) { + ret = BE_ERR_NOMEM; + goto out; + } + + ret = be_list(NULL, &be_nodes); + if (ret != BE_SUCCESS) { + goto out; + } + + for (be_node = be_nodes; be_node; + be_node = be_node->be_next_node) + if (strcmp(be_node->be_root_ds, entry->bootfs) == 0) + break; + + if (nvlist_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, + be_node->be_node_name) != 0) { + ret = BE_ERR_NOMEM; + goto out; + } + + if (nvlist_add_string(be_attrs, BE_ATTR_MOUNTPOINT, *dir) != 0) { + ret = BE_ERR_NOMEM; + goto out; + } + + ret = be_mount(be_attrs); + if (ret == BE_ERR_MOUNTED) { + /* + * if BE is mounted, dir does not point to correct directory + */ + (void) rmdir(*dir); + free(*dir); + *dir = NULL; + } +out: + if (be_nodes != NULL) + be_free_list(be_nodes); + nvlist_free(be_attrs); + return (ret); +} + +static int +bam_umount_be(char *dir) +{ + nvlist_t *be_attrs; + int ret; + + if (dir == NULL) /* nothing to do */ + return (BE_SUCCESS); + + if (nvlist_alloc(&be_attrs, NV_UNIQUE_NAME, 0) != 0) + return (BE_ERR_NOMEM); + + if (nvlist_add_string(be_attrs, BE_ATTR_ORIG_BE_NAME, dir) != 0) { + ret = BE_ERR_NOMEM; + goto out; + } + + ret = be_unmount(be_attrs); +out: + nvlist_free(be_attrs); + return (ret); +} + +/* + * display details of menu entry or single property + */ +static error_t +list_menu_entry(struct menu_entry *entry, char *setting) +{ + int ret = BAM_SUCCESS; + char *ptr, *dir; + char buf[MAX_INPUT]; + ficlVm *vm; + int mounted; + + mounted = bam_mount_be(entry, &dir); + if (mounted != BE_SUCCESS && mounted != BE_ERR_MOUNTED) { + if (dir != NULL) { + (void) rmdir(dir); + free(dir); + } + bam_error(_("%s is not mounted\n"), entry->title); + return (BAM_ERROR); + } + + vm = bf_init("", ficlTextOutSilent); + if (vm == NULL) { + bam_error(_("error setting up forth interpreter\n")); + ret = BAM_ERROR; + goto done; + } + + /* should only get FICL_VM_STATUS_OUT_OF_TEXT */ + (void) snprintf(buf, MAX_INPUT, "set currdev=zfs:%s:", + entry->bootfs); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("error interpreting boot config\n")); + ret = BAM_ERROR; + goto done; + } + (void) snprintf(buf, MAX_INPUT, "include /boot/forth/loader.4th"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("error interpreting boot config\n")); + ret = BAM_ERROR; + goto done; + } + (void) snprintf(buf, MAX_INPUT, "start"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("error interpreting boot config\n")); + ret = BAM_ERROR; + goto done; + } + (void) snprintf(buf, MAX_INPUT, "boot"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("error interpreting boot config\n")); + ret = BAM_ERROR; + goto done; + } + + ret = BAM_SUCCESS; + if (*setting == '\0') + (void) printf("\nTitle: %s\n", entry->title); + else if (strcasecmp(setting, "title") == 0) { + (void) printf("%s\n", entry->title); + goto done; + } + + ptr = getenv("autoboot_delay"); + if (ptr != NULL) { + char *timeout = "-1"; + + if (strcasecmp(ptr, "NO") != 0) + timeout = ptr; + + if (*setting == '\0') + (void) printf("Timeout: %s\n", timeout); + else if (strcasecmp(setting, "timeout") == 0) { + (void) printf("%s\n", timeout); + goto done; + } + + } + ptr = getenv("console"); + if (ptr != NULL) { + if (*setting == '\0') + (void) printf("Console: %s\n", ptr); + else if (strcasecmp(setting, "console") == 0) { + (void) printf("%s\n", ptr); + goto done; + } + } + + if (*setting == '\0') + (void) printf("Bootfs: %s\n", entry->bootfs); + else if (strcasecmp(setting, "bootfs") == 0) { + (void) printf("%s\n", entry->bootfs); + goto done; + } + + ptr = getenv("xen_kernel"); + if (ptr != NULL) { + if (*setting == '\0') { + (void) printf("Xen kernel: %s\n", ptr); + } else if (strcasecmp(setting, "xen_kernel") == 0) { + (void) printf("%s\n", ptr); + goto done; + } + + if (*setting == '\0') { + (void) printf("Xen args: \"%s\"\n", + getenv("xen_cmdline")); + } else if (strcasecmp(setting, "xen_cmdline") == 0) { + (void) printf("%s\n", getenv("xen_cmdline")); + goto done; + } + + if (*setting == '\0') { + (void) printf("Kernel: %s\n", + getenv("bootfile")); + } if (strcasecmp(setting, "kernel") == 0) { + (void) printf("%s\n", getenv("bootfile")); + goto done; + } + } else { + ptr = getenv("kernelname"); + if (ptr != NULL) { + if (*setting == '\0') { + (void) printf("Kernel: %s\n", ptr); + } else if (strcasecmp(setting, "kernel") == 0) { + (void) printf("%s\n", ptr); + goto done; + } + } + } + + ptr = getenv("boot-args"); + if (ptr != NULL) { + if (*setting == '\0') { + (void) printf("Boot-args: \"%s\"\n", ptr); + } else if (strcasecmp(setting, "boot-args") == 0) { + (void) printf("%s\n", ptr); + goto done; + } + } + + if (*setting == '\0' || strcasecmp(setting, "modules") == 0) { + (void) printf("\nModules:\n"); + ficlVmSetTextOut(vm, ficlCallbackDefaultTextOut); + (void) snprintf(buf, MAX_INPUT, "show-module-options"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("error interpreting boot config\n")); + ret = BAM_ERROR; + goto done; + } + ret = BAM_SUCCESS; + goto done; + } + + /* if we got here with setting string, its unknown property */ + if (*setting != '\0') { + bam_error(_("unknown property: %s\n"), setting); + ret = BAM_ERROR; + } else + ret = BAM_SUCCESS; +done: + bf_fini(); + if (mounted != BE_ERR_MOUNTED) { + (void) bam_umount_be(dir); + } + + if (dir != NULL) { + (void) rmdir(dir); + free(dir); + } + + return (ret); +} + +/*ARGSUSED*/ +static error_t +list_entry(struct menu_lst *menu, char *menu_root, char *opt) +{ + error_t ret = BAM_SUCCESS; + struct menu_entry *entry; + char *ptr, *title = NULL; + int i, e = -1; + + if (opt == NULL) { + print_nodes(B_FALSE, menu); + return (ret); + } + + if ((ptr = strchr(opt, '=')) == NULL) { + bam_error(_("invalid option: %s\n"), opt); + return (BAM_ERROR); + } + + i = ptr - opt; + if (strncmp(opt, "entry", i) == 0) { + e = atoi(ptr+1); + } else if (strncmp(opt, "title", i) == 0) { + title = ptr+1; + } else { + bam_error(_("invalid option: %s\n"), opt); + return (BAM_ERROR); + } + + STAILQ_FOREACH(entry, menu, next) { + if (title != NULL) { + if (strcmp(title, entry->title) == 0) + break; + } else if (entry->entry == e) + break; + } + + if (entry == NULL) { + bam_error(_("no matching entry found\n")); + return (BAM_ERROR); + } + + return (list_menu_entry(entry, "")); +} + +/* + * For now this is just stub entry to support grub interface, the + * known consumer is installer ict.py code, calling as: + * bootadm update-menu -R /a -Z -o rdisk + * Later this can be converted to do something useful. + */ +/*ARGSUSED*/ +static error_t +update_entry(struct menu_lst *menu, char *menu_root, char *osdev) +{ + char path[PATH_MAX]; + char *pool = menu_root + 1; + be_node_list_t *be_nodes, *be_node; + int rv; + FILE *fp; + + (void) snprintf(path, PATH_MAX, "%s%s", menu_root, MENU); + rv = be_list(NULL, &be_nodes); + + if (rv != BE_SUCCESS) + return (BAM_ERROR); + + fp = fopen(path, "w"); + if (fp == NULL) { + be_free_list(be_nodes); + return (BAM_ERROR); + } + + for (be_node = be_nodes; be_node; be_node = be_node->be_next_node) { + if (strcmp(be_node->be_rpool, pool) == 0) { + (void) fprintf(fp, "title %s\n", be_node->be_node_name); + (void) fprintf(fp, "bootfs %s\n", be_node->be_root_ds); + } + } + + be_free_list(be_nodes); + (void) fclose(fp); + return (BAM_SUCCESS); +} + +/*ARGSUSED*/ +static error_t +update_temp(struct menu_lst *menu, char *dummy, char *opt) +{ + error_t ret = BAM_ERROR; + char path[PATH_MAX]; + char buf[MAX_INPUT]; + struct mnttab mpref = { 0 }; + struct mnttab mp = { 0 }; + ficlVm *vm; + char *env, *o; + FILE *fp; + + (void) snprintf(path, PATH_MAX, "%s" TRANSIENT, bam_root); + /* + * if opt == NULL, remove transient config + */ + if (opt == NULL) { + (void) unlink(path); + return (BAM_SUCCESS); + } + + fp = fopen(MNTTAB, "r"); + if (fp == NULL) + return (BAM_ERROR); + + mpref.mnt_mountp = "/"; + if (getmntany(fp, &mp, &mpref) != 0) { + (void) fclose(fp); + return (BAM_ERROR); + } + (void) fclose(fp); + + vm = bf_init("", ficlTextOutSilent); + if (vm == NULL) { + bam_error(_("Error setting up forth interpreter\n")); + return (ret); + } + + /* + * need to check current boot config, so fire up the ficl + * if its xen setup, we add option to boot-args list, not replacing it. + */ + (void) snprintf(buf, MAX_INPUT, "set currdev=zfs:%s:", mp.mnt_special); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "include /boot/forth/loader.4th"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "start"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "boot"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + bf_fini(); + + if (opt[0] == '-') { + env = getenv("xen_kernel"); + fp = fopen(path, "w"); + if (fp == NULL) + return (BAM_ERROR); + + if (env != NULL) { + env = getenv("boot-args"); + (void) fprintf(fp, "boot-args=\"%s %s\"\n", env, opt); + } else + (void) fprintf(fp, "boot-args=\"%s\"\n", opt); + (void) fclose(fp); + return (BAM_SUCCESS); + } + + /* + * it should be the case with "kernel args" + * so, we split the opt at first space + * and store bootfile= and boot-args= + */ + env = getenv("xen_kernel"); + + o = strchr(opt, ' '); + if (o == NULL) { + fp = fopen(path, "w"); + if (fp == NULL) + return (BAM_ERROR); + (void) fprintf(fp, "bootfile=\"%s\"\n", opt); + (void) fclose(fp); + return (BAM_SUCCESS); + } + *o++ = '\0'; + fp = fopen(path, "w"); + if (fp == NULL) + return (BAM_ERROR); + (void) fprintf(fp, "bootfile=\"%s\"\n", opt); + + if (env != NULL) { + env = getenv("boot-args"); + (void) fprintf(fp, "boot-args=\"%s %s\"\n", env, opt); + } else + (void) fprintf(fp, "boot-args=\"%s\"\n", o); + + (void) fflush(fp); + (void) fclose(fp); + return (ret); +} + +static error_t +list_setting(struct menu_lst *menu, char *which, char *setting) +{ + int entry = -1; + struct menu_entry *m; + be_node_list_t *be_nodes, *be_node = NULL; + int ret; + + assert(which); + assert(setting); + + /* + * which can be: + * "" - list default entry + * number - use for entry number + * property name + */ + if (*which != '\0') { + if (isdigit(*which)) { + char *rest; + errno = 0; + entry = strtol(which, &rest, 10); + if (errno != 0 || *rest != '\0') { + bam_error(_("invalid boot entry number: %s\n"), + which); + return (BAM_ERROR); + } + } else + setting = which; + } + + /* find default entry */ + if (entry == -1) { + ret = be_list(NULL, &be_nodes); + if (ret != BE_SUCCESS) { + bam_error(_("No BE's found\n")); + return (BAM_ERROR); + } + STAILQ_FOREACH(m, menu, next) { + entry++; + for (be_node = be_nodes; be_node; + be_node = be_node->be_next_node) + if (strcmp(be_node->be_root_ds, m->bootfs) == 0) + break; + if (be_node->be_active_on_boot == B_TRUE) + break; /* found active node */ + } + be_free_list(be_nodes); + if (be_node == NULL) { + bam_error(_("None of BE nodes is marked active\n")); + return (BAM_ERROR); + } + } else { + STAILQ_FOREACH(m, menu, next) + if (m->entry == entry) + break; + + if (m == NULL) { + bam_error(_("no matching entry found\n")); + return (BAM_ERROR); + } + } + + return (list_menu_entry(m, setting)); +} + +/*ARGSUSED*/ +static error_t +disable_hyper(struct menu_lst *menu, char *osroot, char *opt) +{ + char path[PATH_MAX]; + + (void) snprintf(path, PATH_MAX, "%s" XEN_CONFIG, bam_root); + (void) unlink(path); + return (BAM_SUCCESS); +} + +/*ARGSUSED*/ +static error_t +enable_hyper(struct menu_lst *menu, char *osroot, char *opt) +{ + ficlVm *vm; + char path[PATH_MAX]; + char buf[MAX_INPUT]; + char *env; + FILE *fp; + struct mnttab mpref = { 0 }; + struct mnttab mp = { 0 }; + int ret; + + fp = fopen(MNTTAB, "r"); + if (fp == NULL) + return (BAM_ERROR); + + mpref.mnt_mountp = "/"; + if (getmntany(fp, &mp, &mpref) != 0) { + (void) fclose(fp); + return (BAM_ERROR); + } + (void) fclose(fp); + + vm = bf_init("", ficlTextOutSilent); + if (vm == NULL) { + bam_error(_("Error setting up forth interpreter\n")); + return (BAM_ERROR); + } + + /* + * need to check current boot config, so fire up the ficl + * if its xen setup, we add option to boot-args list, not replacing it. + */ + (void) snprintf(buf, MAX_INPUT, "set currdev=zfs:%s:", mp.mnt_special); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "include /boot/forth/loader.4th"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "start"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + (void) snprintf(buf, MAX_INPUT, "boot"); + ret = ficlVmEvaluate(vm, buf); + if (ret != FICL_VM_STATUS_OUT_OF_TEXT) { + bam_error(_("Error interpreting boot config\n")); + bf_fini(); + return (BAM_ERROR); + } + bf_fini(); + + (void) mkdir(CONF_DIR, 0755); + (void) snprintf(path, PATH_MAX, "%s" XEN_CONFIG, bam_root); + fp = fopen(path, "w"); + if (fp == NULL) { + return (BAM_ERROR); /* error, cant write config */ + } + + errno = 0; + /* + * on write error, remove file to ensure we have bootable config. + * note we dont mind if config exists, it will get updated + */ + (void) fprintf(fp, "xen_kernel=\"/boot/${ISADIR}/xen\"\n"); + if (errno != 0) + goto error; + + /* + * really simple and stupid console conversion. + * it really has to be gone, it belongs to milestone/xvm properties. + */ + env = getenv("console"); + if (env != NULL) { + if (strcmp(env, "ttya") == 0) + (void) fprintf(fp, "xen_cmdline=\"console=com1 %s\"\n", + opt); + else if (strcmp(env, "ttyb") == 0) + (void) fprintf(fp, "xen_cmdline=\"console=com2 %s\"\n", + opt); + else + (void) fprintf(fp, "xen_cmdline=\"console=vga %s\"\n", + opt); + } else + (void) fprintf(fp, "xen_cmdline=\"%s\"\n", opt); + if (errno != 0) + goto error; + + (void) fprintf(fp, + "bootfile=\"/platform/i86xpv/kernel/${ISADIR}/unix\"\n"); + if (errno != 0) + goto error; + + (void) fprintf(fp, + "boot-args=\"/platform/i86xpv/kernel/${ISADIR}/unix\"\n"); + if (errno != 0) + goto error; + + (void) fclose(fp); + if (errno != 0) { + (void) unlink(path); + return (BAM_ERROR); + } + return (BAM_SUCCESS); +error: + (void) fclose(fp); + (void) unlink(path); + return (BAM_ERROR); +} diff --git a/usr/src/cmd/boot/bootadm/bootadm_upgrade.c b/usr/src/cmd/boot/bootadm/bootadm_upgrade.c index aafff97207..0a6b95f7ed 100644 --- a/usr/src/cmd/boot/bootadm/bootadm_upgrade.c +++ b/usr/src/cmd/boot/bootadm/bootadm_upgrade.c @@ -21,7 +21,7 @@ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. - * Copyright 2015 Toomas Soome <tsoome@me.com> + * Copyright 2016 Toomas Soome <tsoome@me.com> */ #include <stdio.h> @@ -39,7 +39,6 @@ #include <sys/elf.h> #include <sys/multiboot.h> -#include "message.h" #include "bootadm.h" direct_or_multi_t bam_direct = BAM_DIRECT_NOT_SET; @@ -63,7 +62,7 @@ get_findroot_cap(const char *osroot) if (stat(path, &sb) == -1) { bam_is_findroot = BAM_FINDROOT_ABSENT; - BAM_DPRINTF((D_FINDROOT_ABSENT, fcn)); + BAM_DPRINTF(("%s: findroot capability absent\n", fcn)); return; } @@ -71,18 +70,19 @@ get_findroot_cap(const char *osroot) error = errno; INJECT_ERROR1("GET_CAP_FINDROOT_FOPEN", fp = NULL); if (fp == NULL) { - bam_error(OPEN_FAIL, path, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), path, + strerror(error)); return; } dboot = 0; while (s_fgets(buf, sizeof (buf), fp) != NULL) { if (strcmp(buf, "findroot") == 0) { - BAM_DPRINTF((D_FINDROOT_PRESENT, fcn)); + BAM_DPRINTF(("%s: findroot capability present\n", fcn)); bam_is_findroot = BAM_FINDROOT_PRESENT; } if (strcmp(buf, "dboot") == 0) { - BAM_DPRINTF((D_DBOOT_PRESENT, fcn)); + BAM_DPRINTF(("%s: dboot capability present\n", fcn)); dboot = 1; } } @@ -91,14 +91,15 @@ get_findroot_cap(const char *osroot) if (bam_is_findroot == BAM_FINDROOT_UNKNOWN) { bam_is_findroot = BAM_FINDROOT_ABSENT; - BAM_DPRINTF((D_FINDROOT_ABSENT, fcn)); + BAM_DPRINTF(("%s: findroot capability absent\n", fcn)); } ret = fclose(fp); error = errno; INJECT_ERROR1("GET_CAP_FINDROOT_FCLOSE", ret = 1); if (ret != 0) { - bam_error(CLOSE_FAIL, path, strerror(error)); + bam_error(_("failed to close file: %s: %s\n"), + path, strerror(error)); } } @@ -118,7 +119,7 @@ get_boot_cap(const char *osroot) if (is_sparc()) { /* there is no non dboot sparc new-boot */ bam_direct = BAM_DIRECT_DBOOT; - BAM_DPRINTF((D_IS_SPARC_DBOOT, fcn)); + BAM_DPRINTF(("%s: is sparc - always DBOOT\n", fcn)); return (BAM_SUCCESS); } @@ -128,7 +129,8 @@ get_boot_cap(const char *osroot) error = errno; INJECT_ERROR1("GET_CAP_UNIX_OPEN", fd = -1); if (fd < 0) { - bam_error(OPEN_FAIL, fname, strerror(error)); + bam_error(_("failed to open file: %s: %s\n"), fname, + strerror(error)); return (BAM_ERROR); } @@ -137,7 +139,7 @@ get_boot_cap(const char *osroot) */ if (fstat(fd, &sb) == -1 || sb.st_size < 8192) { (void) close(fd); - bam_error(INVALID_BINARY, fname); + bam_error(_("invalid or corrupted binary: %s\n"), fname); return (BAM_ERROR); } @@ -148,18 +150,20 @@ get_boot_cap(const char *osroot) error = errno; INJECT_ERROR1("GET_CAP_MMAP", image = MAP_FAILED); if (image == MAP_FAILED) { - bam_error(MMAP_FAIL, fname, strerror(error)); + bam_error(_("failed to mmap file: %s: %s\n"), fname, + strerror(error)); return (BAM_ERROR); } ident = (uchar_t *)image; if (ident[EI_MAG0] != ELFMAG0 || ident[EI_MAG1] != ELFMAG1 || ident[EI_MAG2] != ELFMAG2 || ident[EI_MAG3] != ELFMAG3) { - bam_error(NOT_ELF_FILE, fname); + bam_error(_("%s is not an ELF file.\n"), fname); return (BAM_ERROR); } if (ident[EI_CLASS] != ELFCLASS32) { - bam_error(WRONG_ELF_CLASS, fname, ident[EI_CLASS]); + bam_error(_("%s is wrong ELF class 0x%x\n"), fname, + ident[EI_CLASS]); return (BAM_ERROR); } @@ -174,7 +178,7 @@ get_boot_cap(const char *osroot) for (m = 0; m < 8192 - sizeof (multiboot_header_t); m += 4) { mbh = (void *)(image + m); if (mbh->magic == MB_HEADER_MAGIC) { - BAM_DPRINTF((D_IS_DBOOT, fcn)); + BAM_DPRINTF(("%s: is DBOOT unix\n", fcn)); bam_direct = BAM_DIRECT_DBOOT; break; } @@ -185,18 +189,18 @@ get_boot_cap(const char *osroot) INJECT_ERROR1("GET_CAP_MULTIBOOT", bam_direct = BAM_DIRECT_MULTIBOOT); if (bam_direct == BAM_DIRECT_DBOOT) { if (bam_is_hv == BAM_HV_PRESENT) { - BAM_DPRINTF((D_IS_XVM, fcn)); + BAM_DPRINTF(("%s: is xVM system\n", fcn)); } else { - BAM_DPRINTF((D_IS_NOT_XVM, fcn)); + BAM_DPRINTF(("%s: is *NOT* xVM system\n", fcn)); } } else { - BAM_DPRINTF((D_IS_MULTIBOOT, fcn)); + BAM_DPRINTF(("%s: is MULTIBOOT unix\n", fcn)); } /* Not a fatal error if this fails */ get_findroot_cap(osroot); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } @@ -216,17 +220,18 @@ is_bfu_system(const char *root) const char *fcn = "is_bfu_system()"; if (is_bfu != -1) { - BAM_DPRINTF((D_ALREADY_BFU_TEST, fcn, is_bfu ? "" : "NOT")); + BAM_DPRINTF(("%s: already done bfu test. bfu is %s present\n", + fcn, is_bfu ? "" : "NOT")); return (is_bfu); } (void) snprintf(path, sizeof (path), "%s/%s", root, INST_RELEASE); if (stat(path, &sb) != 0) { is_bfu = 1; - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); } else { is_bfu = 0; - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); } return (is_bfu); } @@ -244,13 +249,13 @@ update_line(line_t *linep) size_t size; const char *fcn = "update_line()"; - BAM_DPRINTF((D_UPDATE_LINE_BEFORE, fcn, linep->line)); + BAM_DPRINTF(("%s: line before update: %s\n", fcn, linep->line)); free(linep->line); size = strlen(linep->cmd) + strlen(linep->sep) + strlen(linep->arg) + 1; linep->line = s_calloc(1, size); (void) snprintf(linep->line, size, "%s%s%s", linep->cmd, linep->sep, linep->arg); - BAM_DPRINTF((D_UPDATE_LINE_AFTER, fcn, linep->line)); + BAM_DPRINTF(("%s: line after update: %s\n", fcn, linep->line)); } static char * @@ -260,11 +265,11 @@ skip_wspace(char *ptr) INJECT_ERROR1("SKIP_WSPACE", ptr = NULL); if (ptr == NULL) { - BAM_DPRINTF((D_SKIP_WSPACE_PTR_NULL, fcn)); + BAM_DPRINTF(("%s: NULL ptr\n", fcn)); return (NULL); } - BAM_DPRINTF((D_SKIP_WSPACE_ENTRY_PTR, fcn, ptr)); + BAM_DPRINTF(("%s: ptr on entry: %s\n", fcn, ptr)); for (; *ptr != '\0'; ptr++) { if ((*ptr != ' ') && (*ptr != '\t') && (*ptr != '\n')) @@ -273,7 +278,7 @@ skip_wspace(char *ptr) ptr = (*ptr == '\0' ? NULL : ptr); - BAM_DPRINTF((D_SKIP_WSPACE_EXIT_PTR, fcn, ptr ? ptr : "NULL")); + BAM_DPRINTF(("%s: ptr on exit: %s\n", fcn, ptr ? ptr : "NULL")); return (ptr); } @@ -287,13 +292,13 @@ rskip_bspace(char *bound, char *ptr) assert(bound <= ptr); assert(*bound != ' ' && *bound != '\t' && *bound != '\n'); - BAM_DPRINTF((D_RSKIP_BSPACE_ENTRY, fcn, ptr)); + BAM_DPRINTF(("%s: ptr on entry: %s\n", fcn, ptr)); for (; ptr > bound; ptr--) { if (*ptr == ' ' || *ptr == '\t' || *ptr == '\n') break; } - BAM_DPRINTF((D_RSKIP_BSPACE_EXIT, fcn, ptr)); + BAM_DPRINTF(("%s: ptr on exit: %s\n", fcn, ptr)); return (ptr); } @@ -350,13 +355,13 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) char *flags2_ptr; const char *fcn = "cvt_kernel_line()"; - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, line->line, osroot)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, line->line, osroot)); /* * We only convert multiboot to dboot and nothing else. */ if (!(entry->flags & BAM_ENTRY_MULTIBOOT)) { - BAM_DPRINTF((D_NOT_MULTIBOOT_CONVERT, fcn)); + BAM_DPRINTF(("%s: not MULTIBOOT, not converting\n", fcn)); return (BAM_SUCCESS); } @@ -368,16 +373,19 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) * If so, just emit a message in verbose mode and * return success. */ - BAM_DPRINTF((D_TRYING_FAILSAFE_CVT_TO_DBOOT, fcn)); + BAM_DPRINTF(("%s: trying to convert failsafe to DBOOT\n", fcn)); (void) snprintf(path, PATH_MAX, "%s%s", osroot, DIRECT_BOOT_FAILSAFE_32); (void) snprintf(path_64, PATH_MAX, "%s%s", osroot, DIRECT_BOOT_FAILSAFE_64); if (stat(path, &sb) != 0 && stat(path_64, &sb_64) != 0) { if (bam_verbose) { - bam_error(FAILSAFE_MISSING, line->lineNum); + bam_error(_("bootadm -m upgrade run, but the " + "failsafe archives have not been\nupdated. " + "Not updating line %d\n"), line->lineNum); } - BAM_DPRINTF((D_NO_FAILSAFE_UNIX_CONVERT, fcn)); + BAM_DPRINTF(("%s: no FAILSAFE unix, not converting\n", + fcn)); return (BAM_SUCCESS); } } @@ -388,7 +396,7 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) free(line->cmd); line->cmd = s_strdup(menu_cmds[KERNEL_DOLLAR_CMD]); - BAM_DPRINTF((D_CVT_CMD_KERN_DOLLAR, fcn, line->cmd)); + BAM_DPRINTF(("%s: converted kernel cmd to %s\n", fcn, line->cmd)); assert(sizeof (linebuf) > strlen(line->arg) + 32); (void) strlcpy(linebuf, line->arg, sizeof (linebuf)); @@ -401,7 +409,7 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) * i.e. flags1 = unix = flags2 = NULL */ flags1_ptr = unix_ptr = flags2_ptr = NULL; - BAM_DPRINTF((D_FLAGS1_UNIX_FLAGS2_NULL, fcn)) + BAM_DPRINTF(("%s: NULL flags1, unix, flags2\n", fcn)) goto create; } @@ -414,15 +422,16 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) /* * There is a unix. */ - BAM_DPRINTF((D_UNIX_PRESENT, fcn)); + BAM_DPRINTF(("%s: unix present\n", fcn)); /* See if there's a flags2 past unix */ flags2_ptr = unix_ptr + strlen("/unix"); flags2_ptr = skip_wspace(flags2_ptr); if (flags2_ptr) { - BAM_DPRINTF((D_FLAGS2_PRESENT, fcn, flags2_ptr)); + BAM_DPRINTF(("%s: flags2 present: %s\n", fcn, + flags2_ptr)); } else { - BAM_DPRINTF((D_FLAGS2_ABSENT, fcn)); + BAM_DPRINTF(("%s: flags2 absent\n", fcn)); } /* see if there is a flags1 before unix */ @@ -430,19 +439,21 @@ cvt_kernel_line(line_t *line, const char *osroot, entry_t *entry) if (unix_ptr == old_ptr) { flags1_ptr = NULL; - BAM_DPRINTF((D_FLAGS1_ABSENT, fcn)); + BAM_DPRINTF(("%s: flags1 absent\n", fcn)); } else { flags1_ptr = old_ptr; *unix_ptr = '\0'; unix_ptr++; - BAM_DPRINTF((D_FLAGS1_PRESENT, fcn, flags1_ptr)); + BAM_DPRINTF(("%s: flags1 present: %s\n", fcn, + flags1_ptr)); } } else { /* There is no unix, there is only a bunch of flags */ flags1_ptr = old_ptr; unix_ptr = flags2_ptr = NULL; - BAM_DPRINTF((D_FLAGS1_ONLY, fcn, flags1_ptr)); + BAM_DPRINTF(("%s: flags1 present: %s, unix, flags2 absent\n", + fcn, flags1_ptr)); } /* @@ -457,7 +468,7 @@ create: (void) snprintf(new_arg, sizeof (new_arg), "%s", DIRECT_BOOT_KERNEL); } - BAM_DPRINTF((D_CVTED_UNIX, fcn, new_arg)); + BAM_DPRINTF(("%s: converted unix: %s\n", fcn, new_arg)); if (flags1_ptr != NULL) { (void) strlcat(new_arg, " ", sizeof (new_arg)); @@ -469,12 +480,12 @@ create: (void) strlcat(new_arg, flags2_ptr, sizeof (new_arg)); } - BAM_DPRINTF((D_CVTED_UNIX_AND_FLAGS, fcn, new_arg)); + BAM_DPRINTF(("%s: converted unix with flags : %s\n", fcn, new_arg)); free(line->arg); line->arg = s_strdup(new_arg); update_line(line); - BAM_DPRINTF((D_CVTED_KERNEL_LINE, fcn, line->line)); + BAM_DPRINTF(("%s: converted line is: %s\n", fcn, line->line)); return (BAM_SUCCESS); } @@ -513,25 +524,27 @@ cvt_module_line(line_t *line, entry_t *entry) { const char *fcn = "cvt_module_line()"; - BAM_DPRINTF((D_FUNC_ENTRY1, fcn, line->line)); + BAM_DPRINTF(("%s: entered. arg: %s\n", fcn, line->line)); /* * We only convert multiboot to dboot and nothing else */ if (!(entry->flags & BAM_ENTRY_MULTIBOOT)) { - BAM_DPRINTF((D_NOT_MULTIBOOT_CONVERT, fcn)); + BAM_DPRINTF(("%s: not MULTIBOOT, not converting\n", fcn)); return (BAM_SUCCESS); } if (entry->flags & BAM_ENTRY_FAILSAFE) { if (strcmp(line->arg, FAILSAFE_ARCHIVE) == 0) { - BAM_DPRINTF((D_FAILSAFE_NO_CVT_NEEDED, fcn, line->arg)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: failsafe module line needs no " + "conversion: %s\n", fcn, line->arg)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } } else if (strcmp(line->arg, MULTIBOOT_ARCHIVE) != 0) { - bam_error(UNKNOWN_MODULE_LINE, line->lineNum); - BAM_DPRINTF((D_RETURN_FAILURE, fcn)); + bam_error(_("module command on line %d not recognized.\n"), + line->lineNum); + BAM_DPRINTF(("%s: returning FAILURE\n", fcn)); return (BAM_MSG); } @@ -543,8 +556,8 @@ cvt_module_line(line_t *line, entry_t *entry) FAILSAFE_ARCHIVE : DIRECT_BOOT_ARCHIVE); update_line(line); - BAM_DPRINTF((D_CVTED_MODULE, fcn, line->line)); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: converted module line is: %s\n", fcn, line->line)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } @@ -563,7 +576,8 @@ bam_warn_hand_entries(menu_t *mp, char *osroot) * No warning needed, we are automatically converting * the "hand" entries */ - BAM_DPRINTF((D_FORCE_HAND_CVT, fcn)); + BAM_DPRINTF(("%s: force specified, no warnings about hand " + "entries\n", fcn)); return; } @@ -574,7 +588,8 @@ bam_warn_hand_entries(menu_t *mp, char *osroot) for (entry = mp->entries; entry; entry = entry->next) { if (entry->flags & (BAM_ENTRY_BOOTADM|BAM_ENTRY_LU)) continue; - BAM_DPRINTF((D_FOUND_HAND, fcn, entry->entryNum)); + BAM_DPRINTF(("%s: found hand entry #: %d\n", fcn, + entry->entryNum)); if (++hand_num > hand_max) { hand_max *= 2; hand_list = s_realloc(hand_list, @@ -583,7 +598,10 @@ bam_warn_hand_entries(menu_t *mp, char *osroot) hand_list[hand_num - 1] = entry->entryNum; } - bam_error(HAND_ADDED_ENTRIES, osroot, MENU_URL(osroot)); + bam_error(_("bootadm(1M) will only upgrade GRUB menu entries added " + "by \nbootadm(1M) or lu(1M). The following entries on %s will " + "not be upgraded.\nFor details on manually updating entries, " + "see %s\n"), osroot, MENU_URL(osroot)); bam_print_stderr("Entry Number%s: ", (hand_num > 1) ? "s" : ""); for (i = 0; i < hand_num; i++) { @@ -608,13 +626,15 @@ find_matching_entry( assert(root_opt == 0 || root_opt == 1); (void) snprintf(opt, sizeof (opt), "%d", root_opt); - BAM_DPRINTF((D_FUNC_ENTRY3, fcn, grubsign, grubroot, opt)); + BAM_DPRINTF(("%s: entered. args: %s %s %s\n", fcn, grubsign, + grubroot, opt)); for (entry = estart; entry; entry = entry->next) { if (!(entry->flags & (BAM_ENTRY_BOOTADM|BAM_ENTRY_LU)) && !bam_force) { - BAM_DPRINTF((D_SKIP_ENTRY, fcn, entry->entryNum)); + BAM_DPRINTF(("%s: skipping hand entry #: %d\n", + fcn, entry->entryNum)); continue; } @@ -622,21 +642,25 @@ find_matching_entry( for (line = entry->start; line; line = line->next) { if (line->cmd == NULL || line->arg == NULL) { if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has " + "ended\n", fcn)); break; } else { - BAM_DPRINTF((D_SKIP_NULL, fcn)); + BAM_DPRINTF(("%s: skipping " + "NULL line\n", fcn)); continue; } } if (strcmp(line->cmd, menu_cmds[ROOT_CMD]) == 0 && strcmp(line->arg, grubroot) == 0) { - BAM_DPRINTF((D_ROOT_MATCH, fcn, + BAM_DPRINTF(("%s: found matching root " + "line: %s,%s\n", fcn, line->line, grubsign)); return (entry); } if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", + fcn)); break; } } @@ -644,32 +668,37 @@ find_matching_entry( for (line = entry->start; line; line = line->next) { if (line->cmd == NULL || line->arg == NULL) { if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has " + "ended\n", fcn)); break; } else { - BAM_DPRINTF((D_SKIP_NULL, fcn)); + BAM_DPRINTF(("%s: skipping " + "NULL line\n", fcn)); continue; } } if (strcmp(line->cmd, menu_cmds[FINDROOT_CMD]) == 0 && strcmp(line->arg, grubsign) == 0) { - BAM_DPRINTF((D_FINDROOT_MATCH, fcn, + BAM_DPRINTF(("%s: found matching " + "findroot line: %s,%s\n", fcn, line->line, grubsign)); return (entry); } if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", + fcn)); break; } } } else if (root_opt) { /* Neither root nor findroot */ - BAM_DPRINTF((D_NO_ROOT_FINDROOT, fcn, entry->entryNum)); + BAM_DPRINTF(("%s: no root or findroot and root is " + "opt: %d\n", fcn, entry->entryNum)); return (entry); } } - BAM_DPRINTF((D_NO_MATCH, fcn)); + BAM_DPRINTF(("%s: no matching entry found\n", fcn)); return (NULL); } @@ -700,13 +729,14 @@ bam_add_findroot(menu_t *mp, char *grubsign, char *grubroot, int root_opt) update_num = 0; - bam_print(CVT_FINDROOT); + bam_print(_("converting entries to findroot...\n")); entry = find_matching_entry(mp->entries, grubsign, grubroot, root_opt); while (entry != NULL) { if (entry->flags & BAM_ENTRY_FINDROOT) { /* already converted */ - BAM_DPRINTF((D_ALREADY_FINDROOT, fcn, entry->entryNum)); + BAM_DPRINTF(("%s: entry %d already converted to " + "findroot\n", fcn, entry->entryNum)); entry = find_matching_entry(entry->next, grubsign, grubroot, root_opt); continue; @@ -714,10 +744,12 @@ bam_add_findroot(menu_t *mp, char *grubsign, char *grubroot, int root_opt) for (line = entry->start; line; line = line->next) { if (line->cmd == NULL || line->arg == NULL) { if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", + fcn)); break; } else { - BAM_DPRINTF((D_SKIP_NULL, fcn)); + BAM_DPRINTF(("%s: skipping NULL line\n", + fcn)); continue; } } @@ -734,17 +766,18 @@ bam_add_findroot(menu_t *mp, char *grubsign, char *grubroot, int root_opt) update_num = 1; entry->flags &= ~BAM_ENTRY_ROOT; entry->flags |= BAM_ENTRY_FINDROOT; - BAM_DPRINTF((D_ADDED_FINDROOT, fcn, - newlp->line)); + BAM_DPRINTF(("%s: added findroot line: %s\n", + fcn, newlp->line)); line = newlp; } if (strcmp(line->cmd, menu_cmds[ROOT_CMD]) == 0) { - BAM_DPRINTF((D_FREEING_ROOT, fcn, line->line)); + BAM_DPRINTF(("%s: freeing root line: %s\n", + fcn, line->line)); unlink_line(mp, line); line_free(line); } if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", fcn)); break; } } @@ -753,11 +786,11 @@ bam_add_findroot(menu_t *mp, char *grubsign, char *grubroot, int root_opt) } if (update_num) { - BAM_DPRINTF((D_UPDATED_NUMBERING, fcn)); + BAM_DPRINTF(("%s: updated numbering\n", fcn)); update_numbering(mp); } - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } @@ -767,12 +800,13 @@ bam_add_hv(menu_t *mp, char *grubsign, char *grubroot, int root_opt) entry_t *entry; const char *fcn = "bam_add_hv()"; - bam_print(CVT_HV); + bam_print(_("adding xVM entries...\n")); entry = find_matching_entry(mp->entries, grubsign, grubroot, root_opt); while (entry != NULL) { if (entry->flags & BAM_ENTRY_HV) { - BAM_DPRINTF((D_ALREADY_HV, fcn, entry->entryNum)); + BAM_DPRINTF(("%s: entry %d already converted to " + "xvm HV\n", fcn, entry->entryNum)); return (BAM_SUCCESS); } entry = find_matching_entry(entry->next, grubsign, grubroot, @@ -782,11 +816,11 @@ bam_add_hv(menu_t *mp, char *grubsign, char *grubroot, int root_opt) (void) add_boot_entry(mp, NEW_HV_ENTRY, grubsign, XEN_MENU, XEN_KERNEL_MODULE_LINE, DIRECT_BOOT_ARCHIVE, NULL); - BAM_DPRINTF((D_ADDED_XVM_ENTRY, fcn)); + BAM_DPRINTF(("%s: added xVM HV entry via add_boot_entry()\n", fcn)); update_numbering(mp); - BAM_DPRINTF((D_RETURN_SUCCESS, fcn)); + BAM_DPRINTF(("%s: returning SUCCESS\n", fcn)); return (BAM_SUCCESS); } @@ -805,17 +839,19 @@ bam_add_dboot( error_t ret; const char *fcn = "bam_add_dboot()"; - bam_print(CVT_DBOOT); + bam_print(_("converting entries to dboot...\n")); entry = find_matching_entry(mp->entries, grubsign, grubroot, root_opt); while (entry != NULL) { for (line = entry->start; line; line = line->next) { if (line->cmd == NULL || line->arg == NULL) { if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", + fcn)); break; } else { - BAM_DPRINTF((D_SKIP_NULL, fcn)); + BAM_DPRINTF(("%s: skipping NULL line\n", + fcn)); continue; } } @@ -833,11 +869,13 @@ bam_add_dboot( INJECT_ERROR1("ADD_DBOOT_KERN_MSG", ret = BAM_MSG); if (ret == BAM_ERROR) { - BAM_DPRINTF((D_CVT_KERNEL_FAIL, fcn)); + BAM_DPRINTF(("%s: cvt_kernel_line() " + "failed\n", fcn)); return (ret); } else if (ret == BAM_MSG) { msg = 1; - BAM_DPRINTF((D_CVT_KERNEL_MSG, fcn)); + BAM_DPRINTF(("%s: BAM_MSG returned " + "from cvt_kernel_line()\n", fcn)); } } if (strcmp(line->cmd, menu_cmds[MODULE_CMD]) == 0) { @@ -847,16 +885,18 @@ bam_add_dboot( INJECT_ERROR1("ADD_DBOOT_MOD_MSG", ret = BAM_MSG); if (ret == BAM_ERROR) { - BAM_DPRINTF((D_CVT_MODULE_FAIL, fcn)); + BAM_DPRINTF(("%s: cvt_module_line() " + "failed\n", fcn)); return (ret); } else if (ret == BAM_MSG) { - BAM_DPRINTF((D_CVT_MODULE_MSG, fcn)); + BAM_DPRINTF(("%s: BAM_MSG returned " + "from cvt_module_line()\n", fcn)); msg = 1; } } if (line == entry->end) { - BAM_DPRINTF((D_ENTRY_END, fcn)); + BAM_DPRINTF(("%s: entry has ended\n", fcn)); break; } } @@ -865,7 +905,7 @@ bam_add_dboot( } ret = msg ? BAM_MSG : BAM_SUCCESS; - BAM_DPRINTF((D_RETURN_RET, fcn, ret)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, ret)); return (ret); } @@ -884,7 +924,7 @@ upgrade_menu(menu_t *mp, char *osroot, char *menu_root) assert(osroot); assert(menu_root); - BAM_DPRINTF((D_FUNC_ENTRY2, fcn, osroot, menu_root)); + BAM_DPRINTF(("%s: entered. args: %s %s\n", fcn, osroot, menu_root)); /* * We only support upgrades. Xen may not be present @@ -892,7 +932,8 @@ upgrade_menu(menu_t *mp, char *osroot, char *menu_root) */ if (bam_is_findroot != BAM_FINDROOT_PRESENT || bam_direct != BAM_DIRECT_DBOOT) { - bam_error(DOWNGRADE_NOTSUP); + bam_error(_("automated downgrade of GRUB menu to older " + "version not supported.\n")); return (BAM_ERROR); } @@ -902,7 +943,8 @@ upgrade_menu(menu_t *mp, char *osroot, char *menu_root) osdev = get_special(osroot); INJECT_ERROR1("UPGRADE_OSDEV", osdev = NULL); if (osdev == NULL) { - bam_error(CANT_FIND_SPECIAL, osroot); + bam_error(_("cant find special file for mount-point %s\n"), + osroot); return (BAM_ERROR); } @@ -910,7 +952,7 @@ upgrade_menu(menu_t *mp, char *osroot, char *menu_root) INJECT_ERROR1("UPGRADE_GRUBSIGN", grubsign = NULL); if (grubsign == NULL) { free(osdev); - bam_error(CANT_FIND_GRUBSIGN, osroot); + bam_error(_("cannot find GRUB signature for %s\n"), osroot); return (BAM_ERROR); } @@ -942,18 +984,22 @@ upgrade_menu(menu_t *mp, char *osroot, char *menu_root) goto abort; if (ret1 == BAM_MSG || ret2 == BAM_MSG || ret3 == BAM_MSG) { - bam_error(CVT_TODO, MENU_URL(osroot)); + bam_error(_("one or more GRUB menu entries were not " + "automatically upgraded\nFor details on manually " + "updating entries, see %s\n"), MENU_URL(osroot)); } else { bam_warn_hand_entries(mp, osroot); } free(grubsign); - BAM_DPRINTF((D_RETURN_RET, fcn, BAM_WRITE)); + BAM_DPRINTF(("%s: returning ret = %d\n", fcn, BAM_WRITE)); return (BAM_WRITE); abort: free(grubsign); - bam_error(CVT_ABORT, osroot, MENU_URL(osroot)); + bam_error(_("error upgrading GRUB menu entries on %s. Aborting.\n" + "For details on manually updating entries, see %s\n"), osroot, + MENU_URL(osroot)); return (BAM_ERROR); } diff --git a/usr/src/cmd/boot/bootadm/message.h b/usr/src/cmd/boot/bootadm/message.h deleted file mode 100644 index 4e43b5c3da..0000000000 --- a/usr/src/cmd/boot/bootadm/message.h +++ /dev/null @@ -1,1354 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2009 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * Copyright 2015 Toomas Soome <tsoome@me.com> - */ - -#ifndef _MESSAGE_H -#define _MESSAGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <libintl.h> - -#ifndef lint -#define _(x) gettext(x) -#else -#define _(x) (x) -#endif - -#define FILE_MISS _("file not found: %s\n") - -#define ARCH_EXEC_MISS _("archive creation file not found: %s: %s\n") - -#define PATH_EXEC_OWNER _("%s is not owned by %d, skipping\n") - -#define PATH_EXEC_LINK _("%s is not a regular file, skipping\n") - -#define PATH_EXEC_PERMS _("%s is others or group writable, skipping\n") - -#define UPDATE_CACHE_OLD _("archive cache is out of sync. Rebuilding.\n") - -#define MUST_BE_ROOT _("you must be root to run this command\n") - -#define NOT_ARCHIVE_BOOT \ - _("%s: not a boot archive based Solaris instance\n") - -#define MULT_CMDS _("multiple commands specified: -%c\n") - -#define INVALID_SUBCMD _("invalid sub-command specified: %s\n") - -#define NEED_SUBCMD _("this command requires a sub-command\n") - -#define NEED_CMD _("a command option must be specified\n") - -#define DUP_OPT _("duplicate options specified: -%c\n") - -#define BAD_OPT _("invalid option or missing option argument: -%c\n") - -#define NO_OPT_REQ _("this sub-command (%s) does not take options\n") - -#define MISS_OPT _("an option is required for this sub-command: %s\n") - -#define ABS_PATH_REQ _("path is not absolute: %s\n") - -#define PATH_TOO_LONG \ - _("unable to create path on mountpoint %s, path too long\n") - -#define TOO_LONG _("the following line is too long (> %d chars)\n\t%s\n") - -#define NOT_GRUB_BOOT \ - _("not a GRUB 0.97 based Illumos instance. Operation not supported\n") - -#define NOT_GRUB_ROOT _("missing /boot/grub on root: %s\n") - -#define ALT_ROOT_INVALID \ - _("an alternate root (%s) cannot be used with this sub-command\n") - -#define NO_ENTRY _("no %s entry found\n") - -#define NO_MATCH_ENTRY _("no matching entry found\n") - -#define NO_BOOTADM_MATCH _("no matching bootadm entry found\n") - -#define NO_MEM _("could not allocate memory: size = %u\n") - -#define NO_SPARC _("%s operation unsupported on SPARC machines\n") - -#define CANNOT_LOCATE_GRUB_MENU _("cannot find GRUB menu\n") - -#define CANNOT_LOCATE_GRUB_MENU_FILE _("cannot find GRUB menu file: %s\n") - -#define GRUB_MENU_PATH _("the location for the active GRUB menu is: %s\n") - -#define STUBBOOT_DIR_NOT_FOUND _("cannot find stubboot directory\n") - -#define NO_CMD _("no command at line %d\n") - -#define DUP_CMD \ - _("duplicate command %s at line %d of %sboot/grub/menu.lst\n") - -#define NO_MENU _("menu file not found: %s\n") - -#define GLOBAL_CMD _("%s %s\n") - -#define INVALID_ENTRY _("invalid boot entry number: %s\n") - -#define INVALID_OPTION _("invalid option: %s\n") - -#define SUBOPT_MISS _("missing suboption: %s\n") - -#define NO_KERNEL _("no kernel line found in entry %d\n") - -#define EMPTY_MENU _("the GRUB menu is empty\n") - -#define UNLINK_EMPTY _("file is empty, deleting file: %s\n") - -#define UNLINK_FAIL _("failed to unlink file: %s: %s\n") - -#define NO_MATCH _("no matching entry found: %s\n") - -#define INVALID_OPT _("invalid option: %s\n") - -#define FAILED_SIG _("cannot set SIGCHLD disposition: %s\n") - -#define CANT_UNBLOCK_SIGCHLD _("cannot unblock SIGCHLD: %s\n") - -#define NO3264ELF \ - _("WARNING: file %s is neither a 32-bit nor a 64-bit ELF\n") - -#define BLOCKED_SIG _("SIGCHLD signal blocked. Cannot exec: %s\n") - -#define POPEN_FAIL _("popen failed: %s: %s\n") - -#define PCLOSE_FAIL _("pclose failed: %s: %s\n") - -#define EXEC_FAIL _("command terminated abnormally: %s: %d\n") - -#define OPEN_FAIL _("failed to open file: %s: %s\n") - -#define LOCK_FAIL _("failed to lock file: %s: %s\n") - -#define UNLOCK_FAIL _("failed to unlock file: %s: %s\n") - -#define TIMESTAMP_FAIL _("failed to update the timestamp file, next\ - archive update may experience reduced performance\n") - -#define MMAP_FAIL _("failed to mmap file: %s: %s\n") - -#define FILE_LOCKED _("another instance of bootadm (pid %lu) is running\n") - -#define NO_FLIST _("archive filelist is empty\n") - -#define CLOSE_FAIL _("failed to close file: %s: %s\n") - -#define RENAME_FAIL _("rename to file failed: %s: %s\n") - -#define NOT_IN_MNTTAB _("alternate root %s not in mnttab\n") - -#define CANT_RESOLVE _("cannot resolve path %s: %s\n") - -#define ROOT_ABS _("this sub-command doesn't take root arguments: %s\n") - -#define ARCHIVE_FAIL _("boot-archive creation FAILED, command: '%s'\n") - -#define MULTI_FAIL \ - _("Command '%s' failed while generating multisession archive\n") - -#define INFILE_FAIL _("unable to read from %s: %s\n") - -#define ARCHIVE_BAD _("archive file %s not generated correctly\n") - -#define CACHE_FAIL \ - _("Failed to gather cache files, archives generation aborted\n") - -#define BOOTBLK_FAIL _("unable to access bootblk file : %s\n") - -#define WRITE_FAIL _("write to file failed: %s: %s\n") - -#define GZ_WRITE_FAIL _("failed to write to %s\n") - -#define STAT_FAIL _("stat of file failed: %s: %s\n") - -#define PACK_FAIL _("failed to pack stat data: %s\n") - -#define NVALLOC_FAIL _("failed to create stat data: %s\n") - -#define NVADD_FAIL _("failed to update stat data for: %s: %s\n") - -#define DISKMAP_FAIL \ - _("create_diskmap command failed for OS root: %s.\n") - -#define BIOSDEV_SKIP \ - _("not using biosdev command for disk: %s.\n") - -#define CHECK_NOT_SUPPORTED \ - _("the check option is not supported with subcmd: %s\n") - -#define PARSEABLE_NEW_FILE _(" new %s\n") - -#define PARSEABLE_OUT_DATE _(" changed %s\n") - -#define PARSEABLE_STALE_FILE _(" stale %s\n") - -#define UPDATE_FORCE _("forced update of archive requested\n") - -#define NO_NEW_STAT _("cannot create new stat data\n") - -#define UPDATE_ARCH_MISS _("archive not found: %s\n") - -#define UPDATE_CDIR_MISS _("archive cache directory not found: %s\n") - -#define MULTI_SIZE \ - _("archive %s is bigger than %d bytes and will be rebuilt\n") - -#define READ_FAIL _("read failed for file: %s: %s\n") - -#define UNPACK_FAIL _("failed to unpack stat data: %s: %s\n") - -#define NFTW_FAIL _("cannot find: %s: %s\n") - -#define SIGN_FAIL _("iso descriptor signature for %s is invalid\n") - -#define STATVFS_FAIL _("statvfs failed for %s: %s\n") - -#define IS_RAMDISK _("%s is on a ramdisk device\n") - -#define PRINT _("%s\n") - -#define PRINT_TITLE _("%d %s\n") - -#define INT_ERROR _("Internal error: %s\n") - -#define CANT_FIND_USER \ - _("getpwnam: uid for %s failed, defaulting to %d\n") - -#define CANT_FIND_GROUP \ - _("getgrnam: gid for %s failed, defaulting to %d\n") - -#define CHMOD_FAIL _("chmod operation on %s failed - %s\n") - -#define CHOWN_FAIL _("chgrp operation on %s failed - %s\n") - -#define MISSING_SLICE_FILE _("GRUB slice file %s missing: %s\n") - -#define MKDIR_FAILED _("mkdir of %s failed: %s\n") - -#define MOUNT_FAILED _("mount of %s (fstype %s) failed\n") - -#define MOUNT_MNTPT_FAILED _("mount at %s failed\n") - -#define UMOUNT_FAILED _("umount of %s failed\n") - -#define CANNOT_RESTORE_GRUB_SLICE _("cannot restore GRUB slice\n") - -#define RESTORE_GRUB_FAILED _("cannot restore GRUB loader\n") - -#define MISSING_BACKUP_MENU _("no backup menu %s: %s\n") - -#define RESTORE_MENU_FAILED _("cannot restore menu %s\n") - -#define MISSING_ROOT_FILE _("file missing: %s: %s\n") - -#define BAD_ROOT_FILE _("file is invalid: %s\n") - -#define TRAILING_ARGS _("invalid trailing arguments\n") - -#define RESTORING_GRUB \ - _("No GRUB installation found. Restoring GRUB from backup\n") - -#define REBOOT_WITH_ARGS_ADD_ENTRY_FAILED \ - _("Cannot update menu. Cannot reboot with requested arguments\n") - -#define FDISK_FILES_FOUND \ - _("Deferred FDISK update file(s) found: %s, %s. Not supported.\n") - -#define UNKNOWN_KERNEL _("unable to expand %s to a full file path.\n") - -#define UNKNOWN_KERNEL_REBOOT \ - _("Rebooting with default kernel and options.\n") - -#define NOT_DBOOT \ - _("bootadm set-menu %s may only be run on directboot kernels.\n") - -#define DEFAULT_NOT_BAM _( \ -"Default /boot/grub/menu.lst entry is not controlled by bootadm. Exiting\n") - -#define CANT_FIND_DEFAULT \ -_("unable to find default boot entry (%d) in menu.lst file.\n") - -#define UNKNOWN_KERNEL_LINE \ -_("kernel command on line %d not recognized.\n") - -#define UNKNOWN_MODULE_LINE \ -_("module command on line %d not recognized.\n") - -#define FINDROOT_NOT_FOUND \ -_("findroot in default boot entry (%d) missing.\n") - -#define KERNEL_NOT_FOUND \ -_("kernel$ in default boot entry (%d) missing.\n") - -#define KERNEL_NOT_PARSEABLE \ -_("kernel$ in default boot entry (%d) missing or not parseable.\n") - -#define MODULE_NOT_PARSEABLE \ -_("module$ in default boot entry (%d) missing or not parseable.\n") - -#define NOT_ELF_FILE _("%s is not an ELF file.\n") - -#define WRONG_ELF_CLASS _("%s is wrong ELF class 0x%x\n") - -#define FAILSAFE_MISSING \ -_("bootadm -m upgrade run, but the failsafe archives have not been\n\ -updated. Not updating line %d\n") - -#define INVALID_PLAT \ - _("invalid platform %s - must be one of sun4u, sun4v or i86pc\n") - -#define FDISKPART_FAIL _("failed to determine fdisk partition: %s\n") - -#define INVALID_MHASH_KEY _("invalid key for mnttab hash: %s\n") - -#define INVALID_UFS_SIGNATURE _("invalid UFS boot signature: %s\n") - -#define SIGN_LIST_FPUTS_ERR \ - _("failed to write signature %s to signature list: %s\n") - -#define SIGNATURE_LIST_EXISTS _(" - signature list %s exists\n") - -#define OPENDIR_FAILED _("opendir of %s failed: %s\n") - -#define GRUBSIGN_SORT_FAILED _("error sorting GRUB UFS boot signatures\n") - -#define SEARCHING_UFS_SIGN _(" - searching for UFS boot signatures\n") - -#define ERR_FIND_UFS_SIGN _("search for UFS boot signatures failed\n") - -#define UFS_SIGNATURE_LIST_MISS _("missing UFS signature list file: %s\n") - -#define UFS_SIGNATURE_LIST_OPENERR \ - _("error opening UFS boot signature list file %s: %s\n") - -#define UFS_BADSIGN _("bad UFS boot signature: %s\n") - -#define GRUBSIGN_BACKUP_OPENERR \ - _("error opening boot signature backup file %s: %s\n") - -#define GRUBSIGN_BACKUP_WRITEERR \ - _("error writing boot signature backup file %s: %s\n") - -#define GRUBSIGN_BACKUP_UPDATED \ - _("updated boot signature backup file %s\n") - -#define GRUBSIGN_PRIMARY_CREATERR \ - _("error creating primary boot signature %s: %s\n") - -#define GRUBSIGN_PRIMARY_SYNCERR \ - _("error syncing primary boot signature %s: %s\n") - -#define GRUBSIGN_CREATED_PRIMARY \ - _("created primary GRUB boot signature: %s\n") - -#define GRUBSIGN_CREATE_FAIL \ - _("failed to create GRUB boot signature for device: %s\n") - -#define GRUBSIGN_WRITE_FAIL \ - _("failed to write GRUB boot signature for device: %s\n") - -#define GRUBSIGN_UFS_NONE _(" - no existing UFS boot signatures\n") - -#define GRUBSIGN_NOTSUP _("boot signature not supported for fstype: %s\n") - -#define GRUBSIGN_MKDIR_ERR \ - _("error creating boot signature directory %s: %s\n") - -#define NOT_UFS_SLICE _("%s is not a ufs slice: %s\n") - -#define FSTYP_FAILED _("fstyp failed for slice: %s\n") - -#define FSTYP_BAD _("bad output from fstyp for slice: %s\n") - -#define ZFS_MOUNT_FAILED _("mount of ZFS pool %s failed\n") - -#define ZFS_MNTPT_FAILED \ - _("failed to determine mount point of ZFS pool %s\n") - -#define NULL_ZFS_MNTPT _("ZFS pool %s has no mount-point\n") - -#define BAD_ZFS_MNTPT _("ZFS pool %s has bad mount-point %s\n") - -#define NULL_ZFS_MNTPT _("ZFS pool %s has no mount-point\n") - -#define BAD_ZFS_MNTED _("ZFS pool %s has bad mount status\n") - -#define ZFS_MNTED_FAILED \ - _("failed to determine mount status of ZFS pool %s\n") - -#define INT_BAD_MNTSTATE \ - _("Internal error: bad saved mount state for pool %s\n") - -#define FSTYP_A_FAILED _("fstyp -a on device %s failed\n") - -#define NULL_FSTYP_A _("NULL fstyp -a output for device %s\n") - -#define BAD_FSTYP_A _("bad fstyp -a output for device %s\n") - -#define INVALID_UFS_SIGN _("invalid UFS boot signature %s\n") - -#define CANT_FIND_SPECIAL _("cant find special file for mount-point %s\n") - -#define CANT_FIND_POOL _("cant find pool for mount-point %s\n") - -#define NULL_FINDROOT _("can't find argument for findroot command\n") - -#define INVALID_DEV_DSK _("not a /dev/[r]dsk name: %s\n") - -#define CVT_FINDROOT _("converting entries to findroot...\n") - -#define CVT_HV _("adding xVM entries...\n") - -#define CVT_DBOOT _("converting entries to dboot...\n") - -#define DOWNGRADE_NOTSUP \ -_("automated downgrade of GRUB menu to older version not supported.\n") - -#define CANT_FIND_GRUBSIGN _("cannot find GRUB signature for %s\n") - -#define CVT_TODO \ -_("one or more GRUB menu entries were not automatically upgraded\n\ -For details on manually updating entries, see %s\n") - -#define CVT_ABORT \ -_("error upgrading GRUB menu entries on %s. Aborting.\n\ -For details on manually updating entries, see %s\n") - -#define ALREADY_HYPER \ -_("default entry already setup for use with the hypervisor!\n") - -#define HYPER_ABORT \ -_("error converting GRUB menu entry on %s for use with the hypervisor.\n\ -Aborting.\n") - -#define ALREADY_METAL \ -_("default entry already setup for use with a metal kernel!\n") - -#define METAL_ABORT \ -_("error converting GRUB menu entry on %s for use with a metal kernel.\n\ -Aborting.\n") - -#define HAND_ADDED_ENTRIES \ -_("bootadm(1M) will only upgrade GRUB menu entries added by \n\ -bootadm(1M) or lu(1M). The following entries on %s will not be upgraded.\n\ -For details on manually updating entries, see %s\n") - -#define SIGN_FSTYPE_MISMATCH \ -_("found mismatched boot signature %s for filesystem type: %s.\n") - -#define REBOOT_FSTYPE_FAILED \ -_("failed to determine filesystem type for \"/\". Reboot with \n\ -arguments failed.\n") - -#define REBOOT_SPECIAL_FAILED \ -_("failed to find device special file for \"/\". Reboot with \n\ -arguments failed.\n") - -#define REBOOT_SIGN_FAILED \ -_("failed to find boot signature. Reboot with arguments failed.\n") - -#define REBOOT_DIRECT_FAILED \ -_("the root filesystem is not a dboot Solaris instance. \n\ -This version of bootadm is not supported on this version of Solaris.\n") - -#define BOOTENV_FSTYPE_FAILED \ -_("cannot determine filesystem type for \"/\".\n\ -Cannot generate GRUB menu entry with EEPROM arguments.\n") - -#define BOOTENV_SPECIAL_FAILED \ -_("cannot determine device special file for \"/\".\n\ -Cannot generate GRUB menu entry with EEPROM arguments.\n") - -#define BOOTENV_SIGN_FAILED \ -_("cannot determine boot signature for \"/\".\n\ -Cannot generate GRUB menu entry with EEPROM arguments.\n") - -#define GRUB_SLICE_FILE_EXISTS \ - _("unsupported GRUB slice file (%s) exists - ignoring.\n") - -#define GRUBSIGN_FOUND_OR_CREATED \ -_("found or created GRUB signature %s for %s\n") - -#define GET_FSTYPE_ARGS _("no OS mountpoint. Cannot determine fstype\n") - -#define MNTTAB_MNTPT_NOT_FOUND \ - _("failed to find OS mountpoint %s in %s\n") - -#define MNTTAB_FSTYPE_NULL _("NULL fstype found for OS root %s\n") - -#define MISSING_ARG _("missing argument for sub-command\n") - -#define INVALID_BINARY _("invalid or corrupted binary: %s\n") - -#define PCFS_ROOT_NOTSUP _("root <%s> on PCFS is not supported\n") - -#define NO_O_OSROOT _("OS root not specified with -o option: %s\n") - -#define RDONLY_FS \ - _("%s filesystem is read-only, skipping archives update\n") - -#define RDONLY_TEST_ERROR _("error during read-only test on %s: %s\n") - -#define CANNOT_GRUBROOT_BOOTDISK \ - _("cannot get (hd?,?,?) for menu. menu not on bootdisk: %s\n") - -#define NO_GRUBROOT_FOR_DISK \ - _("cannot determine BIOS disk ID 'hd?' for disk: %s\n") - -#define CACHE_MNTTAB_FAIL _("%s: failed to cache /etc/mnttab\n") - -#define FAILED_ADD_SIGNLIST _("failed to add sign %s to signlist.\n") - -#define GRUBSIGN_BACKUP_MKDIRERR _("mkdirp() of backup dir failed: %s: %s\n") - -#define GET_POOL_FAILED _("failed to get pool name from %s\n") - -#define FAIL_MNT_TOP_DATASET _("failed to mount top dataset for %s\n") - -#define PRIMARY_SIGN_EXISTS _("primary sign %s exists\n") - -#define SET_BACKUP_FAILED _("failed to set backup sign (%s) for %s: %s\n") - -#define SET_PRIMARY_FAILED \ -_("failed to set primary sign (%s) for %s: %s\n") - -#define GET_FSTYPE_FAILED _("failed to get fstype for %s\n") - -#define GET_SPECIAL_NULL_MNTPT \ - _("cannot get special file: NULL mount-point\n") - -#define GET_SPECIAL_NULL \ - _("cannot get special file for mount-point: %s\n") - -#define GET_PHYSICAL_MENU_NULL \ - _("cannot get physical device special file for menu root: %s\n") - -#define GET_GRUBSIGN_ERROR \ - _("failed to get grubsign for root: %s, device %s\n") - -#define FAILED_TO_ADD_BOOT_ENTRY \ - _("failed to add boot entry with title=%s, grub signature=%s\n") - -#define SET_DEFAULT_FAILED _("failed to set GRUB menu default to %d\n") - -#define REBOOT_GET_KERNEL_FAILED \ -_("reboot with arguments: error querying current boot-file settings\n") - -#define REBOOT_GET_ARGS_FAILED \ -_("reboot with arguments: error querying current boot-args settings\n") - -#define REBOOT_SET_DEFAULT_FAILED \ -_("reboot with arguments: setting GRUB menu default to %d failed\n") - -#define GET_SET_KERNEL_ADD_BOOT_ENTRY _("failed to add boot entry: %s\n") - -#define GET_SET_KERNEL_SET_GLOBAL _("failed to set default to: %d\n") - -#define NO_OPTION_ARG _("option has no argument: %s\n") - -#define CANT_MOUNT_POOL_DATASET \ - _("cannot mount pool dataset for pool: %s\n") - -#define ZFS_GET_POOL_FAILED _("failed to get pool for device: %s\n") - -#define ZFS_MOUNT_TOP_DATASET_FAILED \ - _("failed to mount top dataset for pool: %s\n") - -#define GET_POOL_OSDEV_NULL _("NULL device: cannot determine pool name\n") - -#define GET_POOL_BAD_OSDEV \ -_("invalid device %s: cannot determine pool name\n") - -#define POOL_SIGN_INCOMPAT \ -_("pool name %s not present in signature %s\n") - -#define INVALID_ZFS_SPECIAL \ -_("invalid device for ZFS filesystem: %s\n") - -#define CANT_FIND_POOL_FROM_SPECIAL \ -_("cannot derive ZFS pool from special: %s\n") - -#define ZFS_GET_POOL_STATUS \ -_("cannot get zpool status for pool: %s\n") - -#define BAD_ZPOOL_STATUS \ -_("bad zpool status for pool=%s\n") - -#define NO_POOL_IN_ZPOOL_STATUS \ -_("no pool name %s in zpool status\n") - -#define NO_PHYS_IN_ZPOOL_STATUS \ -_("no physical device in zpool status for pool=%s\n") - -#define UFS_GET_PHYS_NOT_SVM \ -_("not a SVM metadevice: %s. Cannot derive physical device\n") - -#define UFS_GET_PHYS_INVALID_SVM \ -_("invalid SVM metadevice name: %s. Cannot derive physical device\n") - -#define UFS_SVM_METASTAT_ERR \ -_("metastat command failed on SVM metadevice: %s\n") - -#define UFS_SVM_METASTAT_SVC_ERR \ -_("failed to start service %s for metastat command\n") - -#define BAD_UFS_SVM_METASTAT \ -_("bad output from metastat command on SVM metadevice: %s\n") - -#define INVALID_UFS_SVM_METASTAT \ -_("invalid fields in metastat output for SVM metadevice: %s\n") - -#define CANNOT_PARSE_UFS_SVM_METASTAT \ -_("cannot parse output of metastat command for metadevice: %s\n") - -#define CANNOT_PARSE_UFS_SVM_SUBMIRROR \ -_("cannot parse submirror line in metastat output for metadevice: %s\n") - -#define GET_PHYSICAL_NOTSUP_FSTYPE \ -_("cannot derive physical device for %s (%s), unsupported filesystem\n") - -#define ERROR_PARSE_UFS_SVM_METASTAT \ -_("error parsing metastat output for SVM metadevice: %s\n") - -#define GET_OSROOT_SPECIAL_ERR \ -_("failed to get special file for osroot: %s\n") - -#define GET_MENU_ROOT_SPECIAL_ERR \ -_("failed to get special file for menu_root: %s\n") - -#define GET_SVC_STATE_ERR _("failed to determine state of service: %s\n") - -#define SVC_IS_ONLINE_FAILED \ - _("failed to determine if service is online: %s\n") - -#define ENABLE_SVC_FAILED _("failed to online service: %s\n") - -#define ERR_SVC_GET_ONLINE \ - _("failed to get online status for service: %s\n") - -#define TIMEOUT_ENABLE_SVC \ - _("timed out waiting for service to online: %s\n") - -#define CANNOT_READ_LU_CKSUM \ - _("failed to read GRUB menu checksum file: %s\n") - -#define MULTIPLE_LU_CKSUM \ - _("multiple checksums for GRUB menu in checksum file: %s\n") - -#define CANNOT_PARSE_LU_CKSUM \ - _("error parsing GRUB menu checksum file: %s\n") - -#define MENU_CKSUM_FAIL \ - _("error generating checksum of GRUB menu\n") - -#define BAD_CKSUM \ - _("bad checksum generated for GRUB menu\n") - -#define BAD_CKSUM_PARSE \ - _("error parsing checksum generated for GRUB menu\n") - -#define MENU_PROP_FAIL \ - _("error propagating updated GRUB menu\n") - -#define MENU_BACKUP_FAIL \ - _("failed to create backup for GRUB menu: %s\n") - -#define BACKUP_PROP_FAIL \ - _("error propagating backup GRUB menu: %s\n") - -#define MENU_CKSUM_WRITE_FAIL \ - _("failed to write GRUB menu checksum file: %s\n") - -#define MENU_CKSUM_PROP_FAIL \ - _("error propagating GRUB menu checksum file: %s\n") - -#define BOOTADM_PROP_FAIL \ - _("error propagating bootadm: %s\n") - -#define PROP_GRUB_MENU \ - _("propagating updated GRUB menu\n") - -#define NEED_DIRPATH _("need to create directory path for %s\n") - -#define UPDT_CACHE_FAIL _("directory cache update failed for %s\n") - -#define NEW_BOOT_ENTRY \ - _("unable to modify default entry; creating new boot entry for %s\n") - -/* - * NOTE: The following are debug messages and not I18Ned - */ - -#define D_MATCHED_TITLE "%s: matched title: %s\n" - -#define D_NOMATCH_TITLE "%s: no match title: %s, %s\n" - -#define D_MATCHED_FINDROOT "%s: matched findroot: %s\n" - -#define D_NOMATCH_FINDROOT "%s: no match findroot: %s, %s\n" - -#define D_NOMATCH_FINDROOT_NULL "%s: no match line has findroot, we don't: %s\n" - -#define D_MATCHED_ROOT "%s: matched root: %s\n" - -#define D_NOMATCH_ROOT "%s: no match root: %s, %s\n" - -#define D_NOMATCH_ROOT_NULL "%s: no match, line has root, we don't: %s\n" - -#define D_NO_ROOT_OPT "%s: root NOT optional\n" - -#define D_ROOT_OPT "%s: root IS optional\n" - -#define D_KERNEL_MATCH "%s: kernel match: %s, %s\n" - -#define D_MODULE_MATCH "%s: module match: %s, %s\n" - -#define D_UPGRADE_FROM_MULTIBOOT \ - "%s: upgrading entry from dboot to multiboot: root = %s\n" - -#define D_ENTRY_NOT_FOUND_CREATING \ - "%s: boot entry not found in menu. Creating new entry, findroot = %s\n" - -#define D_CHANGING_TITLE "%s: changing title to: %s\n" - -#define D_ADDING_FINDROOT_LINE "%s: adding findroot line: %s\n" - -#define D_ADDING_KERNEL_DOLLAR "%s: adding new kernel$ line: %s\n" - -#define D_ADDING_MODULE_DOLLAR "%s: adding new module$ line: %s\n" - -#define D_GET_GRUBROOT_SUCCESS \ - "%s: get_grubroot success. osroot=%s, osdev=%s, menu_root=%s\n" - -#define D_GET_GRUBROOT_FAILURE \ - "%s: get_grubroot failed. osroot=%s, osdev=%s, menu_root=%s\n" - -#define D_UPDATED_BOOT_ENTRY \ - "%s: updated boot entry bam_zfs=%d, grubsign = %s\n" - -#define D_UPDATED_HV_ENTRY \ - "%s: updated HV entry bam_zfs=%d, grubsign = %s\n" - -#define D_UPDATED_MULTIBOOT_ENTRY \ - "%s: updated MULTIBOOT entry grubsign = %s\n" - -#define D_UPDATED_FAILSAFE_ENTRY \ - "%s: updated FAILSAFE entry failsafe_kernel = %s\n" - -#define D_GET_GRUBSIGN_SUCCESS "%s: successfully created grubsign %s\n" - -#define D_ADD_LINE_PREV_NEXT "%s: previous next exists\n" - -#define D_ADD_LINE_NOT_PREV_NEXT "%s: previous next does not exist\n" - -#define D_ADD_LINE_LAST_LINE_IN_ENTRY "%s: last line in entry\n" - -#define D_ADD_LINE_LAST_LINE_IN_MENU "%s: last line in menu\n" - -#define D_FOUND_FINDROOT "%s: found entry with matching findroot: %s\n" - -#define D_SAVING_DEFAULT_TO "%s: saving default to: %s\n" - -#define D_SAVED_DEFAULT_TO "%s: saved default to lineNum=%d, entryNum=%d\n" - -#define D_RESTORE_DEFAULT_NULL "%s: NULL saved default\n" - -#define D_RESTORE_DEFAULT_STR "%s: saved default string: %s\n" - -#define D_RESTORED_DEFAULT_TO "%s: restored default to entryNum: %d\n" - -#define D_FUNC_ENTRY0 "%s: entered. No args\n" - -#define D_FUNC_ENTRY1 "%s: entered. arg: %s\n" - -#define D_FUNC_ENTRY2 "%s: entered. args: %s %s\n" - -#define D_FUNC_ENTRY3 "%s: entered. args: %s %s %s\n" - -#define D_FUNC_ENTRY4 "%s: entered. args: %s %s %s %s\n" - -#define D_OPT_NULL "%s: opt is NULL\n" - -#define D_TRANSIENT_NOTFOUND "%s: transient entry not found\n" - -#define D_RESTORED_DEFAULT "%s: restored old default\n" - -#define D_ENTRY_EQUALS "%s: opt has entry=: %s\n" - -#define D_ENTRY_SET_IS "%s: default set to %d, set_default ret=%d\n" - -#define D_REBOOT_RESOLVED_PARTIAL "%s: resolved partial path: %s\n" - -#define D_FOUND_GLOBAL "%s: found matching global command: %s\n" - -#define D_SET_GLOBAL_WROTE_NEW "%s: wrote new global line: %s\n" - -#define D_SET_GLOBAL_REPLACED "%s: replaced global line with: %s\n" - -#define D_ARCHIVE_LINE_NONE "%s: no module/archive line for entry: %d\n" - -#define D_ARCHIVE_LINE_NOCHANGE "%s: no change for line: %s\n" - -#define D_ARCHIVE_LINE_REPLACED "%s: replaced for line: %s\n" - -#define D_GET_SET_KERNEL_NO_RC "%s: no RC entry, nothing to report\n" - -#define D_GET_SET_KERNEL_ALREADY "%s: no reset, already has default\n" - -#define D_GET_SET_KERNEL_RESTORE_DEFAULT "%s: resetting to default\n" - -#define D_GET_SET_KERNEL_RESET_KERNEL_SET_ARG \ -"%s: reset kernel to default, but retained old args: %s\n" - -#define D_GET_SET_KERNEL_RESET_ARG_SET_KERNEL \ -"%s: reset args to default, but retained old kernel: %s\n" - -#define D_GET_SET_KERNEL_REPLACED_KERNEL_SAME_ARG \ -"%s: rc line exists, replaced kernel, same args: %s\n" - -#define D_GET_SET_KERNEL_SAME_KERNEL_REPLACED_ARG \ -"%s: rc line exists, same kernel, but new args: %s\n" - -#define D_SET_OPTION "%s: setting %s option to %s\n" - -#define D_EXPAND_PATH "%s: expanded path: %s\n" - -#define D_GET_SET_KERNEL_ARGS "%s: read menu boot-args: %s\n" - -#define D_GET_SET_KERNEL_KERN "%s: read menu boot-file: %s\n" - -#define D_BAM_ROOT "%s: bam_alt_root: %d, bam_root: %s\n" - -#define D_REBOOT_OPTION "%s: reboot with args, option specified: kern=%s\n" - -#define D_REBOOT_ABSPATH "%s: reboot with args, abspath specified: kern=%s\n" - -#define D_GET_SET_KERNEL_NEW_KERN "%s: new kernel=%s\n" - -#define D_GET_SET_KERNEL_NEW_ARG "%s: new args=%s\n" - -#define D_Z_MENU_GET_POOL_FROM_SPECIAL "%s: derived pool=%s from special\n" - -#define D_Z_GET_MENU_MOUNT_TOP_DATASET "%s: top dataset mountpoint=%s\n" - -#define D_Z_GET_MENU_MENU_ROOT "%s: zfs menu_root=%s\n" - -#define D_Z_IS_LEGACY "%s: is legacy, pool=%s\n" - -#define D_Z_IS_NOT_LEGACY "%s: is *NOT* legacy, pool=%s\n" - -#define D_Z_MOUNT_TOP_NONLEG_MOUNTED_ALREADY \ - "%s: non-legacy pool %s mounted already\n" - -#define D_Z_MOUNT_TOP_NONLEG_MOUNTED_NOT_ALREADY \ - "%s: non-legacy pool %s *NOT* already mounted\n" - -#define D_Z_MOUNT_TOP_NONLEG_MOUNTED_NOW \ - "%s: non-legacy pool %s mounted now\n" - -#define D_Z_MOUNT_TOP_NONLEG_MNTPT \ - "%s: non-legacy pool %s is mounted at %s\n" - -#define D_Z_UMOUNT_TOP_ALREADY_NOP \ - "%s: pool %s was already mounted at %s, Nothing to umount\n" - -#define D_Z_UMOUNT_TOP_LEGACY \ - "%s: legacy pool %s was mounted by us, successfully unmounted\n" - -#define D_Z_UMOUNT_TOP_NONLEG \ - "%s: nonleg pool %s was mounted by us, successfully unmounted\n" - -#define D_Z_MOUNT_TOP_LEG_ALREADY \ - "%s: legacy pool %s already mounted\n" - -#define D_Z_MOUNT_TOP_LEG_MNTPT_ABS \ - "%s: legacy pool %s mount-point %s absent\n" - -#define D_Z_MOUNT_TOP_LEG_MNTPT_PRES \ - "%s: legacy pool %s mount-point %s is already present\n" - -#define D_Z_MOUNT_TOP_LEG_MOUNTED \ - "%s: legacy pool %s successfully mounted at %s\n" - -#define D_Z_MOUNT_TOP_LEG_MOUNTED \ - "%s: legacy pool %s successfully mounted at %s\n" - -#define D_GET_MOUNTPOINT_RET \ - "%s: returning mount-point for special %s: %s\n" - -#define D_IS_ZFS "%s: is a ZFS filesystem: %s\n" - -#define D_IS_NOT_ZFS "%s: is *NOT* a ZFS filesystem: %s\n" - -#define D_IS_UFS "%s: is a UFS filesystem: %s\n" - -#define D_IS_NOT_UFS "%s: is *NOT* a UFS filesystem: %s\n" - -#define D_IS_PCFS "%s: is a PCFS filesystem: %s\n" - -#define D_IS_NOT_PCFS "%s: is *NOT* a PCFS filesystem: %s\n" - -#define D_MENU_PATH "%s: menu path is: %s\n" - -#define D_FREEING_LU_SIGNS "%s: feeing LU sign: %s\n" - -#define D_OPEN_FAIL "%s: failed to open %s: %s\n" - -#define D_GET_POOL_OSDEV "%s: osdev arg = %s\n" - -#define D_GET_POOL_RET "%s: got pool. pool = %s\n" - -#define D_GET_GRUBSIGN_NO_EXISTING "%s: no existing grubsign for %s: %s\n" - -#define D_GET_PHYSICAL_ALREADY \ - "%s: got physical device already directly for menu_root=%s special=%s\n" - -#define D_GET_PHYSICAL_RET "%s: returning physical=%s\n" - -#define D_STRTOK_ZPOOL_STATUS "%s: strtok() zpool status line=%s\n" - -#define D_FOUND_POOL_IN_ZPOOL_STATUS "%s: found pool name: %s in zpool status\n" - -#define D_COUNTING_ZFS_PHYS "%s: counting phys slices in zpool status: %d\n" - -#define D_ADDING_ZFS_PHYS "%s: adding phys slice=%s from pool %s status\n" - -#define D_FUNC_ENTRY_N1 "%s: entering args: %d\n" - -#define D_UFS_SVM_SHORT "%s: short SVM name for special=%s is %s\n" - -#define D_UFS_SVM_ONE_COMP "%s: single component %s for metadevice %s\n" - -#define D_CHECK_ON_BOOTDISK "%s: checking if phys-device=%s is on bootdisk\n" - -#define D_IS_ON_BOOTDISK "%s: phys-device=%s *IS* on bootdisk\n" - -#define D_ROOT_OPT_NOT_ZFS "%s: one or more non-ZFS filesystems (%s, %s)\n" - -#define D_ROOT_OPTIONAL_OSPECIAL "%s: ospecial=%s for osroot=%s\n" - -#define D_ROOT_OPTIONAL_MSPECIAL "%s: mspecial=%s for menu_root=%s\n" - -#define D_ROOT_OPTIONAL_FIXED_OSPECIAL "%s: FIXED ospecial=%s for osroot=%s\n" - -#define D_CHECK_CMD_CMD_NOMATCH "%s: command %s does not match %s\n" - -#define D_FINDROOT_ABSENT "%s: findroot capability absent\n" - -#define D_FINDROOT_PRESENT "%s: findroot capability present\n" - -#define D_DBOOT_PRESENT "%s: dboot capability present\n" - -#define D_XVM_PRESENT "%s: xVM capability present\n" - -#define D_IS_SPARC_DBOOT "%s: is sparc - always DBOOT\n" - -#define D_IS_DBOOT "%s: is DBOOT unix\n" - -#define D_IS_MULTIBOOT "%s: is MULTIBOOT unix\n" - -#define D_IS_XVM "%s: is xVM system\n" - -#define D_IS_NOT_XVM "%s: is *NOT* xVM system\n" - -#define D_ALREADY_BFU_TEST "%s: already done bfu test. bfu is %s present\n" - -#define D_UPDATE_LINE_BEFORE "%s: line before update: %s\n" - -#define D_UPDATE_LINE_AFTER "%s: line after update: %s\n" - -#define D_SKIP_WSPACE_PTR_NULL "%s: NULL ptr\n" - -#define D_SKIP_WSPACE_ENTRY_PTR "%s: ptr on entry: %s\n" - -#define D_SKIP_WSPACE_EXIT_PTR "%s: ptr on exit: %s\n" - -#define D_RSKIP_BSPACE_ENTRY "%s: ptr on entry: %s\n" - -#define D_RSKIP_BSPACE_EXIT "%s: ptr on exit: %s\n" - -#define D_RSKIP_BSPACE_EXIT "%s: ptr on exit: %s\n" - -#define D_NOT_MULTIBOOT_CONVERT "%s: not MULTIBOOT, not converting\n" - -#define D_TRYING_FAILSAFE_CVT_TO_DBOOT \ - "%s: trying to convert failsafe to DBOOT\n" - -#define D_NO_FAILSAFE_UNIX_CONVERT "%s: no FAILSAFE unix, not converting\n" - -#define D_CVT_CMD_KERN_DOLLAR "%s: converted kernel cmd to %s\n" - -#define D_CVT_CMD_MOD_DOLLAR "%s: converted module cmd to %s\n" - -#define D_FLAGS1_UNIX_FLAGS2_NULL "%s: NULL flags1, unix, flags2\n" - -#define D_UNIX_PRESENT "%s: unix present\n" - -#define D_UNIX_PRESENT "%s: unix present\n" - -#define D_UNIX_ABSENT "%s: unix ABSENT\n" - -#define D_FLAGS2_PRESENT "%s: flags2 present: %s\n" - -#define D_FLAGS2_ABSENT "%s: flags2 absent\n" - -#define D_FLAGS1_PRESENT "%s: flags1 present: %s\n" - -#define D_FLAGS1_ABSENT "%s: flags1 absent\n" - -#define D_FLAGS1_ONLY "%s: flags1 present: %s, unix, flags2 absent\n" - -#define D_CVTED_UNIX "%s: converted unix: %s\n" - -#define D_CVTED_UNIX_AND_FLAGS "%s: converted unix with flags : %s\n" - -#define D_CVTED_KERNEL_LINE "%s: converted line is: %s\n" - -#define D_FAILSAFE_NO_CVT_NEEDED \ - "%s: failsafe module line needs no conversion: %s\n" - -#define D_CVTED_MODULE "%s: converted module line is: %s\n" - -#define D_FORCE_HAND_CVT "%s: force specified, no warnings about hand entries\n" - -#define D_FOUND_HAND "%s: found hand entry #: %d\n" - -#define D_SKIP_ENTRY "%s: skipping hand entry #: %d\n" - -#define D_SKIP_ROOT_ENTRY "%s: skipping root entry #: %d\n" - -#define D_ENTRY_END "%s: entry has ended\n" - -#define D_SKIP_NULL "%s: skipping NULL line\n" - -#define D_ROOT_MATCH "%s: found matching root line: %s,%s\n" - -#define D_FINDROOT_MATCH "%s: found matching findroot line: %s,%s\n" - -#define D_NO_ROOT_FINDROOT "%s: no root or findroot and root is opt: %d\n" - -#define D_NO_MATCH "%s: no matching entry found\n" - -#define D_ALREADY_FINDROOT "%s: entry %d already converted to findroot\n" - -#define D_ADDED_FINDROOT "%s: added findroot line: %s\n" - -#define D_ADDED_NUMBERING "%s: updating numbering\n" - -#define D_ALREADY_HV "%s: entry %d already converted to xvm HV\n" - -#define D_ADDED_XVM_ENTRY "%s: added xVM HV entry via add_boot_entry()\n" - -#define D_CVT_KERNEL_FAIL "%s: cvt_kernel_line() failed\n" - -#define D_CVT_KERNEL_MSG "%s: BAM_MSG returned from cvt_kernel_line()\n" - -#define D_CVT_MODULE_FAIL "%s: cvt_module_line() failed\n" - -#define D_CVT_MODULE_MSG "%s: BAM_MSG returned from cvt_module_line()\n" - -#define D_UPDATED_NUMBERING "%s: updated numbering\n" - -#define D_FREEING_ROOT "%s: freeing root line: %s\n" - -#define D_MENU_ROOT "%s: menu root is %s\n" - -#define D_CLEAN_MENU_ROOT "%s: cleaned menu root is <%s>\n" - -#define D_BOOT_GET_CAP_FAILED "%s: Failed to get boot capability\n" - -#define D_WRITING_MENU_ROOT "%s: writing menu to clean-menu-root: <%s>\n" - -#define D_WROTE_FILE "%s: wrote file successfully: %s\n" - -#define D_FLIST_FAIL "%s: failed to open archive filelist: %s: %s\n" - -#define D_NOT_ARCHIVE_BOOT "%s: not a boot archive based Solaris instance: %s\n" - -#define D_IS_ARCHIVE_BOOT "%s: *IS* a boot archive based Solaris instance: %s\n" - -#define D_NO_GRUB_DIR "%s: Missing GRUB directory: %s\n" - -#define D_RDONLY_FS "%s: is a READONLY filesystem: %s\n" - -#define D_RDWR_FS "%s: is a RDWR filesystem: %s\n" - -#define D_ENTRY_NEW "%s: new boot entry alloced\n" - -#define D_ENTRY_NEW_FIRST "%s: (first) new boot entry created\n" - -#define D_ENTRY_NEW_LINKED "%s: new boot entry linked in\n" - -#define D_NOT_KERNEL_CMD "%s: not a kernel command: %s\n" - -#define D_SET_DBOOT_32 "%s: setting DBOOT|DBOOT_32 flag: %s\n" - -#define D_SET_DBOOT "%s: setting DBOOT flag: %s\n" - -#define D_SET_DBOOT_64 "%s: setting DBOOT|DBOOT_64 flag: %s\n" - -#define D_SET_DBOOT_FAILSAFE "%s: setting DBOOT|DBOOT_FAILSAFE flag: %s\n" - -#define D_SET_DBOOT_FAILSAFE_32 \ - "%s: setting DBOOT|DBOOT_FAILSAFE|DBOOT_32 flag: %s\n" - -#define D_SET_DBOOT_FAILSAFE_64 \ - "%s: setting DBOOT|DBOOT_FAILSAFE|DBOOT_64 flag: %s\n" - -#define D_SET_MULTIBOOT "%s: setting MULTIBOOT flag: %s\n" - -#define D_SET_MULTIBOOT_FAILSAFE \ - "%s: setting MULTIBOOT|MULTIBOOT_FAILSAFE flag: %s\n" - -#define D_SET_HV "%s: setting XEN HV flag: %s\n" - -#define D_REC_MKDIR "%s: making recursive directory %s\n" - -#define D_SET_HAND_KERNEL "%s: is HAND kernel flag: %s\n" - -#define D_IS_UNKNOWN_KERNEL "%s: is UNKNOWN kernel entry: %s\n" - -#define D_NOT_MODULE_CMD "%s: not module cmd: %s\n" - -#define D_BOOTADM_LU_MODULE "%s: bootadm or LU module cmd: %s\n" - -#define D_IS_HAND_MODULE "%s: is HAND module: %s\n" - -#define D_IS_UNKNOWN_MODULE "%s: is UNKNOWN module: %s\n" - -#define D_IS_BOOTADM_ENTRY "%s: is bootadm(1M) entry: %s\n" - -#define D_IS_LU_ENTRY "%s: is LU entry: %s\n" - -#define D_IS_ROOT_CMD "%s: setting ROOT: %s\n" - -#define D_IS_FINDROOT_CMD "%s: setting FINDROOT: %s\n" - -#define D_CMDLINE "%s: executing: %s\n" - -#define D_IS_CHAINLOADER_CMD "%s: setting CHAINLOADER: %s\n" - -#define D_NO_BOOTENVRC "could not open %s: %s\n" - -#define D_ADD_FINDROOT_NUM "%s: findroot added: line#: %d: entry#: %d\n" - -#define D_FREEING_LINE "%s: freeing line: %d\n" - -#define D_FREEING_ENTRY "%s: freeing entry: %d\n" - -#define D_CREATED_DISKMAP "%s: created diskmap file: %s\n" - -#define D_CREATE_DISKMAP_FAIL "%s: FAILED to create diskmap file: %s\n" - -#define D_NO_SIGNDIR "%s: no sign dir: %s\n" - -#define D_EXIST_BACKUP_SIGNS \ -"%s: found backup signs: zfs=%s ufs=%s lu=%s\n" - -#define D_RETURN_SUCCESS "%s: returning SUCCESS\n" - -#define D_RETURN_FAILURE "%s: returning FAILURE\n" - -#define D_RETURN_RET "%s: returning ret = %d\n" - -#define D_EXIST_PRIMARY_SIGN "%s: existing primary sign: %s\n" - -#define D_EXIST_BACKUP_SIGN "%s: existing backup sign: %s\n" - -#define D_EXIST_PRIMARY_SIGNS \ -"%s: found primary signs: zfs=%s ufs=%s lu=%s\n" - -#define D_CHECK_UFS_EXIST_SIGN "%s: checking for existing UFS sign\n" - -#define D_CHECK_ZFS_EXIST_SIGN "%s: checking for existing ZFS sign\n" - -#define D_NO_MNTPT "%s: no mount-point for special=%s and fstype=%s\n" - -#define D_CACHE_MNTS \ -"%s: caching mount: special=%s, mntpt=%s, fstype=%s\n" - -#define D_MNTTAB_HASH_NOMATCH "%s: no match in cache for: %s\n" - -#define D_MNTTAB_HASH_MATCH "%s: *MATCH* in cache for: %s\n" - -#define D_NO_SIGN_TO_LIST "%s: no sign on %s to add to signlist\n" - -#define D_SIGN_LIST_PUTS_DONE \ -"%s: successfully added sign on %s to signlist\n" - -#define D_SLICE_ENOENT "%s: slice does not exist: %s\n" - -#define D_VTOC_SIZE_ZERO "%s: VTOC: skipping 0-length slice: %s\n" - -#define D_VTOC_NOT_ROOT_TAG "%s: VTOC: unsupported tag, skipping: %s\n" - -#define D_VTOC_ROOT_TAG "%s: VTOC: supported tag, checking: %s\n" - -#define D_VTOC_NOT_RDWR_FLAG "%s: VTOC: non-RDWR flag, skipping: %s\n" - -#define D_VTOC_RDWR_FLAG "%s: VTOC: RDWR flag, checking: %s\n" - -#define D_EFI_SIZE_ZERO "%s: EFI: skipping 0-length slice: %s\n" - -#define D_EFI_NOT_ROOT_TAG "%s: EFI: unsupported tag, skipping: %s\n" - -#define D_EFI_ROOT_TAG "%s: EFI: supported tag, checking: %s\n" - -#define D_EFI_NOT_RDWR_FLAG "%s: EFI: non-RDWR flag, skipping: %s\n" - -#define D_EFI_RDWR_FLAG "%s: EFI: RDWR flag, checking: %s\n" - -#define D_SLICE0_ENOENT "%s: slice 0 does not exist: %s\n" - -#define D_VTOC_READ_FAIL "%s: VTOC: failed to read: %s\n" - -#define D_VTOC_INVALID "%s: VTOC: is INVALID: %s\n" - -#define D_VTOC_UNKNOWN_ERR "%s: VTOC: unknown error while reading: %s\n" - -#define D_VTOC_NOTSUP "%s: VTOC: not supported: %s\n" - -#define D_VTOC_READ_SUCCESS "%s: VTOC: SUCCESS reading: %s\n" - -#define D_VTOC_UNKNOWN_RETCODE "%s: VTOC: READ: unknown return code: %s\n" - -#define D_EFI_READ_FAIL "%s: EFI: failed to read: %s\n" - -#define D_EFI_INVALID "%s: EFI: is INVALID: %s\n" - -#define D_EFI_UNKNOWN_ERR "%s: EFI: unknown error while reading: %s\n" - -#define D_EFI_NOTSUP "%s: EFI: not supported: %s\n" - -#define D_EFI_READ_SUCCESS "%s: EFI: SUCCESS reading: %s\n" - -#define D_EFI_UNKNOWN_RETCODE "%s: EFI: READ: unknown return code: %s\n" - -#define D_NOT_VTOC_OR_EFI "%s: disk has neither VTOC nor EFI: %s\n" - -#define D_SKIP_SLICE_NOTZERO "%s: skipping non-s0 slice: %s\n" - -#define D_FOUND_HOLE_SIGNLIST "%s: found hole %d in sign list.\n" - -#define D_ZERO_LEN_SIGNLIST "%s: generated zero length signlist: %s.\n" - -#define D_CREATED_ZFS_SIGN "%s: created ZFS sign: %s\n" - -#define D_CREATE_NEW_UFS "%s: created new UFS sign\n" - -#define D_CREATE_NEW_ZFS "%s: created new ZFS sign\n" - -#define D_CREATED_NEW_SIGN "%s: created new sign: %s\n" - -#define D_FOUND_IN_BACKUP "%s: found sign (%s) in backup.\n" - -#define D_NOT_FOUND_IN_EXIST_BACKUP \ - "%s: backup exists but sign %s not found\n" - -#define D_BACKUP_NOT_EXIST "%s: no backup file (%s) found.\n" - -#define D_BACKUP_DIR_NOEXIST "%s: backup dir (%s) does not exist.\n" - -#define D_SET_BACKUP_UFS "%s: setting UFS backup sign\n" - -#define D_SET_BACKUP_ZFS "%s: setting ZFS backup sign\n" - -#define D_PRIMARY_NOT_EXIST "%s: primary sign (%s) does not exist\n" - -#define D_PRIMARY_DIR_NOEXIST "%s: primary signdir (%s) does not exist\n" - -#define D_SET_PRIMARY_UFS "%s: setting UFS primary sign\n" - -#define D_SET_PRIMARY_ZFS "%s: setting ZFS primary sign\n" - -#define D_GET_TITLE "%s: got title: %s\n" - -#define D_GET_SPECIAL_NOT_IN_MNTTAB \ - "%s: Cannot get special file: mount-point %s not in mnttab\n" - -#define D_GET_SPECIAL "%s: returning special: %s\n" - -#define D_MENU_WRITE_ENTER "%s: entered menu_write() for root: <%s>\n" - -#define D_GOT_SVC_STATUS "%s: got status for service: %s\n" - -#define D_SVC_ONLINE "%s: service is online: %s\n" - -#define D_SVC_NOT_ONLINE "%s: service is *NOT* online(%s): %s\n" - -#define D_SVC_ALREADY_ONLINE "%s: service is already online: %s\n" - -#define D_SVC_ONLINE_INITIATED "%s: initiated online of service: %s\n" - -#define D_SVC_NOW_ONLINE "%s: service is NOW online: %s\n" - -#define D_NOT_LU_BE "%s: not a Live Upgrade BE\n" - -#define D_NO_CKSUM_FILE "%s: checksum file absent: %s\n" - -#define D_CKSUM_FILE_OPENED "%s: opened checksum file: %s\n" - -#define D_CKSUM_FILE_READ "%s: read checksum file: %s\n" - -#define D_CKSUM_FILE_PARSED "%s: parsed checksum file: %s\n" - -#define D_CKSUM_GEN_SUCCESS "%s: successfully generated checksum\n" - -#define D_CKSUM_GEN_OUTPUT_VALID "%s: generated checksum output valid\n" - -#define D_CKSUM_GEN_PARSED "%s: successfully parsed generated checksum\n" - -#define D_CKSUM_NO_CHANGE "%s: no change in checksum of GRUB menu\n" - -#define D_CKSUM_HAS_CHANGED "%s: checksum of GRUB menu has changed\n" - -#define D_PROPAGATED_MENU "%s: successfully propagated GRUB menu\n" - -#define D_CREATED_BACKUP "%s: successfully created backup GRUB menu: %s\n" - -#define D_PROPAGATED_BACKUP "%s: successfully propagated backup GRUB menu: %s\n" - -#define D_CREATED_CKSUM_FILE "%s: successfully created checksum file: %s\n" - -#define D_PROPAGATED_CKSUM_FILE \ - "%s: successfully propagated checksum file: %s\n" - -#define D_PROPAGATED_BOOTADM \ - "%s: successfully propagated bootadm: %s\n" - -#ifdef __cplusplus -} -#endif - -#endif /* _MESSAGE_H */ diff --git a/usr/src/cmd/boot/installboot/Makefile b/usr/src/cmd/boot/installboot/Makefile index 024e277115..83ff8e242d 100644 --- a/usr/src/cmd/boot/installboot/Makefile +++ b/usr/src/cmd/boot/installboot/Makefile @@ -18,50 +18,27 @@ # # CDDL HEADER END # -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. -# - -PROG= installboot - -EINFO_SRC= ./../common/bblk_einfo.c -UTILS_SRC =./../common/boot_utils.c -EXTRA_SRC =./../common/mboot_extra.c - -OBJS= installboot.o bblk_einfo.o boot_utils.o mboot_extra.o -SRCS= installboot.c $(UTILS_SRC) $(EINFO_SRC) $(EXTRA_SRC) - -include ../Makefile.com - -CPPFLAGS += -I$(SRC)/uts/common - -LDLIBS += -lmd5 +# Copyright 2016 Toomas Soome <tsoome@me.com> +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# -C99MODE= $(C99_ENABLE) +SUBDIRS = $(MACH) -LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN +all := TARGET= all +install := TARGET= install +clean := TARGET= clean +clobber := TARGET= clobber +_msg := TARGET= _msg +lint := TARGET= lint .KEEP_STATE: -all: $(PROG) - -$(PROG): $(OBJS) - $(LINK.c) -o $@ $(OBJS) $(LDLIBS) - $(POST_PROCESS) - -boot_utils.o: $(UTILS_SRC) - $(COMPILE.c) -o $@ $(UTILS_SRC) - -mboot_extra.o: $(EXTRA_SRC) - $(COMPILE.c) -o $@ $(EXTRA_SRC) - -bblk_einfo.o: $(EINFO_SRC) - $(COMPILE.c) -o $@ $(EINFO_SRC) - -install: all $(ROOTUSRSBINPROG) +install: $(SUBDIRS) -clean: - $(RM) $(OBJS) +all clobber clean lint _msg: $(SUBDIRS) -lint: lint_SRCS +FRC: -include ../Makefile.targ +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) diff --git a/usr/src/cmd/boot/installboot/Makefile.com b/usr/src/cmd/boot/installboot/Makefile.com new file mode 100644 index 0000000000..566e48c42a --- /dev/null +++ b/usr/src/cmd/boot/installboot/Makefile.com @@ -0,0 +1,66 @@ +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +PROG= installboot + +EINFO_SRC =../../common/bblk_einfo.c +UTILS_SRC =../../common/boot_utils.c +EXTRA_SRC =../../common/mboot_extra.c + +OBJS= installboot.o bblk_einfo.o boot_utils.o mboot_extra.o +SRCS= installboot.c $(UTILS_SRC) $(EINFO_SRC) $(EXTRA_SRC) + +include ../../Makefile.com + +CPPFLAGS += -I$(SRC)/uts/common + +LDLIBS += -lmd5 + +C99MODE= $(C99_ENABLE) + +LINTFLAGS += -erroff=E_BAD_PTR_CAST_ALIGN + +.KEEP_STATE: + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) -o $@ $(OBJS) $(LDLIBS) + $(POST_PROCESS) + +boot_utils.o: $(UTILS_SRC) + $(COMPILE.c) -o $@ $(UTILS_SRC) + +mboot_extra.o: $(EXTRA_SRC) + $(COMPILE.c) -o $@ $(EXTRA_SRC) + +bblk_einfo.o: $(EINFO_SRC) + $(COMPILE.c) -o $@ $(EINFO_SRC) + +install: all $(ROOTUSRSBINPROG) + +clean: + $(RM) $(OBJS) + +lint: lint_SRCS diff --git a/usr/src/cmd/boot/installboot/i386/Makefile b/usr/src/cmd/boot/installboot/i386/Makefile new file mode 100644 index 0000000000..5b473a6570 --- /dev/null +++ b/usr/src/cmd/boot/installboot/i386/Makefile @@ -0,0 +1,35 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +include ../Makefile.com + +OBJS += getresponse.o +SRCS += $(SRC)/common/util/getresponse.c + +CPPFLAGS += -I$(SRC)/common/util +LDLIBS += -lfdisk -lefi -lfstyp -luuid + +# getresponse.c and libfdisk.c need this +LINTFLAGS += \ + -xerroff=E_NAME_DEF_NOT_USED2 + +.KEEP_STATE: + +all: + +$(PROG): $(OBJS) + +%.o: $(SRC)/common/util/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + +include $(SRC)/cmd/boot/Makefile.targ diff --git a/usr/src/cmd/boot/installboot/i386/installboot.c b/usr/src/cmd/boot/installboot/i386/installboot.c new file mode 100644 index 0000000000..a822b46b71 --- /dev/null +++ b/usr/src/cmd/boot/installboot/i386/installboot.c @@ -0,0 +1,1597 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2012 Nexenta Systems, Inc. All rights reserved. + * Copyright 2016 Toomas Soome <tsoome@me.com> + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <assert.h> +#include <locale.h> +#include <strings.h> +#include <libfdisk.h> + +#include <sys/dktp/fdisk.h> +#include <sys/dkio.h> +#include <sys/vtoc.h> +#include <sys/multiboot.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> +#include <sys/efi_partition.h> +#include <libfstyp.h> +#include <uuid/uuid.h> + +#include "installboot.h" +#include "../../common/bblk_einfo.h" +#include "../../common/boot_utils.h" +#include "../../common/mboot_extra.h" +#include "getresponse.h" + +#ifndef TEXT_DOMAIN +#define TEXT_DOMAIN "SUNW_OST_OSCMD" +#endif + +/* + * BIOS bootblock installation: + * + * 1. MBR is first sector of the disk. If the file system on target is + * ufs or zfs, the same MBR code is installed on first sector of the + * partition as well; this will allow to have real MBR sector to be + * replaced by some other boot loader and have illumos chainloaded. + * + * installboot will record the start LBA and size of stage2 code in MBR code. + * On boot, the MBR code will read the stage2 code and executes it. + * + * 2. Stage2 location depends on file system type; + * In case of zfs, installboot will store stage2 to zfs bootblk area, + * which is 512k bytes from partition start and size is 3.5MB. + * + * In case of ufs, the stage2 location is 50 512B sectors from + * Solaris2 MBR partition start, within boot slice, boot slice size is + * one cylinder. + * + * In case of pcfs, the stage2 location is 50 512B sectors from beginning + * of the disk, filling the space between MBR and first partition. + * This location assumes no other bootloader and the space is one cylinder, + * as first partition is starting from cylinder 1. + * + * In case of GPT partitioning and if file system is not zfs, the boot + * support is only possible with dedicated boot partition. For GPT, + * the current implementation is using BOOT partition, which must exist. + * BOOT partition does only contain raw boot blocks, without any file system. + * + * Loader stage2 is created with embedded version, by using fake multiboot (MB) + * header within first 32k and EINFO block is at the end of the actual + * boot block. MB header load_addr is set to 0 and load_end_addr is set to + * actual block end, so the EINFO size is (file size - load_end_addr). + * installboot does also store the illumos boot partition LBA to MB space, + * starting from bss_end_addr structure member location; stage2 will + * detect the partition and file system based on this value. + * + * Stored location values in MBR/stage2 also mean the bootblocks must be + * reinstalled in case the partition content is relocated. + */ + +static boolean_t write_mbr = B_FALSE; +static boolean_t force_mbr = B_FALSE; +static boolean_t force_update = B_FALSE; +static boolean_t do_getinfo = B_FALSE; +static boolean_t do_version = B_FALSE; +static boolean_t do_mirror_bblk = B_FALSE; +static boolean_t strip = B_FALSE; +static boolean_t verbose_dump = B_FALSE; + +/* Versioning string, if present. */ +static char *update_str; + +/* + * Temporary buffer to store the first 32K of data looking for a multiboot + * signature. + */ +char mboot_scan[MBOOT_SCAN_SIZE]; + +/* Function prototypes. */ +static void check_options(char *); +static int get_start_sector(ib_device_t *); + +static int read_stage1_from_file(char *, ib_data_t *data); +static int read_bootblock_from_file(char *, ib_data_t *data); +static int read_bootblock_from_disk(ib_device_t *device, ib_bootblock_t *, + char **); +static void add_bootblock_einfo(ib_bootblock_t *, char *); +static int prepare_stage1(ib_data_t *); +static int prepare_bootblock(ib_data_t *, char *); +static int write_stage1(ib_data_t *); +static int write_bootblock(ib_data_t *); +static int init_device(ib_device_t *, char *); +static void cleanup_device(ib_device_t *); +static int commit_to_disk(ib_data_t *, char *); +static int handle_install(char *, char **); +static int handle_getinfo(char *, char **); +static int handle_mirror(char *, char **); +static boolean_t is_update_necessary(ib_data_t *, char *); +static int propagate_bootblock(ib_data_t *, ib_data_t *, char *); +static void usage(char *); + +static int +read_stage1_from_file(char *path, ib_data_t *dest) +{ + int fd; + + assert(dest != NULL); + + /* read the stage1 file from filesystem */ + fd = open(path, O_RDONLY); + if (fd == -1 || + read(fd, dest->stage1, SECTOR_SIZE) != SECTOR_SIZE) { + (void) fprintf(stderr, gettext("cannot read stage1 file %s\n"), + path); + return (BC_ERROR); + } + (void) close(fd); + return (BC_SUCCESS); +} + +static int +read_bootblock_from_file(char *file, ib_data_t *data) +{ + ib_bootblock_t *bblock = &data->bootblock; + struct stat sb; + uint32_t buf_size; + uint32_t mboot_off; + int fd = -1; + int retval = BC_ERROR; + + assert(data != NULL); + assert(file != NULL); + + fd = open(file, O_RDONLY); + if (fd == -1) { + BOOT_DEBUG("Error opening %s\n", file); + perror("open"); + goto out; + } + + if (fstat(fd, &sb) == -1) { + BOOT_DEBUG("Error getting information (stat) about %s", file); + perror("stat"); + goto outfd; + } + + /* loader bootblock has version built in */ + buf_size = sb.st_size; + + bblock->buf_size = buf_size; + BOOT_DEBUG("bootblock in-memory buffer size is %d\n", + bblock->buf_size); + + bblock->buf = malloc(buf_size); + if (bblock->buf == NULL) { + perror(gettext("Memory allocation failure")); + goto outbuf; + } + bblock->file = bblock->buf; + + if (read(fd, bblock->file, bblock->buf_size) != bblock->buf_size) { + BOOT_DEBUG("Read from %s failed\n", file); + perror("read"); + goto outfd; + } + + if (find_multiboot(bblock->file, MBOOT_SCAN_SIZE, &mboot_off) + != BC_SUCCESS) { + (void) fprintf(stderr, + gettext("Unable to find multiboot header\n")); + goto outfd; + } + + bblock->mboot = (multiboot_header_t *)(bblock->file + mboot_off); + bblock->mboot_off = mboot_off; + + bblock->file_size = + bblock->mboot->load_end_addr - bblock->mboot->load_addr; + BOOT_DEBUG("bootblock file size is %d\n", bblock->file_size); + + bblock->extra = bblock->buf + P2ROUNDUP(bblock->file_size, 8); + bblock->extra_size = bblock->buf_size - P2ROUNDUP(bblock->file_size, 8); + + BOOT_DEBUG("mboot at %p offset %d, extra at %p size %d, buf=%p " + "(size=%d)\n", bblock->mboot, bblock->mboot_off, bblock->extra, + bblock->extra_size, bblock->buf, bblock->buf_size); + + (void) close(fd); + return (BC_SUCCESS); + +outbuf: + (void) free(bblock->buf); + bblock->buf = NULL; +outfd: + (void) close(fd); +out: + return (retval); +} + +static int +read_bootblock_from_disk(ib_device_t *device, ib_bootblock_t *bblock, + char **path) +{ + int dev_fd; + uint32_t size, offset; + uint32_t buf_size; + uint32_t mboot_off; + multiboot_header_t *mboot; + + assert(device != NULL); + assert(bblock != NULL); + + if (device->target.fstype == IG_FS_ZFS) { + dev_fd = device->target.fd; + offset = BBLK_ZFS_BLK_OFF * SECTOR_SIZE; + *path = device->target.path; + } else { + dev_fd = device->stage.fd; + offset = device->stage.offset * SECTOR_SIZE; + *path = device->stage.path; + } + + if (read_in(dev_fd, mboot_scan, sizeof (mboot_scan), offset) + != BC_SUCCESS) { + BOOT_DEBUG("Error reading bootblock area\n"); + perror("read"); + return (BC_ERROR); + } + + /* No multiboot means no chance of knowing bootblock size */ + if (find_multiboot(mboot_scan, sizeof (mboot_scan), &mboot_off) + != BC_SUCCESS) { + BOOT_DEBUG("Unable to find multiboot header\n"); + return (BC_NOEXTRA); + } + mboot = (multiboot_header_t *)(mboot_scan + mboot_off); + + /* + * make sure mboot has sane values + */ + if (mboot->load_end_addr == 0 || + mboot->load_end_addr < mboot->load_addr) + return (BC_NOEXTRA); + + /* + * Currently, the amount of space reserved for extra information + * is "fixed". We may have to scan for the terminating extra payload + * in the future. + */ + size = mboot->load_end_addr - mboot->load_addr; + buf_size = P2ROUNDUP(size + SECTOR_SIZE, SECTOR_SIZE); + bblock->file_size = size; + + bblock->buf = malloc(buf_size); + if (bblock->buf == NULL) { + BOOT_DEBUG("Unable to allocate enough memory to read" + " the extra bootblock from the disk\n"); + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + bblock->buf_size = buf_size; + + if (read_in(dev_fd, bblock->buf, buf_size, offset) != BC_SUCCESS) { + BOOT_DEBUG("Error reading the bootblock\n"); + (void) free(bblock->buf); + bblock->buf = NULL; + return (BC_ERROR); + } + + /* Update pointers. */ + bblock->file = bblock->buf; + bblock->mboot_off = mboot_off; + bblock->mboot = (multiboot_header_t *)(bblock->buf + bblock->mboot_off); + bblock->extra = bblock->buf + P2ROUNDUP(bblock->file_size, 8); + bblock->extra_size = bblock->buf_size - P2ROUNDUP(bblock->file_size, 8); + + BOOT_DEBUG("mboot at %p offset %d, extra at %p size %d, buf=%p " + "(size=%d)\n", bblock->mboot, bblock->mboot_off, bblock->extra, + bblock->extra_size, bblock->buf, bblock->buf_size); + + return (BC_SUCCESS); +} + +static boolean_t +is_update_necessary(ib_data_t *data, char *updt_str) +{ + bblk_einfo_t *einfo; + bblk_einfo_t *einfo_file; + bblk_hs_t bblock_hs; + ib_bootblock_t bblock_disk; + ib_bootblock_t *bblock_file = &data->bootblock; + ib_device_t *device = &data->device; + int ret; + char *path; + + assert(data != NULL); + + bzero(&bblock_disk, sizeof (ib_bootblock_t)); + + ret = read_bootblock_from_disk(device, &bblock_disk, &path); + if (ret != BC_SUCCESS) { + BOOT_DEBUG("Unable to read bootblock from %s\n", path); + return (B_TRUE); + } + + einfo = find_einfo(bblock_disk.extra, bblock_disk.extra_size); + if (einfo == NULL) { + BOOT_DEBUG("No extended information available on disk\n"); + return (B_TRUE); + } + + einfo_file = find_einfo(bblock_file->extra, bblock_file->extra_size); + if (einfo_file == NULL) { + /* + * loader bootblock is versioned. missing version means + * probably incompatible block. installboot can not install + * grub, for example. + */ + (void) fprintf(stderr, + gettext("ERROR: non versioned bootblock in file\n")); + return (B_FALSE); + } else { + if (updt_str == NULL) { + updt_str = einfo_get_string(einfo_file); + do_version = B_TRUE; + } + } + + if (!do_version || updt_str == NULL) { + (void) fprintf(stderr, + gettext("WARNING: target device %s has a " + "versioned bootblock that is going to be overwritten by a " + "non versioned one\n"), device->path); + return (B_TRUE); + } + + if (force_update) { + BOOT_DEBUG("Forcing update of %s bootblock\n", device->path); + return (B_TRUE); + } + + BOOT_DEBUG("Ready to check installed version vs %s\n", updt_str); + + bblock_hs.src_buf = (unsigned char *)bblock_file->file; + bblock_hs.src_size = bblock_file->file_size; + + return (einfo_should_update(einfo, &bblock_hs, updt_str)); +} + +static void +add_bootblock_einfo(ib_bootblock_t *bblock, char *updt_str) +{ + bblk_hs_t hs; + uint32_t avail_space; + + assert(bblock != NULL); + + if (updt_str == NULL) { + BOOT_DEBUG("WARNING: no update string passed to " + "add_bootblock_einfo()\n"); + return; + } + + /* Fill bootblock hashing source information. */ + hs.src_buf = (unsigned char *)bblock->file; + hs.src_size = bblock->file_size; + /* How much space for the extended information structure? */ + avail_space = bblock->buf_size - P2ROUNDUP(bblock->file_size, 8); + /* Place the extended information structure. */ + add_einfo(bblock->extra, updt_str, &hs, avail_space); +} + +/* + * set up data for case stage1 is installed as MBR + * set up location and size of bootblock + * set disk guid to provide unique information for biosdev command + */ +static int +prepare_stage1(ib_data_t *data) +{ + ib_device_t *device; + + assert(data != NULL); + device = &data->device; + + /* copy BPB */ + bcopy(device->mbr + STAGE1_BPB_OFFSET, + data->stage1 + STAGE1_BPB_OFFSET, STAGE1_BPB_SIZE); + + + /* copy MBR, note STAGE1_SIG == BOOTSZ */ + bcopy(device->mbr + STAGE1_SIG, data->stage1 + STAGE1_SIG, + SECTOR_SIZE - STAGE1_SIG); + + /* set stage2 size */ + *((uint16_t *)(data->stage1 + STAGE1_STAGE2_SIZE)) = + (uint16_t)(data->bootblock.buf_size / SECTOR_SIZE); + + /* + * set stage2 location. + * for zfs always use zfs embedding, for ufs/pcfs use partition_start + * as base for stage2 location, for ufs/pcfs in MBR partition, use + * free space after MBR record. + */ + if (device->target.fstype == IG_FS_ZFS) + *((uint64_t *)(data->stage1 + STAGE1_STAGE2_LBA)) = + device->target.start + device->target.offset; + else { + *((uint64_t *)(data->stage1 + STAGE1_STAGE2_LBA)) = + device->stage.start + device->stage.offset; + } + + /* + * set disk uuid. we only need reasonable amount of uniqueness + * to allow biosdev to identify disk based on mbr differences. + */ + uuid_generate(data->stage1 + STAGE1_STAGE2_UUID); + + return (BC_SUCCESS); +} + +static int +prepare_bootblock(ib_data_t *data, char *updt_str) +{ + ib_bootblock_t *bblock; + ib_device_t *device; + uint64_t *ptr; + + assert(data != NULL); + + bblock = &data->bootblock; + device = &data->device; + + ptr = (uint64_t *)(&bblock->mboot->bss_end_addr); + *ptr = device->target.start; + + /* + * the loader bootblock has built in version, if custom + * version was provided, update it. + */ + if (do_version) + add_bootblock_einfo(bblock, updt_str); + + return (BC_SUCCESS); +} + +static int +write_bootblock(ib_data_t *data) +{ + ib_device_t *device = &data->device; + ib_bootblock_t *bblock = &data->bootblock; + uint64_t abs; + int dev_fd, ret; + off_t offset; + char *path; + + assert(data != NULL); + + /* + * ZFS bootblock area is 3.5MB, make sure we can fit. + * buf_size is size of bootblk+EINFO. + */ + if (bblock->buf_size > BBLK_ZFS_BLK_SIZE) { + (void) fprintf(stderr, gettext("bootblock is too large\n")); + return (BC_ERROR); + } + + if (device->target.fstype == IG_FS_ZFS) { + dev_fd = device->target.fd; + abs = device->target.start + device->target.offset; + offset = BBLK_ZFS_BLK_OFF * SECTOR_SIZE; + path = device->target.path; + } else { + dev_fd = device->stage.fd; + abs = device->stage.start + device->stage.offset; + offset = device->stage.offset * SECTOR_SIZE; + path = device->stage.path; + if (bblock->buf_size > + (device->stage.size - device->stage.offset) * SECTOR_SIZE) { + (void) fprintf(stderr, gettext("Device %s is " + "too small to fit the stage2\n"), path); + return (BC_ERROR); + } + } + ret = write_out(dev_fd, bblock->buf, bblock->buf_size, offset); + if (ret != BC_SUCCESS) { + BOOT_DEBUG("Error writing the ZFS bootblock " + "to %s at offset %d\n", path, offset); + return (BC_ERROR); + } + + (void) fprintf(stdout, gettext("bootblock written for %s," + " %d sectors starting at %d (abs %lld)\n"), path, + (bblock->buf_size / SECTOR_SIZE) + 1, offset / SECTOR_SIZE, abs); + + return (BC_SUCCESS); +} + +static int +write_stage1(ib_data_t *data) +{ + ib_device_t *device = &data->device; + + assert(data != NULL); + + /* + * Partition boot block or volume boot record. + * This is essentially copy of MBR (1 sector) and we store it + * to support multi boot setups. + * + * Not all combinations are supported; as pcfs does not leave + * space, we will not write to pcfs target. + * In addition, in VTOC setup, we will only write VBR to slice 2. + */ + if (device->stage.start != 0 && + strcmp(device->target.path, device->stage.path)) { + /* we got separate stage area, use it */ + if (write_out(device->stage.fd, data->stage1, + sizeof (data->stage1), 0) != BC_SUCCESS) { + (void) fprintf(stdout, gettext("cannot write " + "partition boot sector\n")); + perror("write"); + return (BC_ERROR); + } + + (void) fprintf(stdout, gettext("stage1 written to " + "%s %d sector 0 (abs %d)\n"), + device->devtype == IG_DEV_MBR? "partition":"slice", + device->stage.id, device->stage.start); + } + + /* + * both ufs and zfs have initial 8k reserved for VTOC/boot + * so its safe to use this area. however, only + * write to target if we have MBR/GPT. + */ + if (device->devtype != IG_DEV_VTOC && + device->target.fstype != IG_FS_PCFS) { + if (write_out(device->target.fd, data->stage1, + sizeof (data->stage1), 0) != BC_SUCCESS) { + (void) fprintf(stdout, gettext("cannot write " + "partition boot sector\n")); + perror("write"); + return (BC_ERROR); + } + + (void) fprintf(stdout, gettext("stage1 written to " + "%s %d sector 0 (abs %d)\n"), + device->devtype == IG_DEV_MBR? "partition":"slice", + device->target.id, device->target.start); + } + + if (write_mbr) { + if (write_out(device->fd, data->stage1, + sizeof (data->stage1), 0) != BC_SUCCESS) { + (void) fprintf(stdout, + gettext("cannot write master boot sector\n")); + perror("write"); + return (BC_ERROR); + } + (void) fprintf(stdout, + gettext("stage1 written to master boot sector\n")); + } + + return (BC_SUCCESS); +} + +/* + * find partition/slice start sector. will be recorded in stage2 and used + * by stage2 to identify partition with boot file system. + */ +static int +get_start_sector(ib_device_t *device) +{ + uint32_t secnum = 0, numsec = 0; + int i, pno, rval, log_part = 0; + struct mboot *mboot; + struct ipart *part = NULL; + ext_part_t *epp; + struct part_info dkpi; + struct extpart_info edkpi; + + if (device->devtype == IG_DEV_EFI) { + struct dk_gpt *vtoc; + + if (efi_alloc_and_read(device->fd, &vtoc) < 0) + return (BC_ERROR); + + if (device->stage.start == 0) { + /* zero size means the fstype must be zfs */ + assert(device->target.fstype == IG_FS_ZFS); + + device->stage.start = + vtoc->efi_parts[device->stage.id].p_start; + device->stage.size = + vtoc->efi_parts[device->stage.id].p_size; + device->stage.offset = BBLK_ZFS_BLK_OFF; + device->target.offset = BBLK_ZFS_BLK_OFF; + } + + device->target.start = + vtoc->efi_parts[device->target.id].p_start; + device->target.size = + vtoc->efi_parts[device->target.id].p_size; + + /* with pcfs we always write MBR */ + if (device->target.fstype == IG_FS_PCFS) { + force_mbr = 1; + write_mbr = 1; + } + + efi_free(vtoc); + goto found_part; + } + + mboot = (struct mboot *)device->mbr; + + /* For MBR we have device->stage filled already. */ + if (device->devtype == IG_DEV_MBR) { + /* MBR partition starts from 0 */ + pno = device->target.id - 1; + part = (struct ipart *)mboot->parts + pno; + + if (part->relsect == 0) { + (void) fprintf(stderr, gettext("Partition %d of the " + "disk has an incorrect offset\n"), + device->target.id); + return (BC_ERROR); + } + device->target.start = part->relsect; + device->target.size = part->numsect; + + /* with pcfs we always write MBR */ + if (device->target.fstype == IG_FS_PCFS) { + force_mbr = 1; + write_mbr = 1; + } + if (device->target.fstype == IG_FS_ZFS) + device->target.offset = BBLK_ZFS_BLK_OFF; + + goto found_part; + } + + /* + * Search for Solaris fdisk partition + * Get the solaris partition information from the device + * and compare the offset of S2 with offset of solaris partition + * from fdisk partition table. + */ + if (ioctl(device->target.fd, DKIOCEXTPARTINFO, &edkpi) < 0) { + if (ioctl(device->target.fd, DKIOCPARTINFO, &dkpi) < 0) { + (void) fprintf(stderr, gettext("cannot get the " + "slice information of the disk\n")); + return (BC_ERROR); + } else { + edkpi.p_start = dkpi.p_start; + edkpi.p_length = dkpi.p_length; + } + } + + device->target.start = edkpi.p_start; + device->target.size = edkpi.p_length; + if (device->target.fstype == IG_FS_ZFS) + device->target.offset = BBLK_ZFS_BLK_OFF; + + for (i = 0; i < FD_NUMPART; i++) { + part = (struct ipart *)mboot->parts + i; + + if (part->relsect == 0) { + (void) fprintf(stderr, gettext("Partition %d of the " + "disk has an incorrect offset\n"), i+1); + return (BC_ERROR); + } + + if (edkpi.p_start >= part->relsect && + edkpi.p_start < (part->relsect + part->numsect)) { + /* Found the partition */ + break; + } + } + + if (i == FD_NUMPART) { + /* No solaris fdisk partitions (primary or logical) */ + (void) fprintf(stderr, gettext("Solaris partition not found. " + "Aborting operation.\n")); + return (BC_ERROR); + } + + /* + * We have found a Solaris fdisk partition (primary or extended) + * Handle the simple case first: Solaris in a primary partition + */ + if (!fdisk_is_dos_extended(part->systid)) { + device->stage.start = part->relsect; + device->stage.size = part->numsect; + if (device->target.fstype == IG_FS_ZFS) + device->stage.offset = BBLK_ZFS_BLK_OFF; + else + device->stage.offset = BBLK_BLKLIST_OFF; + device->stage.id = i + 1; + goto found_part; + } + + /* + * Solaris in a logical partition. Find that partition in the + * extended part. + */ + + if ((rval = libfdisk_init(&epp, device->path, NULL, FDISK_READ_DISK)) + != FDISK_SUCCESS) { + switch (rval) { + /* + * The first 3 cases are not an error per-se, just that + * there is no Solaris logical partition + */ + case FDISK_EBADLOGDRIVE: + case FDISK_ENOLOGDRIVE: + case FDISK_EBADMAGIC: + (void) fprintf(stderr, gettext("Solaris " + "partition not found. " + "Aborting operation.\n")); + return (BC_ERROR); + case FDISK_ENOVGEOM: + (void) fprintf(stderr, gettext("Could not get " + "virtual geometry\n")); + return (BC_ERROR); + case FDISK_ENOPGEOM: + (void) fprintf(stderr, gettext("Could not get " + "physical geometry\n")); + return (BC_ERROR); + case FDISK_ENOLGEOM: + (void) fprintf(stderr, gettext("Could not get " + "label geometry\n")); + return (BC_ERROR); + default: + (void) fprintf(stderr, gettext("Failed to " + "initialize libfdisk.\n")); + return (BC_ERROR); + } + } + + rval = fdisk_get_solaris_part(epp, &pno, &secnum, &numsec); + libfdisk_fini(&epp); + if (rval != FDISK_SUCCESS) { + /* No solaris logical partition */ + (void) fprintf(stderr, gettext("Solaris partition not found. " + "Aborting operation.\n")); + return (BC_ERROR); + } + + device->stage.start = secnum; + device->stage.size = numsec; + device->stage.id = pno; + log_part = 1; + +found_part: + /* get confirmation for -m */ + if (write_mbr && !force_mbr) { + (void) fprintf(stdout, gettext("Updating master boot sector " + "destroys existing boot managers (if any).\n" + "continue (y/n)? ")); + if (!yes()) { + write_mbr = 0; + (void) fprintf(stdout, gettext("master boot sector " + "not updated\n")); + return (BC_ERROR); + } + } + + /* + * warn, if illumos in primary partition and loader not in MBR and + * partition is not active + */ + if (device->devtype != IG_DEV_EFI) { + if (!log_part && part->bootid != 128 && !write_mbr) { + (void) fprintf(stdout, gettext("Solaris fdisk " + "partition is inactive.\n"), device->stage.id); + } + } + + return (BC_SUCCESS); +} + +static int +open_device(char *path) +{ + struct stat statbuf = {0}; + int fd = -1; + + if (nowrite) + fd = open(path, O_RDONLY); + else + fd = open(path, O_RDWR); + + if (fd == -1) { + BOOT_DEBUG("Unable to open %s\n", path); + perror("open"); + return (-1); + } + + if (fstat(fd, &statbuf) != 0) { + BOOT_DEBUG("Unable to stat %s\n", path); + perror("stat"); + (void) close(fd); + return (-1); + } + + if (S_ISCHR(statbuf.st_mode) == 0) { + (void) fprintf(stderr, gettext("%s: Not a character device\n"), + path); + (void) close(fd); + return (-1); + } + + return (fd); +} + +static int +get_boot_partition(ib_device_t *device, struct mboot *mbr) +{ + struct ipart *part; + char *path, *ptr; + int i; + + part = (struct ipart *)mbr->parts; + for (i = 0; i < FD_NUMPART; i++) { + if (part[i].systid == X86BOOT) + break; + } + + /* no X86BOOT, try to use space between MBR and first partition */ + if (i == FD_NUMPART) { + device->stage.path = strdup(device->path); + if (device->stage.path == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + device->stage.fd = dup(device->fd); + device->stage.id = 0; + device->stage.devtype = IG_DEV_MBR; + device->stage.fstype = IG_FS_NONE; + device->stage.start = 0; + device->stage.size = part[0].relsect; + device->stage.offset = BBLK_BLKLIST_OFF; + return (BC_SUCCESS); + } + + if ((path = strdup(device->path)) == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + + ptr = strrchr(path, 'p'); + ptr++; + *ptr = '\0'; + (void) asprintf(&ptr, "%s%d", path, i+1); /* partitions are p1..p4 */ + free(path); + if (ptr == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + device->stage.path = ptr; + device->stage.fd = open_device(ptr); + device->stage.id = i + 1; + device->stage.devtype = IG_DEV_MBR; + device->stage.fstype = IG_FS_NONE; + device->stage.start = part[i].relsect; + device->stage.size = part[i].numsect; + device->stage.offset = 1; /* leave sector 0 for VBR */ + return (BC_SUCCESS); +} + +static int +get_boot_slice(ib_device_t *device, struct dk_gpt *vtoc) +{ + uint_t i; + char *path, *ptr; + + for (i = 0; i < vtoc->efi_nparts; i++) { + if (vtoc->efi_parts[i].p_tag == V_BOOT) { + if ((path = strdup(device->target.path)) == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + ptr = strrchr(path, 's'); + ptr++; + *ptr = '\0'; + (void) asprintf(&ptr, "%s%d", path, i); + free(path); + if (ptr == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + device->stage.path = ptr; + device->stage.fd = open_device(ptr); + device->stage.id = i; + device->stage.devtype = IG_DEV_EFI; + device->stage.fstype = IG_FS_NONE; + device->stage.start = vtoc->efi_parts[i].p_start; + device->stage.size = vtoc->efi_parts[i].p_size; + device->stage.offset = 1; /* leave sector 0 for VBR */ + return (BC_SUCCESS); + } + } + return (BC_SUCCESS); +} + +static int +init_device(ib_device_t *device, char *path) +{ + struct dk_gpt *vtoc; + fstyp_handle_t fhdl; + const char *fident; + char *p; + int pathlen = strlen(path); + int ret; + + bzero(device, sizeof (*device)); + device->fd = -1; /* whole disk fd */ + device->stage.fd = -1; /* bootblock partition fd */ + device->target.fd = -1; /* target fs partition fd */ + + /* basic check, whole disk is not allowed */ + if ((p = strrchr(path, '/')) == NULL) + p = path; + if ((strrchr(p, 'p') == NULL && strrchr(p, 's') == NULL) || + (path[pathlen-2] == 'p' && path[pathlen-1] == '0')) { + (void) fprintf(stderr, gettext("installing loader to " + "whole disk device is not supported\n")); + } + + device->target.path = strdup(path); + if (device->target.path == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + device->path = strdup(path); + if (device->path == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + + /* change device name to p0 */ + device->path[pathlen - 2] = 'p'; + device->path[pathlen - 1] = '0'; + + if (strstr(device->target.path, "diskette")) { + (void) fprintf(stderr, gettext("installing loader to a floppy " + "disk is not supported\n")); + return (BC_ERROR); + } + + /* Detect if the target device is a pcfs partition. */ + if (strstr(device->target.path, "p0:boot")) { + (void) fprintf(stderr, gettext("installing loader to x86 boot " + "partition is not supported\n")); + return (BC_ERROR); + } + + if ((device->fd = open_device(device->path)) == -1) + return (BC_ERROR); + + /* read in the device boot sector. */ + if (read(device->fd, device->mbr, SECTOR_SIZE) != SECTOR_SIZE) { + (void) fprintf(stderr, gettext("Error reading boot sector\n")); + perror("read"); + return (BC_ERROR); + } + + device->devtype = IG_DEV_VTOC; + if (efi_alloc_and_read(device->fd, &vtoc) >= 0) { + ret = get_boot_slice(device, vtoc); + device->devtype = IG_DEV_EFI; + efi_free(vtoc); + if (ret == BC_ERROR) + return (BC_ERROR); + } else if (device->target.path[pathlen - 2] == 'p') { + device->devtype = IG_DEV_MBR; + ret = get_boot_partition(device, (struct mboot *)device->mbr); + if (ret == BC_ERROR) + return (BC_ERROR); + } else if (device->target.path[pathlen - 1] == '2') { + /* + * NOTE: we could relax there and allow zfs boot on + * slice 2 for instance, but lets keep traditional limits. + */ + (void) fprintf(stderr, + gettext("raw device must be a root slice (not s2)\n")); + return (BC_ERROR); + } + + /* fill stage partition for case there is no boot partition */ + if (device->stage.path == NULL) { + if ((device->stage.path = strdup(path)) == NULL) { + perror(gettext("Memory allocation failure")); + return (BC_ERROR); + } + if (device->devtype == IG_DEV_VTOC) { + /* use slice 2 */ + device->stage.path[pathlen - 2] = 's'; + device->stage.path[pathlen - 1] = '2'; + device->stage.id = 2; + } else { + p = strrchr(device->stage.path, 'p'); + if (p == NULL) + p = strrchr(device->stage.path, 's'); + device->stage.id = atoi(++p); + } + device->stage.devtype = device->devtype; + device->stage.fd = open_device(device->stage.path); + } + + p = strrchr(device->target.path, 'p'); + if (p == NULL) + p = strrchr(device->target.path, 's'); + device->target.id = atoi(++p); + + if (strcmp(device->stage.path, device->target.path) == 0) + device->target.fd = dup(device->stage.fd); + else + device->target.fd = open_device(device->target.path); + + if (fstyp_init(device->target.fd, 0, NULL, &fhdl) != 0) + return (BC_ERROR); + + if (fstyp_ident(fhdl, NULL, &fident) != 0) { + fstyp_fini(fhdl); + (void) fprintf(stderr, gettext("Failed to detect file " + "system type\n")); + return (BC_ERROR); + } + + /* at this moment non-boot partition has no size set, use this fact */ + if (device->devtype == IG_DEV_EFI && strcmp(fident, "zfs") && + device->stage.size == 0) { + fstyp_fini(fhdl); + (void) fprintf(stderr, gettext("Booting %s of EFI labeled " + "disks requires the boot partition.\n"), fident); + return (BC_ERROR); + } + if (strcmp(fident, "zfs") == 0) + device->target.fstype = IG_FS_ZFS; + else if (strcmp(fident, "ufs") == 0) { + device->target.fstype = IG_FS_UFS; + } else if (strcmp(fident, "pcfs") == 0) { + device->target.fstype = IG_FS_PCFS; + } else { + (void) fprintf(stderr, gettext("File system %s is not " + "supported by loader\n"), fident); + fstyp_fini(fhdl); + return (BC_ERROR); + } + fstyp_fini(fhdl); + + /* check for boot partition content */ + if (device->stage.size) { + if (fstyp_init(device->stage.fd, 0, NULL, &fhdl) != 0) + return (BC_ERROR); + + if (fstyp_ident(fhdl, NULL, &fident) == 0) { + (void) fprintf(stderr, gettext("Unexpected %s file " + "system on boot partition\n"), fident); + fstyp_fini(fhdl); + return (BC_ERROR); + } + fstyp_fini(fhdl); + } + return (get_start_sector(device)); +} + +static void +cleanup_device(ib_device_t *device) +{ + if (device->path) + free(device->path); + if (device->stage.path) + free(device->stage.path); + if (device->target.path) + free(device->target.path); + + if (device->fd != -1) + (void) close(device->fd); + if (device->stage.fd != -1) + (void) close(device->stage.fd); + if (device->target.fd != -1) + (void) close(device->target.fd); + bzero(device, sizeof (*device)); +} + +static void +cleanup_bootblock(ib_bootblock_t *bblock) +{ + free(bblock->buf); + bzero(bblock, sizeof (ib_bootblock_t)); +} + +/* + * Propagate the bootblock on the source disk to the destination disk and + * version it with 'updt_str' in the process. Since we cannot trust any data + * on the attaching disk, we do not perform any specific check on a potential + * target extended information structure and we just blindly update. + */ +static int +propagate_bootblock(ib_data_t *src, ib_data_t *dest, char *updt_str) +{ + ib_bootblock_t *src_bblock = &src->bootblock; + ib_bootblock_t *dest_bblock = &dest->bootblock; + + assert(src != NULL); + assert(dest != NULL); + + /* read the stage1 file from source disk */ + if (read(src->device.fd, dest->stage1, SECTOR_SIZE) != SECTOR_SIZE) { + (void) fprintf(stderr, gettext("cannot read stage1 from %s\n"), + src->device.path); + return (BC_ERROR); + } + + cleanup_bootblock(dest_bblock); + + dest_bblock->buf_size = src_bblock->buf_size; + dest_bblock->buf = malloc(dest_bblock->buf_size); + if (dest_bblock->buf == NULL) { + perror(gettext("Memory Allocation Failure")); + return (BC_ERROR); + } + dest_bblock->file = dest_bblock->buf; + dest_bblock->file_size = src_bblock->file_size; + (void) memcpy(dest_bblock->buf, src_bblock->buf, + dest_bblock->buf_size); + + dest_bblock->mboot = (multiboot_header_t *)(dest_bblock->file + + src_bblock->mboot_off); + dest_bblock->mboot_off = src_bblock->mboot_off; + dest_bblock->extra = (char *)dest_bblock->file + + P2ROUNDUP(dest_bblock->file_size, 8); + dest_bblock->extra_size = src_bblock->extra_size; + + (void) fprintf(stdout, gettext("Propagating %s bootblock to %s\n"), + src->device.path, dest->device.path); + + return (commit_to_disk(dest, updt_str)); +} + +static int +commit_to_disk(ib_data_t *data, char *update_str) +{ + assert(data != NULL); + + if (prepare_bootblock(data, update_str) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Error updating the bootblock " + "image\n")); + return (BC_ERROR); + } + + if (prepare_stage1(data) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Error updating the stage1 " + "image\n")); + return (BC_ERROR); + } + + if (write_bootblock(data) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Error writing bootblock to " + "disk\n")); + return (BC_ERROR); + } + + return (write_stage1(data)); +} + +/* + * Install a new bootblock on the given device. handle_install() expects argv + * to contain 3 parameters (the target device path and the path to the + * bootblock. + * + * Returns: BC_SUCCESS - if the installation is successful + * BC_ERROR - if the installation failed + * BC_NOUPDT - if no installation was performed because the + * version currently installed is more recent than the + * supplied one. + * + */ +static int +handle_install(char *progname, char **argv) +{ + ib_data_t install_data; + char *stage1 = NULL; + char *bootblock = NULL; + char *device_path = NULL; + int ret = BC_ERROR; + + stage1 = strdup(argv[0]); + bootblock = strdup(argv[1]); + device_path = strdup(argv[2]); + + if (!device_path || !bootblock || !stage1) { + (void) fprintf(stderr, gettext("Missing parameter")); + usage(progname); + goto out; + } + + BOOT_DEBUG("device path: %s, stage1 path: %s bootblock path: %s\n", + device_path, stage1, bootblock); + bzero(&install_data, sizeof (ib_data_t)); + + if (init_device(&install_data.device, device_path) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Unable to open device %s\n"), + device_path); + goto out; + } + + if (read_stage1_from_file(stage1, &install_data) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Error opening %s\n"), stage1); + goto out_dev; + } + + if (read_bootblock_from_file(bootblock, &install_data) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Error reading %s\n"), + bootblock); + goto out_dev; + } + + /* + * is_update_necessary() will take care of checking if versioning and/or + * forcing the update have been specified. It will also emit a warning + * if a non-versioned update is attempted over a versioned bootblock. + */ + if (!is_update_necessary(&install_data, update_str)) { + (void) fprintf(stderr, gettext("bootblock version installed " + "on %s is more recent or identical\n" + "Use -F to override or install without the -u option\n"), + device_path); + ret = BC_NOUPDT; + goto out_dev; + } + + BOOT_DEBUG("Ready to commit to disk\n"); + ret = commit_to_disk(&install_data, update_str); + +out_dev: + cleanup_device(&install_data.device); +out: + free(stage1); + free(bootblock); + free(device_path); + return (ret); +} + +/* + * Retrieves from a device the extended information (einfo) associated to the + * installed stage2. + * Expects one parameter, the device path, in the form: /dev/rdsk/c?[t?]d?s0. + * Returns: + * - BC_SUCCESS (and prints out einfo contents depending on 'flags') + * - BC_ERROR (on error) + * - BC_NOEINFO (no extended information available) + */ +static int +handle_getinfo(char *progname, char **argv) +{ + + ib_data_t data; + ib_bootblock_t *bblock = &data.bootblock; + ib_device_t *device = &data.device; + bblk_einfo_t *einfo; + uint8_t flags = 0; + char *device_path, *path; + int retval = BC_ERROR; + int ret; + + device_path = strdup(argv[0]); + if (!device_path) { + (void) fprintf(stderr, gettext("Missing parameter")); + usage(progname); + goto out; + } + + bzero(&data, sizeof (ib_data_t)); + BOOT_DEBUG("device path: %s\n", device_path); + + if (init_device(device, device_path) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Unable to gather device " + "information from %s\n"), device_path); + goto out_dev; + } + + ret = read_bootblock_from_disk(device, bblock, &path); + if (ret == BC_ERROR) { + (void) fprintf(stderr, gettext("Error reading bootblock from " + "%s\n"), path); + goto out_dev; + } + + if (ret == BC_NOEXTRA) { + BOOT_DEBUG("No multiboot header found on %s, unable " + "to locate extra information area (old/non versioned " + "bootblock?) \n", device_path); + (void) fprintf(stderr, gettext("No extended information " + "found\n")); + retval = BC_NOEINFO; + goto out_dev; + } + + einfo = find_einfo(bblock->extra, bblock->extra_size); + if (einfo == NULL) { + retval = BC_NOEINFO; + (void) fprintf(stderr, gettext("No extended information " + "found\n")); + goto out_dev; + } + + /* Print the extended information. */ + if (strip) + flags |= EINFO_EASY_PARSE; + if (verbose_dump) + flags |= EINFO_PRINT_HEADER; + + print_einfo(flags, einfo, bblock->extra_size); + retval = BC_SUCCESS; + +out_dev: + cleanup_device(&data.device); +out: + free(device_path); + return (retval); +} + +/* + * Attempt to mirror (propagate) the current bootblock over the attaching disk. + * + * Returns: + * - BC_SUCCESS (a successful propagation happened) + * - BC_ERROR (an error occurred) + * - BC_NOEXTRA (it is not possible to dump the current bootblock since + * there is no multiboot information) + */ +static int +handle_mirror(char *progname, char **argv) +{ + ib_data_t curr_data; + ib_data_t attach_data; + ib_device_t *curr_device = &curr_data.device; + ib_device_t *attach_device = &attach_data.device; + ib_bootblock_t *bblock_curr = &curr_data.bootblock; + ib_bootblock_t *bblock_attach = &attach_data.bootblock; + bblk_einfo_t *einfo_curr = NULL; + char *curr_device_path; + char *attach_device_path; + char *updt_str = NULL; + char *path; + int retval = BC_ERROR; + int ret; + + curr_device_path = strdup(argv[0]); + attach_device_path = strdup(argv[1]); + + if (!curr_device_path || !attach_device_path) { + (void) fprintf(stderr, gettext("Missing parameter")); + usage(progname); + goto out; + } + BOOT_DEBUG("Current device path is: %s, attaching device path is: " + " %s\n", curr_device_path, attach_device_path); + + bzero(&curr_data, sizeof (ib_data_t)); + bzero(&attach_data, sizeof (ib_data_t)); + + if (init_device(curr_device, curr_device_path) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Unable to gather device " + "information from %s (current device)\n"), + curr_device_path); + goto out_currdev; + } + + if (init_device(attach_device, attach_device_path) != BC_SUCCESS) { + (void) fprintf(stderr, gettext("Unable to gather device " + "information from %s (attaching device)\n"), + attach_device_path); + goto out_devs; + } + + ret = read_bootblock_from_disk(curr_device, bblock_curr, &path); + if (ret == BC_ERROR) { + BOOT_DEBUG("Error reading bootblock from %s\n", path); + retval = BC_ERROR; + goto out_devs; + } + + if (ret == BC_NOEXTRA) { + BOOT_DEBUG("No multiboot header found on %s, unable to retrieve" + " the bootblock\n", path); + retval = BC_NOEXTRA; + goto out_devs; + } + + write_mbr = B_TRUE; + force_mbr = B_TRUE; + einfo_curr = find_einfo(bblock_curr->extra, bblock_curr->extra_size); + if (einfo_curr != NULL) + updt_str = einfo_get_string(einfo_curr); + + retval = propagate_bootblock(&curr_data, &attach_data, updt_str); + cleanup_bootblock(bblock_curr); + cleanup_bootblock(bblock_attach); +out_devs: + cleanup_device(attach_device); +out_currdev: + cleanup_device(curr_device); +out: + free(curr_device_path); + free(attach_device_path); + return (retval); +} + +#define USAGE_STRING "Usage:\t%s [-h|-m|-f|-n|-F|-u verstr] stage1 stage2 " \ + "raw-device\n" \ + "\t%s -M [-n] raw-device attach-raw-device\n" \ + "\t%s [-e|-V] -i raw-device\n" + +#define CANON_USAGE_STR gettext(USAGE_STRING) + +static void +usage(char *progname) +{ + (void) fprintf(stdout, CANON_USAGE_STR, progname, progname, progname); +} + +int +main(int argc, char **argv) +{ + int opt; + int params = 3; + int ret; + char *progname; + char **handle_args; + + (void) setlocale(LC_ALL, ""); + (void) textdomain(TEXT_DOMAIN); + if (init_yes() < 0) { + (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), + strerror(errno)); + exit(BC_ERROR); + } + + while ((opt = getopt(argc, argv, "deFfhiMmnu:V")) != EOF) { + switch (opt) { + case 'd': + boot_debug = B_TRUE; + break; + case 'e': + strip = B_TRUE; + break; + case 'F': + force_update = B_TRUE; + break; + case 'f': + force_mbr = B_TRUE; + break; + case 'h': + usage(argv[0]); + exit(BC_SUCCESS); + break; + case 'i': + do_getinfo = B_TRUE; + params = 1; + break; + case 'M': + do_mirror_bblk = B_TRUE; + params = 2; + break; + case 'm': + write_mbr = B_TRUE; + break; + case 'n': + nowrite = B_TRUE; + break; + case 'u': + do_version = B_TRUE; + + update_str = malloc(strlen(optarg) + 1); + if (update_str == NULL) { + perror(gettext("Memory allocation failure")); + exit(BC_ERROR); + } + (void) strlcpy(update_str, optarg, strlen(optarg) + 1); + break; + case 'V': + verbose_dump = B_TRUE; + break; + default: + /* fall through to process non-optional args */ + break; + } + } + + /* check arguments */ + if (argc != optind + params) { + usage(argv[0]); + exit(BC_ERROR); + } + progname = argv[0]; + check_options(progname); + handle_args = argv + optind; + + if (nowrite) + (void) fprintf(stdout, gettext("Dry run requested. Nothing will" + " be written to disk.\n")); + + if (do_getinfo) { + ret = handle_getinfo(progname, handle_args); + } else if (do_mirror_bblk) { + ret = handle_mirror(progname, handle_args); + } else { + ret = handle_install(progname, handle_args); + } + return (ret); +} + +#define MEANINGLESS_OPT gettext("%s specified but meaningless, ignoring\n") +static void +check_options(char *progname) +{ + if (do_getinfo && do_mirror_bblk) { + (void) fprintf(stderr, gettext("Only one of -M and -i can be " + "specified at the same time\n")); + usage(progname); + exit(BC_ERROR); + } + + if (do_mirror_bblk) { + /* + * -u and -F may actually reflect a user intent that is not + * correct with this command (mirror can be interpreted + * "similar" to install. Emit a message and continue. + * -e and -V have no meaning, be quiet here and only report the + * incongruence if a debug output is requested. + */ + if (do_version) { + (void) fprintf(stderr, MEANINGLESS_OPT, "-u"); + do_version = B_FALSE; + } + if (force_update) { + (void) fprintf(stderr, MEANINGLESS_OPT, "-F"); + force_update = B_FALSE; + } + if (strip || verbose_dump) { + BOOT_DEBUG(MEANINGLESS_OPT, "-e|-V"); + strip = B_FALSE; + verbose_dump = B_FALSE; + } + } + + if (do_getinfo) { + if (write_mbr || force_mbr || do_version || force_update) { + BOOT_DEBUG(MEANINGLESS_OPT, "-m|-f|-u|-F"); + write_mbr = force_mbr = do_version = B_FALSE; + force_update = B_FALSE; + } + } +} diff --git a/usr/src/cmd/boot/installboot/i386/installboot.h b/usr/src/cmd/boot/installboot/i386/installboot.h new file mode 100644 index 0000000000..741f1cb682 --- /dev/null +++ b/usr/src/cmd/boot/installboot/i386/installboot.h @@ -0,0 +1,112 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2012 Nexenta Systems, Inc. All rights reserved. + * Copyright 2016 Toomas Soome <tsoome@me.com> + */ + +#ifndef _INSTALLBOOT_H +#define _INSTALLBOOT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/multiboot.h> +#include <sys/types.h> + +#define SECTOR_SIZE (512) + +/* partitioning type for device */ +enum ig_devtype_t { + IG_DEV_VTOC = 0, + IG_DEV_MBR, + IG_DEV_EFI +}; + +/* file system type */ +enum ig_fstype_t { + IG_FS_NONE = 0, + IG_FS_ZFS, + IG_FS_UFS, + IG_FS_PCFS +}; + +/* partition info for boot block location. */ +struct stage_part { + char *path; /* device name */ + int fd; /* open file descriptor */ + int id; /* partition/slice number */ + enum ig_devtype_t devtype; /* partitioning type */ + enum ig_fstype_t fstype; /* none or pcfs */ + uint64_t start; /* partition LBA */ + uint64_t size; /* partition size */ + uint64_t offset; /* block offset */ +}; + +/* boot device data */ +typedef struct _ib_device { + char *path; /* whole disk */ + int fd; /* whole disk fd */ + enum ig_devtype_t devtype; + struct stage_part stage; /* location of boot block */ + struct stage_part target; /* target file system */ + char mbr[SECTOR_SIZE]; +} ib_device_t; + +/* stage 2 location */ +typedef struct _ib_bootblock { + char *buf; + char *file; + char *extra; + multiboot_header_t *mboot; + uint32_t mboot_off; + uint32_t file_size; + uint32_t buf_size; + uint32_t extra_size; +} ib_bootblock_t; + +typedef struct _ib_data { + unsigned char stage1[SECTOR_SIZE]; /* partition boot block */ + ib_device_t device; /* boot device */ + ib_bootblock_t bootblock; /* stage 2 */ +} ib_data_t; + +#define BBLK_BLKLIST_OFF 50 /* vtoc/disk boot offset */ +#define BBLK_ZFS_BLK_OFF 1024 /* vdev boot offset */ +#define BBLK_ZFS_BLK_SIZE (7ULL << 19) /* vdev max boot size */ + +/* locations of MBR parts, must be reviewd if mbr code is changed */ +#define STAGE1_BPB_OFFSET (0x3) /* technically BPB starts at 0xb */ +#define STAGE1_BPB_SIZE (0x3b) +#define STAGE1_MBR_VERSION (0xfa) /* 2 bytes, not used */ +#define STAGE1_STAGE2_SIZE (0xfc) /* 16bits */ +#define STAGE1_STAGE2_LBA (0xfe) /* 64bits */ +#define STAGE1_STAGE2_UUID (0x106) /* 128bits */ +#define STAGE1_SIG (0x1b8) /* 4+2 bytes */ +#define STAGE1_PARTTBL (0x1be) /* MBR partition table */ +#define STAGE1_MAGIC (0x1fe) /* 0xAA55 */ +#ifdef __cplusplus +} +#endif + +#endif /* _INSTALLBOOT_H */ diff --git a/usr/src/cmd/boot/installboot/sparc/Makefile b/usr/src/cmd/boot/installboot/sparc/Makefile new file mode 100644 index 0000000000..cbf9632fba --- /dev/null +++ b/usr/src/cmd/boot/installboot/sparc/Makefile @@ -0,0 +1,18 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +include ../Makefile.com + +.KEEP_STATE: + +all: + +include $(SRC)/cmd/boot/Makefile.targ diff --git a/usr/src/cmd/boot/installboot/installboot.c b/usr/src/cmd/boot/installboot/sparc/installboot.c index 2a4f48fd18..36b0bd3d15 100644 --- a/usr/src/cmd/boot/installboot/installboot.c +++ b/usr/src/cmd/boot/installboot/sparc/installboot.c @@ -36,9 +36,9 @@ #include <sys/sysmacros.h> #include "installboot.h" -#include "./../common/bblk_einfo.h" -#include "./../common/boot_utils.h" -#include "./../common/mboot_extra.h" +#include "../../common/bblk_einfo.h" +#include "../../common/boot_utils.h" +#include "../../common/mboot_extra.h" #ifndef TEXT_DOMAIN #define TEXT_DOMAIN "SUNW_OST_OSCMD" diff --git a/usr/src/cmd/boot/installboot/installboot.h b/usr/src/cmd/boot/installboot/sparc/installboot.h index 2fa7ad2561..2fa7ad2561 100644 --- a/usr/src/cmd/boot/installboot/installboot.h +++ b/usr/src/cmd/boot/installboot/sparc/installboot.h diff --git a/usr/src/cmd/eeprom/i386/Makefile b/usr/src/cmd/eeprom/i386/Makefile index 4c28dce186..d47fd832d1 100644 --- a/usr/src/cmd/eeprom/i386/Makefile +++ b/usr/src/cmd/eeprom/i386/Makefile @@ -18,9 +18,7 @@ # # CDDL HEADER END # -# -#ident "%Z%%M% %I% %E% SMI" -# +# Copyright 2016 Toomas Soome <tsoome@me.com> # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -29,10 +27,6 @@ SRCDIR = .. include $(SRCDIR)/Makefile.com -# We "borrow" some error messages from bootadm. Add the path to pick these up -CFLAGS += -I../../boot/bootadm -LINTFLAGS += -I../../boot/bootadm - OBJS += benv.o benv_kvm.o .KEEP_STATE: diff --git a/usr/src/cmd/eeprom/i386/benv.c b/usr/src/cmd/eeprom/i386/benv.c index f032a3e064..11613cc5ce 100644 --- a/usr/src/cmd/eeprom/i386/benv.c +++ b/usr/src/cmd/eeprom/i386/benv.c @@ -20,11 +20,11 @@ */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. */ #include "benv.h" -#include "message.h" #include <ctype.h> #include <stdarg.h> #include <sys/mman.h> @@ -186,280 +186,15 @@ get_var(char *name, eplist_t *list) return (NULL); } -/*PRINTFLIKE1*/ -static void -eeprom_error(const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - (void) fprintf(stderr, "eeprom: "); - (void) vfprintf(stderr, format, ap); - va_end(ap); -} - -static int -exec_cmd(char *cmdline, char *output, int64_t osize) -{ - char buf[BUFSIZ]; - int ret; - size_t len; - FILE *ptr; - sigset_t set; - void (*disp)(int); - - if (output) - output[0] = '\0'; - - /* - * For security - * - only absolute paths are allowed - * - set IFS to space and tab - */ - if (*cmdline != '/') { - eeprom_error(ABS_PATH_REQ, cmdline); - return (-1); - } - (void) putenv("IFS= \t"); - - /* - * We may have been exec'ed with SIGCHLD blocked - * unblock it here - */ - (void) sigemptyset(&set); - (void) sigaddset(&set, SIGCHLD); - if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { - eeprom_error(FAILED_SIG, strerror(errno)); - return (-1); - } - - /* - * Set SIGCHLD disposition to SIG_DFL for popen/pclose - */ - disp = sigset(SIGCHLD, SIG_DFL); - if (disp == SIG_ERR) { - eeprom_error(FAILED_SIG, strerror(errno)); - return (-1); - } - if (disp == SIG_HOLD) { - eeprom_error(BLOCKED_SIG, cmdline); - return (-1); - } - - ptr = popen(cmdline, "r"); - if (ptr == NULL) { - eeprom_error(POPEN_FAIL, cmdline, strerror(errno)); - return (-1); - } - - /* - * If we simply do a pclose() following a popen(), pclose() - * will close the reader end of the pipe immediately even - * if the child process has not started/exited. pclose() - * does wait for cmd to terminate before returning though. - * When the executed command writes its output to the pipe - * there is no reader process and the command dies with - * SIGPIPE. To avoid this we read repeatedly until read - * terminates with EOF. This indicates that the command - * (writer) has closed the pipe and we can safely do a - * pclose(). - * - * Since pclose() does wait for the command to exit, - * we can safely reap the exit status of the command - * from the value returned by pclose() - */ - while (fgets(buf, sizeof (buf), ptr) != NULL) { - if (output && osize > 0) { - (void) snprintf(output, osize, "%s", buf); - len = strlen(buf); - output += len; - osize -= len; - } - } - - /* - * If there's a "\n" at the end, we want to chop it off - */ - if (output) { - len = strlen(output) - 1; - if (output[len] == '\n') - output[len] = '\0'; - } - - ret = pclose(ptr); - if (ret == -1) { - eeprom_error(PCLOSE_FAIL, cmdline, strerror(errno)); - return (-1); - } - - if (WIFEXITED(ret)) { - return (WEXITSTATUS(ret)); - } else { - eeprom_error(EXEC_FAIL, cmdline, ret); - return (-1); - } -} - -#define BOOTADM_STR "bootadm: " - -/* - * bootadm starts all error messages with "bootadm: ". - * Add a note so users don't get confused on how they ran bootadm. - */ -static void -output_error_msg(const char *msg) -{ - size_t len = sizeof (BOOTADM_STR) - 1; - - if (strncmp(msg, BOOTADM_STR, len) == 0) { - eeprom_error("error returned from %s\n", msg); - } else if (msg[0] != '\0') { - eeprom_error("%s\n", msg); - } -} - -static char * -get_bootadm_value(char *name, const int quiet) -{ - char *ptr, *ret_str, *end_ptr, *orig_ptr; - char output[BUFSIZ]; - int is_console, is_kernel = 0; - size_t len; - - is_console = (strcmp(name, "console") == 0); - - if (strcmp(name, "boot-file") == 0) { - is_kernel = 1; - ptr = "/sbin/bootadm set-menu kernel 2>&1"; - } else if (is_console || (strcmp(name, "boot-args") == 0)) { - ptr = "/sbin/bootadm set-menu args 2>&1"; - } else { - eeprom_error("Unknown value in get_bootadm_value: %s\n", name); - return (NULL); - } - - if (exec_cmd(ptr, output, BUFSIZ) != 0) { - if (quiet == 0) { - output_error_msg(output); - } - return (NULL); - } - - if (is_console) { - if ((ptr = strstr(output, "console=")) == NULL) { - return (NULL); - } - ptr += strlen("console="); - - /* - * -B may have comma-separated values. It may also be - * followed by other flags. - */ - len = strcspn(ptr, " \t,"); - ret_str = calloc(len + 1, 1); - if (ret_str == NULL) { - eeprom_error(NO_MEM, len + 1); - return (NULL); - } - (void) strncpy(ret_str, ptr, len); - return (ret_str); - } else if (is_kernel) { - ret_str = strdup(output); - if (ret_str == NULL) - eeprom_error(NO_MEM, strlen(output) + 1); - return (ret_str); - } else { - /* If there's no console setting, we can return */ - if ((orig_ptr = strstr(output, "console=")) == NULL) { - return (strdup(output)); - } - len = strcspn(orig_ptr, " \t,"); - ptr = orig_ptr; - end_ptr = orig_ptr + len + 1; - - /* Eat up any white space */ - while ((*end_ptr == ' ') || (*end_ptr == '\t')) - end_ptr++; - - /* - * If there's data following the console string, copy it. - * If not, cut off the new string. - */ - if (*end_ptr == '\0') - *ptr = '\0'; - - while (*end_ptr != '\0') { - *ptr = *end_ptr; - ptr++; - end_ptr++; - } - *ptr = '\0'; - if ((strchr(output, '=') == NULL) && - (strncmp(output, "-B ", 3) == 0)) { - /* - * Since we removed the console setting, we no - * longer need the initial "-B " - */ - orig_ptr = output + 3; - } else { - orig_ptr = output; - } - - ret_str = strdup(orig_ptr); - if (ret_str == NULL) - eeprom_error(NO_MEM, strlen(orig_ptr) + 1); - return (ret_str); - } -} - -/* - * If quiet is 1, print nothing if there is no value. If quiet is 0, print - * a message. Return 1 if the value is printed, 0 otherwise. - */ -static int -print_bootadm_value(char *name, const int quiet) -{ - int rv = 0; - char *value = get_bootadm_value(name, quiet); - - if ((value != NULL) && (value[0] != '\0')) { - (void) printf("%s=%s\n", name, value); - rv = 1; - } else if (quiet == 0) { - (void) printf("%s: data not available.\n", name); - } - - if (value != NULL) - free(value); - return (rv); -} - static void print_var(char *name, eplist_t *list) { benv_ent_t *p; char *bootcmd; - /* - * The console property is kept in both menu.lst and bootenv.rc. The - * menu.lst value takes precedence. - */ - if (strcmp(name, "console") == 0) { - if (print_bootadm_value(name, 1) == 0) { - if ((p = get_var(name, list)) != NULL) { - (void) printf("%s=%s\n", name, p->val ? - p->val : ""); - } else { - (void) printf("%s: data not available.\n", - name); - } - } - } else if (strcmp(name, "bootcmd") == 0) { + if (strcmp(name, "bootcmd") == 0) { bootcmd = getbootcmd(); (void) printf("%s=%s\n", name, bootcmd ? bootcmd : ""); - } else if ((strcmp(name, "boot-file") == 0) || - (strcmp(name, "boot-args") == 0)) { - (void) print_bootadm_value(name, 0); } else if ((p = get_var(name, list)) == NULL) { (void) printf("%s: data not available.\n", name); } else { @@ -472,30 +207,13 @@ print_vars(eplist_t *list) { eplist_t *e; benv_ent_t *p; - int console_printed = 0; - - /* - * The console property is kept both in menu.lst and bootenv.rc. - * The menu.lst value takes precedence, so try printing that one - * first. - */ - console_printed = print_bootadm_value("console", 1); for (e = list->next; e != list; e = e->next) { p = (benv_ent_t *)e->item; if (p->name != NULL) { - if (((strcmp(p->name, "console") == 0) && - (console_printed == 1)) || - ((strcmp(p->name, "boot-file") == 0) || - (strcmp(p->name, "boot-args") == 0))) { - /* handle these separately */ - continue; - } (void) printf("%s=%s\n", p->name, p->val ? p->val : ""); } } - (void) print_bootadm_value("boot-file", 1); - (void) print_bootadm_value("boot-args", 1); } /* @@ -522,77 +240,6 @@ put_quoted(FILE *fp, char *val) (void) putc('\'', fp); } -static void -set_bootadm_var(char *name, char *value) -{ - char buf[BUFSIZ]; - char output[BUFSIZ] = ""; - char *console, *args; - int is_console; - - if (verbose) { - (void) printf("old:"); - (void) print_bootadm_value(name, 0); - } - - /* - * For security, we single-quote whatever we run on the command line, - * and we don't allow single quotes in the string. - */ - if (strchr(value, '\'') != NULL) { - eeprom_error("Single quotes are not allowed " - "in the %s property.\n", name); - return; - } - - is_console = (strcmp(name, "console") == 0); - if (strcmp(name, "boot-file") == 0) { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm set-menu " - "kernel='%s' 2>&1", value); - } else if (is_console || (strcmp(name, "boot-args") == 0)) { - if (is_console) { - args = get_bootadm_value("boot-args", 1); - console = value; - } else { - args = value; - console = get_bootadm_value("console", 1); - } - if (((args == NULL) || (args[0] == '\0')) && - ((console == NULL) || (console[0] == '\0'))) { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm set-menu " - "args= 2>&1"); - } else if ((args == NULL) || (args[0] == '\0')) { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " - "set-menu args='-B console=%s' 2>&1", - console); - } else if ((console == NULL) || (console[0] == '\0')) { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " - "set-menu args='%s' 2>&1", args); - } else if (strncmp(args, "-B ", 3) != 0) { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " - "set-menu args='-B console=%s %s' 2>&1", - console, args); - } else { - (void) snprintf(buf, BUFSIZ, "/sbin/bootadm " - "set-menu args='-B console=%s,%s' 2>&1", - console, args + 3); - } - } else { - eeprom_error("Unknown value in set_bootadm_value: %s\n", name); - return; - } - - if (exec_cmd(buf, output, BUFSIZ) != 0) { - output_error_msg(output); - return; - } - - if (verbose) { - (void) printf("new:"); - (void) print_bootadm_value(name, 0); - } -} - /* * Returns 1 if bootenv.rc was modified, 0 otherwise. */ @@ -600,28 +247,10 @@ static int set_var(char *name, char *val, eplist_t *list) { benv_ent_t *p; - int old_verbose; if (strcmp(name, "bootcmd") == 0) return (0); - if ((strcmp(name, "boot-file") == 0) || - (strcmp(name, "boot-args") == 0)) { - set_bootadm_var(name, val); - return (0); - } - - /* - * The console property is kept in two places: menu.lst and bootenv.rc. - * Update them both. We clear verbose to prevent duplicate messages. - */ - if (strcmp(name, "console") == 0) { - old_verbose = verbose; - verbose = 0; - set_bootadm_var(name, val); - verbose = old_verbose; - } - if (verbose) { (void) printf("old:"); print_var(name, list); diff --git a/usr/src/cmd/ficl/Makefile b/usr/src/cmd/ficl/Makefile new file mode 100644 index 0000000000..6e2c325821 --- /dev/null +++ b/usr/src/cmd/ficl/Makefile @@ -0,0 +1,45 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# +# cmd/ficl/Makefile +# + +PROG= ficl-sys + +include ../Makefile.cmd + +SUBDIRS= $(MACH) +$(BUILD64)SUBDIRS += $(MACH64) + +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber + +.KEEP_STATE: + +all: $(SUBDIRS) + +clean clobber lint: $(SUBDIRS) + +install: $(SUBDIRS) + -$(RM) $(ROOTPROG) + -$(LN) $(ISAEXEC) $(ROOTPROG) + +$(SUBDIRS): FRC + @cd $@; pwd; $(MAKE) $(TARGET) + +FRC: + +include ../Makefile.targ diff --git a/usr/src/cmd/ficl/Makefile.com b/usr/src/cmd/ficl/Makefile.com new file mode 100644 index 0000000000..6be92a0115 --- /dev/null +++ b/usr/src/cmd/ficl/Makefile.com @@ -0,0 +1,41 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +PROG= ficl-sys +OBJS= main.o +SRCS= main.c + +include ../../Makefile.cmd +include ../../Makefile.ctf + +LDLIBS += -lficl-sys -ltecla -lumem +CPPFLAGS += -D_FILE_OFFSET_BITS=64 -I$(SRC)/common/ficl + +.KEEP_STATE: + +all: $(PROG) + +$(PROG): $(OBJS) + $(LINK.c) $(OBJS) -o $@ $(LDLIBS) + $(POST_PROCESS) + +clean: + $(RM) $(OBJS) + +include ../../Makefile.targ + +%.o: $(SRC)/common/ficl/%.c + $(COMPILE.c) $(OUTPUT_OPTION) $< $(CTFCONVERT_HOOK) + $(POST_PROCESS_O) diff --git a/usr/src/cmd/ficl/amd64/Makefile b/usr/src/cmd/ficl/amd64/Makefile new file mode 100644 index 0000000000..5947231d79 --- /dev/null +++ b/usr/src/cmd/ficl/amd64/Makefile @@ -0,0 +1,19 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +include ../Makefile.com +include ../../Makefile.cmd.64 + +install: all $(ROOTPROG64) diff --git a/usr/src/cmd/ficl/i386/Makefile b/usr/src/cmd/ficl/i386/Makefile new file mode 100644 index 0000000000..df3cfceab6 --- /dev/null +++ b/usr/src/cmd/ficl/i386/Makefile @@ -0,0 +1,18 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +include ../Makefile.com + +install: all $(ROOTPROG32) diff --git a/usr/src/cmd/ficl/sparc/Makefile b/usr/src/cmd/ficl/sparc/Makefile new file mode 100644 index 0000000000..df3cfceab6 --- /dev/null +++ b/usr/src/cmd/ficl/sparc/Makefile @@ -0,0 +1,18 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +include ../Makefile.com + +install: all $(ROOTPROG32) diff --git a/usr/src/cmd/ficl/sparcv9/Makefile b/usr/src/cmd/ficl/sparcv9/Makefile new file mode 100644 index 0000000000..5947231d79 --- /dev/null +++ b/usr/src/cmd/ficl/sparcv9/Makefile @@ -0,0 +1,19 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Toomas Soome <tsoome@me.com> +# + +include ../Makefile.com +include ../../Makefile.cmd.64 + +install: all $(ROOTPROG64) diff --git a/usr/src/cmd/halt/Makefile b/usr/src/cmd/halt/Makefile index 3eb9fddfc7..98d8eccee4 100644 --- a/usr/src/cmd/halt/Makefile +++ b/usr/src/cmd/halt/Makefile @@ -18,7 +18,7 @@ # # CDDL HEADER END # -# +# Copyright 2016 Toomas Soome <tsoome@me.com> # Copyright 2010 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # @@ -50,7 +50,7 @@ CPPFLAGS += -I../../uts/common/fs/zfs CERRWARN += -_gcc=-Wno-unused-label LDLIBS += -lbsm -lscf -lzfs -lgen -LDLIBS_i386 += -lgrubmgmt +LDLIBS_i386 += -lbe LDLIBS += $(LDLIBS_$(MACH)) CLOBBERFILES += $(ROOTLINKS) $(ROOTSYMLINKS) diff --git a/usr/src/cmd/halt/halt.c b/usr/src/cmd/halt/halt.c index 8464619a68..0293c5e788 100644 --- a/usr/src/cmd/halt/halt.c +++ b/usr/src/cmd/halt/halt.c @@ -19,6 +19,7 @@ * CDDL HEADER END */ /* + * Copyright 2016 Toomas Soome <tsoome@me.com> * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * Copyright 2011 Joyent, Inc. All rights reserved. @@ -85,8 +86,8 @@ #include <spawn.h> #include <libzfs.h> -#if defined(__i386) -#include <libgrubmgmt.h> +#if defined(__x86) +#include <libbe.h> #endif #if !defined(TEXT_DOMAIN) @@ -95,7 +96,7 @@ #if defined(__sparc) #define CUR_ELFDATA ELFDATA2MSB -#elif defined(__i386) +#elif defined(__x86) #define CUR_ELFDATA ELFDATA2LSB #endif @@ -136,11 +137,11 @@ static ctid_t startdct = -1; */ static char fastboot_mounted[MAXPATHLEN]; -#if defined(__i386) -static grub_boot_args_t fbarg; -static grub_boot_args_t *fbarg_used; -static int fbarg_entnum = GRUB_ENTRY_DEFAULT; -#endif /* __i386 */ +#if defined(__x86) +static char *fbarg; +static char *fbarg_used; +static int fbarg_entnum = BE_ENTRY_DEFAULT; +#endif /* __x86 */ static int validate_ufs_disk(char *, char *); static int validate_zfs_pool(char *, char *); @@ -1046,49 +1047,47 @@ parse_fastboot_args(char *bootargs_buf, size_t buf_size, if (*is_dryrun) return (rc); -#if defined(__i386) - /* Read boot args from GRUB menu */ +#if defined(__x86) + /* Read boot args from Boot Environment */ if ((bootargs_buf[0] == 0 || isdigit(bootargs_buf[0])) && bename == NULL) { /* - * If no boot arguments are given, or a GRUB menu entry - * number is provided, process the GRUB menu. + * If no boot arguments are given, or a BE entry + * number is provided, process the boot arguments from BE. */ int entnum; if (bootargs_buf[0] == 0) - entnum = GRUB_ENTRY_DEFAULT; + entnum = BE_ENTRY_DEFAULT; else { errno = 0; entnum = strtoul(bootargs_buf, NULL, 10); rc = errno; } - if (rc == 0 && (rc = grub_get_boot_args(&fbarg, NULL, - entnum)) == 0) { - if (strlcpy(bootargs_buf, fbarg.gba_bootargs, + if (rc == 0 && (rc = be_get_boot_args(&fbarg, entnum)) == 0) { + if (strlcpy(bootargs_buf, fbarg, buf_size) >= buf_size) { - grub_cleanup_boot_args(&fbarg); + free(fbarg); bcopy(bootargs_saved, bootargs_buf, buf_size); rc = E2BIG; } } - /* Failed to read GRUB menu, fall back to normal reboot */ + /* Failed to read FB args, fall back to normal reboot */ if (rc != 0) { (void) fprintf(stderr, - gettext("%s: Failed to process GRUB menu " - "entry for fast reboot.\n\t%s\n"), - cmdname, grub_strerror(rc)); + gettext("%s: Failed to process boot " + "arguments from Boot Environment.\n"), cmdname); (void) fprintf(stderr, gettext("%s: Falling back to regular reboot.\n"), cmdname); return (-1); } /* No need to process further */ - fbarg_used = &fbarg; + fbarg_used = fbarg; fbarg_entnum = entnum; return (0); } -#endif /* __i386 */ +#endif /* __x86 */ /* Zero out the boot argument buffer as we will reconstruct it */ bzero(bootargs_buf, buf_size); @@ -1306,7 +1305,7 @@ main(int argc, char *argv[]) fcn = AD_POWEROFF; } else if (strcmp(cmdname, "reboot") == 0) { (void) audit_reboot_setup(); -#if defined(__i386) +#if defined(__x86) optstring = "dlnqpfe:"; usage = gettext("usage: %s [ -dlnq(p|fe:) ] [ boot args ]\n"); #else @@ -1353,7 +1352,7 @@ main(int argc, char *argv[]) case 'p': prom_reboot = 1; break; -#if defined(__i386) +#if defined(__x86) case 'e': bename = optarg; break; @@ -1515,14 +1514,14 @@ main(int argc, char *argv[]) need_check_zones = halt_zones(); } -#if defined(__i386) +#if defined(__x86) /* set new default entry in the GRUB entry */ - if (fbarg_entnum != GRUB_ENTRY_DEFAULT) { + if (fbarg_entnum != BE_ENTRY_DEFAULT) { char buf[32]; (void) snprintf(buf, sizeof (buf), "default=%u", fbarg_entnum); (void) halt_exec(BOOTADM_PROG, "set-menu", buf, NULL); } -#endif /* __i386 */ +#endif /* __x86 */ /* if we're dumping, do the archive update here and don't defer it */ if (cmd == A_DUMP && zoneid == GLOBAL_ZONEID && !nosync) @@ -1676,10 +1675,10 @@ fail: } else if (strlen(fastboot_mounted) != 0) { (void) umount(fastboot_mounted); -#if defined(__i386) - } else if (fbarg_used != NULL) { - grub_cleanup_boot_args(fbarg_used); -#endif /* __i386 */ +#if defined(__x86) + } else { + free(fbarg_used); +#endif /* __x86 */ } } diff --git a/usr/src/cmd/svc/startd/Makefile b/usr/src/cmd/svc/startd/Makefile index 1a29300a68..0479bc97b8 100644 --- a/usr/src/cmd/svc/startd/Makefile +++ b/usr/src/cmd/svc/startd/Makefile @@ -21,6 +21,7 @@ # # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright 2012 Milan Jurik. All rights reserved. +# Copyright 2016 Toomas Soome <tsoome@me.com> # PROG = svc.startd @@ -93,7 +94,7 @@ LDLIBS += \ -lumem \ -luutil -LDLIBS_i386 += -lgrubmgmt +LDLIBS_i386 += -lbe LDLIBS += $(LDLIBS_$(MACH)) -L $(ROOT)/lib/fm -lfmevent LDFLAGS += -R /lib/fm diff --git a/usr/src/cmd/svc/startd/graph.c b/usr/src/cmd/svc/startd/graph.c index 5a4e933220..fa20e56775 100644 --- a/usr/src/cmd/svc/startd/graph.c +++ b/usr/src/cmd/svc/startd/graph.c @@ -23,6 +23,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2013, Joyent, Inc. All rights reserved. * Copyright (c) 2015, Syneto S.R.L. All rights reserved. + * Copyright 2016 Toomas Soome <tsoome@me.com> */ /* @@ -162,9 +163,9 @@ #include <sys/statvfs.h> #include <sys/uadmin.h> #include <zone.h> -#if defined(__i386) -#include <libgrubmgmt.h> -#endif /* __i386 */ +#if defined(__x86) +#include <libbe.h> +#endif /* __x86 */ #include "startd.h" #include "protocol.h" @@ -533,8 +534,8 @@ graph_walk_dependents(graph_vertex_t *v, void (*func)(graph_vertex_t *, void *), } static void -graph_walk_dependencies(graph_vertex_t *v, void (*func)(graph_vertex_t *, - void *), void *arg) +graph_walk_dependencies(graph_vertex_t *v, + void (*func)(graph_vertex_t *, void *), void *arg) { graph_edge_t *e; @@ -3588,9 +3589,9 @@ do_uadmin(void) struct tm nowtm; char down_buf[256], time_buf[256]; uintptr_t mdep; -#if defined(__i386) - grub_boot_args_t fbarg; -#endif /* __i386 */ +#if defined(__x86) + char *fbarg = NULL; +#endif /* __x86 */ mdep = NULL; fd = creat(resetting, 0777); @@ -3641,27 +3642,22 @@ do_uadmin(void) * print warning and fall back to regular reboot. */ if (halting == AD_FASTREBOOT) { -#if defined(__i386) - int rc; - - if ((rc = grub_get_boot_args(&fbarg, NULL, - GRUB_ENTRY_DEFAULT)) == 0) { - mdep = (uintptr_t)&fbarg.gba_bootargs; +#if defined(__x86) + if (be_get_boot_args(&fbarg, BE_ENTRY_DEFAULT) == 0) { + mdep = (uintptr_t)fbarg; } else { /* - * Failed to read GRUB menu, fall back to normal reboot + * Failed to read BE info, fall back to normal reboot */ halting = AD_BOOT; - uu_warn("Failed to process GRUB menu entry " - "for fast reboot.\n\t%s\n" - "Falling back to regular reboot.\n", - grub_strerror(rc)); + uu_warn("Failed to get fast reboot arguments.\n" + "Falling back to regular reboot.\n"); } -#else /* __i386 */ +#else /* __x86 */ halting = AD_BOOT; uu_warn("Fast reboot configured, but not supported by " "this ISA\n"); -#endif /* __i386 */ +#endif /* __x86 */ } fork_with_timeout("/sbin/umountall -l", 0, 5); @@ -3717,11 +3713,10 @@ do_uadmin(void) (void) uadmin(A_SHUTDOWN, halting, mdep); uu_warn("uadmin() failed"); -#if defined(__i386) - /* uadmin fail, cleanup grub_boot_args */ +#if defined(__x86) if (halting == AD_FASTREBOOT) - grub_cleanup_boot_args(&fbarg); -#endif /* __i386 */ + free(fbarg); +#endif /* __x86 */ if (remove(resetting) != 0 && errno != ENOENT) uu_warn("Could not remove \"%s\"", resetting); diff --git a/usr/src/cmd/ztest/ztest.c b/usr/src/cmd/ztest/ztest.c index b4d979ba05..ad38bfa033 100644 --- a/usr/src/cmd/ztest/ztest.c +++ b/usr/src/cmd/ztest/ztest.c @@ -3216,9 +3216,12 @@ ztest_objset_destroy_cb(const char *name, void *arg) * Destroy the dataset. */ if (strchr(name, '@') != NULL) { - VERIFY0(dsl_destroy_snapshot(name, B_FALSE)); + VERIFY0(dsl_destroy_snapshot(name, B_TRUE)); } else { - VERIFY0(dsl_destroy_head(name)); + error = dsl_destroy_head(name); + /* There could be a hold on this dataset */ + if (error != EBUSY) + ASSERT0(error); } return (0); } |