1753a6d4Sherry Moore/*
2753a6d4Sherry Moore * CDDL HEADER START
3753a6d4Sherry Moore *
4753a6d4Sherry Moore * The contents of this file are subject to the terms of the
5753a6d4Sherry Moore * Common Development and Distribution License (the "License").
6753a6d4Sherry Moore * You may not use this file except in compliance with the License.
7753a6d4Sherry Moore *
8753a6d4Sherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9753a6d4Sherry Moore * or http://www.opensolaris.org/os/licensing.
10753a6d4Sherry Moore * See the License for the specific language governing permissions
11753a6d4Sherry Moore * and limitations under the License.
12753a6d4Sherry Moore *
13753a6d4Sherry Moore * When distributing Covered Code, include this CDDL HEADER in each
14753a6d4Sherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15753a6d4Sherry Moore * If applicable, add the following below this CDDL HEADER, with the
16753a6d4Sherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
17753a6d4Sherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
18753a6d4Sherry Moore *
19753a6d4Sherry Moore * CDDL HEADER END
20753a6d4Sherry Moore */
21753a6d4Sherry Moore/*
22753a6d4Sherry Moore * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23753a6d4Sherry Moore * Use is subject to license terms.
24753a6d4Sherry Moore */
25753a6d4Sherry Moore
26753a6d4Sherry Moore#ifndef _LIBGRUBMGMT_H
27753a6d4Sherry Moore#define	_LIBGRUBMGMT_H
28753a6d4Sherry Moore
29753a6d4Sherry Moore#include <sys/types.h>
30753a6d4Sherry Moore#include <sys/param.h>
31753a6d4Sherry Moore#include <sys/mntent.h>
32753a6d4Sherry Moore#include <sys/uadmin.h>
33753a6d4Sherry Moore#include <libzfs.h>
34753a6d4Sherry Moore
35753a6d4Sherry Moore#ifdef	__cplusplus
36753a6d4Sherry Mooreextern "C" {
37753a6d4Sherry Moore#endif
38753a6d4Sherry Moore
39753a6d4Sherry Moore#define	GRUB_ENTRY_DEFAULT	-1	/* Use the default entry */
40753a6d4Sherry Moore
41753a6d4Sherry Moore/*
42753a6d4Sherry Moore * Data structure for describing the GRUB menu
43753a6d4Sherry Moore */
44753a6d4Sherry Mooretypedef struct grub_menu grub_menu_t;
45753a6d4Sherry Mooretypedef struct grub_line grub_line_t;
46753a6d4Sherry Mooretypedef struct grub_entry grub_entry_t;
47753a6d4Sherry Moore
48753a6d4Sherry Moore/*
49753a6d4Sherry Moore * Data structure for describing the file system where the
50753a6d4Sherry Moore * GRUB menu resides
51753a6d4Sherry Moore */
52753a6d4Sherry Mooretypedef struct grub_fsdesc {
53753a6d4Sherry Moore	int	gfs_is_tmp_mounted;	/* is temporary mounted */
54753a6d4Sherry Moore	char	gfs_dev[MAXNAMELEN];	/* device/zfs dataset to mount */
55753a6d4Sherry Moore	char	gfs_mountp[MAXPATHLEN];	/* mount point */
56753a6d4Sherry Moore} grub_fsdesc_t;
57753a6d4Sherry Moore
58753a6d4Sherry Moore/*
59753a6d4Sherry Moore * Data structure for collecting data for Fast Reboot
60753a6d4Sherry Moore */
61753a6d4Sherry Mooretypedef struct grub_boot_args {
62753a6d4Sherry Moore	grub_fsdesc_t	gba_fsd;
63753a6d4Sherry Moore	int		gba_kernel_fd;
64753a6d4Sherry Moore	char		gba_kernel[BOOTARGS_MAX];
65753a6d4Sherry Moore	char		gba_module[BOOTARGS_MAX];
66753a6d4Sherry Moore	char		gba_bootargs[BOOTARGS_MAX];
67753a6d4Sherry Moore} grub_boot_args_t;
68753a6d4Sherry Moore
69753a6d4Sherry Moore/*
70753a6d4Sherry Moore * Wrapper functions for retriving boot arguments for Fast Reboot.
71753a6d4Sherry Moore * grub_get_boot_args() calls grub_menu_init() and grub_menu_fini().
72753a6d4Sherry Moore * If menupath is NULL, it will use 'currently active' GRUB menu file.
73753a6d4Sherry Moore *
74753a6d4Sherry Moore * All _get_boot_args functions will mount the root file system for the
75753a6d4Sherry Moore * given entry if not mounted, and open and validate the kernel file.
76753a6d4Sherry Moore * Caller must allocate bargs, and call grub_cleanup_boot_args() to
77753a6d4Sherry Moore * clean up mount points and open file handles when done.
78753a6d4Sherry Moore *
79753a6d4Sherry Moore * grub_get_boot_args:
80753a6d4Sherry Moore *	Collects boot argument from the specified GRUB menu entry.
81753a6d4Sherry Moore *	If entrynum == -1, default GRUB menu entry will be used.
82753a6d4Sherry Moore *
83753a6d4Sherry Moore * grub_cleanup_boot_args:
84753a6d4Sherry Moore *	Cleans up and releases all the resources allocated by
85753a6d4Sherry Moore *	grub_get_boot_args.  Closes kernel file.  Umounts root file
86753a6d4Sherry Moore *	system if temporarily mounted.
87753a6d4Sherry Moore */
88753a6d4Sherry Mooreextern int grub_get_boot_args(grub_boot_args_t *bargs, const char *menupath,
89753a6d4Sherry Moore    int entrynum);
90753a6d4Sherry Mooreextern void grub_cleanup_boot_args(grub_boot_args_t *bargs);
91753a6d4Sherry Moore
92753a6d4Sherry Mooreextern const char *grub_strerror(int);
93753a6d4Sherry Moore
94753a6d4Sherry Moore#ifdef __cplusplus
95753a6d4Sherry Moore}
96753a6d4Sherry Moore#endif
97753a6d4Sherry Moore
98753a6d4Sherry Moore#endif	/* _LIBGRUBMGMT_H */
99