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