753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER START
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
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 *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * or http://www.opensolaris.org/os/licensing.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * See the License for the specific language governing permissions
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * and limitations under the License.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
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 *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * CDDL HEADER END
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use is subject to license terms.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#ifndef _LIBGRUBMGMT_H
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define _LIBGRUBMGMT_H
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/types.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/param.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/mntent.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <sys/uadmin.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#include <libzfs.h>
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#ifdef __cplusplus
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreextern "C" {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define GRUB_ENTRY_DEFAULT -1 /* Use the default entry */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Data structure for describing the GRUB menu
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooretypedef struct grub_menu grub_menu_t;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooretypedef struct grub_line grub_line_t;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooretypedef struct grub_entry grub_entry_t;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Data structure for describing the file system where the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * GRUB menu resides
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooretypedef struct grub_fsdesc {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int gfs_is_tmp_mounted; /* is temporary mounted */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char gfs_dev[MAXNAMELEN]; /* device/zfs dataset to mount */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char gfs_mountp[MAXPATHLEN]; /* mount point */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore} grub_fsdesc_t;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Data structure for collecting data for Fast Reboot
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooretypedef struct grub_boot_args {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore grub_fsdesc_t gba_fsd;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int gba_kernel_fd;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char gba_kernel[BOOTARGS_MAX];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char gba_module[BOOTARGS_MAX];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore char gba_bootargs[BOOTARGS_MAX];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore} grub_boot_args_t;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/*
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Wrapper functions for retriving boot arguments for Fast Reboot.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * grub_get_boot_args() calls grub_menu_init() and grub_menu_fini().
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If menupath is NULL, it will use 'currently active' GRUB menu file.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * All _get_boot_args functions will mount the root file system for the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * given entry if not mounted, and open and validate the kernel file.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Caller must allocate bargs, and call grub_cleanup_boot_args() to
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * clean up mount points and open file handles when done.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * grub_get_boot_args:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Collects boot argument from the specified GRUB menu entry.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If entrynum == -1, default GRUB menu entry will be used.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore *
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * grub_cleanup_boot_args:
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Cleans up and releases all the resources allocated by
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * grub_get_boot_args. Closes kernel file. Umounts root file
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * system if temporarily mounted.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreextern int grub_get_boot_args(grub_boot_args_t *bargs, const char *menupath,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore int entrynum);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreextern void grub_cleanup_boot_args(grub_boot_args_t *bargs);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Mooreextern const char *grub_strerror(int);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#ifdef __cplusplus
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore}
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#endif /* _LIBGRUBMGMT_H */