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