xref: /titanic_50/usr/src/lib/libgrubmgmt/common/libgrubmgmt.h (revision 753a6d457b330b1b29b2d3eefcd0831116ce950d)
1*753a6d45SSherry Moore /*
2*753a6d45SSherry Moore  * CDDL HEADER START
3*753a6d45SSherry Moore  *
4*753a6d45SSherry Moore  * The contents of this file are subject to the terms of the
5*753a6d45SSherry Moore  * Common Development and Distribution License (the "License").
6*753a6d45SSherry Moore  * You may not use this file except in compliance with the License.
7*753a6d45SSherry Moore  *
8*753a6d45SSherry Moore  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*753a6d45SSherry Moore  * or http://www.opensolaris.org/os/licensing.
10*753a6d45SSherry Moore  * See the License for the specific language governing permissions
11*753a6d45SSherry Moore  * and limitations under the License.
12*753a6d45SSherry Moore  *
13*753a6d45SSherry Moore  * When distributing Covered Code, include this CDDL HEADER in each
14*753a6d45SSherry Moore  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*753a6d45SSherry Moore  * If applicable, add the following below this CDDL HEADER, with the
16*753a6d45SSherry Moore  * fields enclosed by brackets "[]" replaced with your own identifying
17*753a6d45SSherry Moore  * information: Portions Copyright [yyyy] [name of copyright owner]
18*753a6d45SSherry Moore  *
19*753a6d45SSherry Moore  * CDDL HEADER END
20*753a6d45SSherry Moore  */
21*753a6d45SSherry Moore /*
22*753a6d45SSherry Moore  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*753a6d45SSherry Moore  * Use is subject to license terms.
24*753a6d45SSherry Moore  */
25*753a6d45SSherry Moore 
26*753a6d45SSherry Moore #ifndef _LIBGRUBMGMT_H
27*753a6d45SSherry Moore #define	_LIBGRUBMGMT_H
28*753a6d45SSherry Moore 
29*753a6d45SSherry Moore #include <sys/types.h>
30*753a6d45SSherry Moore #include <sys/param.h>
31*753a6d45SSherry Moore #include <sys/mntent.h>
32*753a6d45SSherry Moore #include <sys/uadmin.h>
33*753a6d45SSherry Moore #include <libzfs.h>
34*753a6d45SSherry Moore 
35*753a6d45SSherry Moore #ifdef	__cplusplus
36*753a6d45SSherry Moore extern "C" {
37*753a6d45SSherry Moore #endif
38*753a6d45SSherry Moore 
39*753a6d45SSherry Moore #define	GRUB_ENTRY_DEFAULT	-1	/* Use the default entry */
40*753a6d45SSherry Moore 
41*753a6d45SSherry Moore /*
42*753a6d45SSherry Moore  * Data structure for describing the GRUB menu
43*753a6d45SSherry Moore  */
44*753a6d45SSherry Moore typedef struct grub_menu grub_menu_t;
45*753a6d45SSherry Moore typedef struct grub_line grub_line_t;
46*753a6d45SSherry Moore typedef struct grub_entry grub_entry_t;
47*753a6d45SSherry Moore 
48*753a6d45SSherry Moore /*
49*753a6d45SSherry Moore  * Data structure for describing the file system where the
50*753a6d45SSherry Moore  * GRUB menu resides
51*753a6d45SSherry Moore  */
52*753a6d45SSherry Moore typedef struct grub_fsdesc {
53*753a6d45SSherry Moore 	int	gfs_is_tmp_mounted;	/* is temporary mounted */
54*753a6d45SSherry Moore 	char	gfs_dev[MAXNAMELEN];	/* device/zfs dataset to mount */
55*753a6d45SSherry Moore 	char	gfs_mountp[MAXPATHLEN];	/* mount point */
56*753a6d45SSherry Moore } grub_fsdesc_t;
57*753a6d45SSherry Moore 
58*753a6d45SSherry Moore /*
59*753a6d45SSherry Moore  * Data structure for collecting data for Fast Reboot
60*753a6d45SSherry Moore  */
61*753a6d45SSherry Moore typedef struct grub_boot_args {
62*753a6d45SSherry Moore 	grub_fsdesc_t	gba_fsd;
63*753a6d45SSherry Moore 	int		gba_kernel_fd;
64*753a6d45SSherry Moore 	char		gba_kernel[BOOTARGS_MAX];
65*753a6d45SSherry Moore 	char		gba_module[BOOTARGS_MAX];
66*753a6d45SSherry Moore 	char		gba_bootargs[BOOTARGS_MAX];
67*753a6d45SSherry Moore } grub_boot_args_t;
68*753a6d45SSherry Moore 
69*753a6d45SSherry Moore /*
70*753a6d45SSherry Moore  * Wrapper functions for retriving boot arguments for Fast Reboot.
71*753a6d45SSherry Moore  * grub_get_boot_args() calls grub_menu_init() and grub_menu_fini().
72*753a6d45SSherry Moore  * If menupath is NULL, it will use 'currently active' GRUB menu file.
73*753a6d45SSherry Moore  *
74*753a6d45SSherry Moore  * All _get_boot_args functions will mount the root file system for the
75*753a6d45SSherry Moore  * given entry if not mounted, and open and validate the kernel file.
76*753a6d45SSherry Moore  * Caller must allocate bargs, and call grub_cleanup_boot_args() to
77*753a6d45SSherry Moore  * clean up mount points and open file handles when done.
78*753a6d45SSherry Moore  *
79*753a6d45SSherry Moore  * grub_get_boot_args:
80*753a6d45SSherry Moore  *	Collects boot argument from the specified GRUB menu entry.
81*753a6d45SSherry Moore  *	If entrynum == -1, default GRUB menu entry will be used.
82*753a6d45SSherry Moore  *
83*753a6d45SSherry Moore  * grub_cleanup_boot_args:
84*753a6d45SSherry Moore  *	Cleans up and releases all the resources allocated by
85*753a6d45SSherry Moore  *	grub_get_boot_args.  Closes kernel file.  Umounts root file
86*753a6d45SSherry Moore  *	system if temporarily mounted.
87*753a6d45SSherry Moore  */
88*753a6d45SSherry Moore extern int grub_get_boot_args(grub_boot_args_t *bargs, const char *menupath,
89*753a6d45SSherry Moore     int entrynum);
90*753a6d45SSherry Moore extern void grub_cleanup_boot_args(grub_boot_args_t *bargs);
91*753a6d45SSherry Moore 
92*753a6d45SSherry Moore extern const char *grub_strerror(int);
93*753a6d45SSherry Moore 
94*753a6d45SSherry Moore #ifdef __cplusplus
95*753a6d45SSherry Moore }
96*753a6d45SSherry Moore #endif
97*753a6d45SSherry Moore 
98*753a6d45SSherry Moore #endif	/* _LIBGRUBMGMT_H */
99