753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER START
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * The contents of this file are subject to the terms of the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Common Development and Distribution License (the "License").
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You may not use this file except in compliance with the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * See the License for the specific language governing permissions
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * and limitations under the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If applicable, add the following below this CDDL HEADER, with the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER END
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use is subject to license terms.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This file contains functions for constructing boot arguments
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * from GRUB menu for Fast Reboot.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif /* __i386 */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Open the kernel file.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return zero on sucess or error code otherwise.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * On success the kernel file descriptor is returned in fdp.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* kernel basename must be unix */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (pread64(fd, ident, sizeof (ident), 0) == sizeof (ident))) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((class == ELFCLASS32 || class == ELFCLASS64) &&
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Construct boot arguments for Fast Reboot from the ge_barg field of
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * a GRUB menu entry.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 0 on success, errno on failure.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorebarg2bootargs(const grub_barg_t *barg, grub_boot_args_t *fbarg)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((fsd = grub_get_rootfsd(&barg->gb_root)) == NULL)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bcopy(fsd, &fbarg->gba_fsd, sizeof (fbarg->gba_fsd));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bcopy(barg->gb_kernel, fbarg->gba_kernel, sizeof (fbarg->gba_kernel));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bcopy(barg->gb_module, fbarg->gba_module, sizeof (fbarg->gba_module));
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (snprintf(path, sizeof (path), "%s%s", fbarg->gba_fsd.gfs_mountp,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * GRUB requires absolute path, no symlinks, so do we
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((rc = resolvepath(path, rpath, sizeof (rpath))) == -1)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore rc = get_kernel_fd(rpath, &fbarg->gba_kernel_fd);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* construct bootargs command-line */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore sizeof (fbarg->gba_bootargs), "%s %s", fbarg->gba_fsd.gfs_mountp,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fbarg->gba_kernel) >= sizeof (fbarg->gba_bootargs))
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Construct boot arguments for Fast Reboot from grub_menu_t.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 0 on success, errno on failure.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooregrub_entry_get_boot_args(grub_entry_t *ent, grub_boot_args_t *fbarg)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (IS_ENTRY_VALID(ent) && (rc = grub_entry_construct_barg(ent)) == 0)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Construct boot arguments for Fast Reboot from grub_menu_t and the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * entry number.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 0 on success, errno on failure.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooregrub_menu_get_boot_args(const grub_menu_t *mp, int num,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((ent = grub_menu_get_entry(mp, num)) == NULL)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Construct boot arguments from the specified GRUB menu entry.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Caller must allocate space for fbarg, and call grub_cleanup_boot_args()
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * when it's done with fbarg to clean up.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Return 0 on success, errno on failure.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooregrub_get_boot_args(grub_boot_args_t *fbarg, const char *menupath, int num)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((rc = grub_menu_init(menupath, &mp)) == 0) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Clean up when done with fbarg: close file handle, unmount file
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * systems. Must be safe to call even if not all the fields are