xref: /freebsd/usr.sbin/bsdinstall/partedit/partedit.h (revision a7dea1671b87c07d2d266f836bfa8b58efc7c134)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2011 Nathan Whitehorn
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _PARTEDIT_PARTEDIT_H
32 #define _PARTEDIT_PARTEDIT_H
33 
34 #include <sys/queue.h>
35 #include <inttypes.h>
36 #include <fstab.h>
37 
38 struct gprovider;
39 struct gmesh;
40 struct ggeom;
41 
42 extern int tmpdfd;
43 
44 TAILQ_HEAD(pmetadata_head, partition_metadata);
45 extern struct pmetadata_head part_metadata;
46 
47 struct partition_metadata {
48 	char *name;		/* name of this partition, as in GEOM */
49 
50 	struct fstab *fstab;	/* fstab data for this partition */
51 	char *newfs;		/* shell command to initialize partition */
52 
53 	int bootcode;
54 
55 	TAILQ_ENTRY(partition_metadata) metadata;
56 };
57 
58 struct partition_metadata *get_part_metadata(const char *name, int create);
59 void delete_part_metadata(const char *name);
60 
61 int part_wizard(const char *fstype);
62 int scripted_editor(int argc, const char **argv);
63 int wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype,
64     int interactive);
65 
66 /* gpart operations */
67 void gpart_delete(struct gprovider *pp);
68 void gpart_destroy(struct ggeom *lg_geom);
69 void gpart_edit(struct gprovider *pp);
70 void gpart_create(struct gprovider *pp, const char *default_type,
71     const char *default_size, const char *default_mountpoint,
72     char **output, int interactive);
73 intmax_t gpart_max_free(struct ggeom *gp, intmax_t *start);
74 void gpart_revert(struct gprovider *pp);
75 void gpart_revert_all(struct gmesh *mesh);
76 void gpart_commit(struct gmesh *mesh);
77 int gpart_partition(const char *lg_name, const char *scheme);
78 void set_default_part_metadata(const char *name, const char *scheme,
79     const char *type, const char *mountpoint, const char *newfs);
80 void gpart_set_root(const char *lg_name, const char *attribute);
81 const char *choose_part_type(const char *def_scheme);
82 
83 /* machine-dependent bootability checks */
84 const char *default_scheme(void);		/* Default partition scheme */
85 int is_scheme_bootable(const char *scheme);	/* Non-zero if scheme boots */
86 int is_fs_bootable(const char *scheme, const char *fs); /* Ditto if FS boots */
87 
88 /* Size of boot partition in bytes. Zero if no boot partition */
89 size_t bootpart_size(const char *scheme);
90 
91 /*
92  * Type and mountpoint of boot partition for given scheme. If boot partition
93  * should not be mounted, set mountpoint to NULL or leave it unchanged.
94  * Note that mountpoint non-NULL implies partcode_path() will be ignored.
95  * Do *NOT* set both!
96  */
97 const char *bootpart_type(const char *scheme, const char **mountpoint);
98 
99 /* Path to bootcode that goes in the scheme (e.g. disk MBR). NULL if none */
100 const char *bootcode_path(const char *scheme);
101 
102 /*
103  * Path to boot blocks to be dd'ed into the partition suggested by bootpart_*
104  * for the given scheme and root filesystem type. If the boot partition should
105  * be mounted rather than dd'ed to, return NULL here.
106  */
107 const char *partcode_path(const char *scheme, const char *fs_type);
108 
109 #endif
110