xref: /freebsd/sys/geom/part/g_part.h (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
1 /*-
2  * Copyright (c) 2006, 2007 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _GEOM_PART_H_
30 #define	_GEOM_PART_H_
31 
32 #define	G_PART_TRACE(args)	g_trace args
33 
34 #define G_PART_PROBE_PRI_LOW	-10
35 #define	G_PART_PROBE_PRI_NORM	-5
36 #define	G_PART_PROBE_PRI_HIGH	0
37 
38 enum g_part_alias {
39 	G_PART_ALIAS_EFI,		/* A EFI system partition entry. */
40 	G_PART_ALIAS_FREEBSD,		/* A BSD labeled partition entry. */
41 	G_PART_ALIAS_FREEBSD_BOOT,	/* A FreeBSD boot partition entry. */
42 	G_PART_ALIAS_FREEBSD_SWAP,	/* A swap partition entry. */
43 	G_PART_ALIAS_FREEBSD_UFS,	/* A UFS/UFS2 file system entry. */
44 	G_PART_ALIAS_FREEBSD_VINUM,	/* A Vinum partition entry. */
45 	G_PART_ALIAS_FREEBSD_ZFS,	/* A ZFS file system entry. */
46 	G_PART_ALIAS_MBR,		/* A MBR (extended) partition entry. */
47 	/* Keep the following last */
48 	G_PART_ALIAS_COUNT
49 };
50 
51 const char *g_part_alias_name(enum g_part_alias);
52 
53 /* G_PART scheme (KOBJ class). */
54 struct g_part_scheme {
55 	KOBJ_CLASS_FIELDS;
56 	size_t		gps_entrysz;
57 	int		gps_minent;
58 	int		gps_maxent;
59 };
60 #define	G_PART_SCHEME_DECLARE(s)	DATA_SET(g_part_scheme_set, s)
61 
62 struct g_part_entry {
63 	LIST_ENTRY(g_part_entry) gpe_entry;
64 	struct g_provider *gpe_pp;	/* Corresponding provider. */
65 	off_t		gpe_offset;	/* Byte offset. */
66 	quad_t		gpe_start;	/* First LBA of partition. */
67 	quad_t		gpe_end;	/* Last LBA of partition. */
68 	int		gpe_index;
69 	int		gpe_created:1;	/* Entry is newly created. */
70 	int		gpe_deleted:1;	/* Entry has been deleted. */
71 	int		gpe_modified:1;	/* Entry has been modified. */
72 	int		gpe_internal:1;	/* Entry is not a used entry. */
73 };
74 
75 /* G_PART table (KOBJ instance). */
76 struct g_part_table {
77 	KOBJ_FIELDS;
78 	struct g_part_scheme *gpt_scheme;
79 	struct g_geom	*gpt_gp;
80 	LIST_HEAD(, g_part_entry) gpt_entry;
81 	quad_t		gpt_first;	/* First allocatable LBA */
82 	quad_t		gpt_last;	/* Last allocatable LBA */
83 	int		gpt_entries;
84 	/*
85 	 * gpt_smhead and gpt_smtail are bitmaps representing the first
86 	 * 32 sectors on the disk (gpt_smhead) and the last 32 sectors
87 	 * on the disk (gpt_smtail). These maps are used by the commit
88 	 * verb to clear sectors previously used by a scheme after the
89 	 * partitioning scheme has been destroyed.
90 	 */
91 	uint32_t	gpt_smhead;
92 	uint32_t	gpt_smtail;
93 	/*
94 	 * gpt_sectors and gpt_heads are the fixed or synchesized number
95 	 * of sectors per track and heads (resp) that make up a disks
96 	 * geometry. This is to support partitioning schemes as well as
97 	 * file systems that work on a geometry. The MBR scheme and the
98 	 * MS-DOS (FAT) file system come to mind.
99 	 * We keep track of whether the geometry is fixed or synchesized
100 	 * so that a partitioning scheme can correct the synthesized
101 	 * geometry, based on the on-disk metadata.
102 	 */
103 	uint32_t	gpt_sectors;
104 	uint32_t	gpt_heads;
105 	/*
106 	 * gpt_offset holds the absolute block address of the scheme
107 	 * on disk. Some partitioning schemes (historically) use
108 	 * absolute addressing. Relative addresses are obtained by
109 	 * subtracting gpt_offset from the absolute addresses.
110 	 */
111 	uint64_t	gpt_offset;
112 
113 	int		gpt_depth;	/* Sub-partitioning level. */
114 	int		gpt_isleaf:1;	/* Cannot be sub-partitioned. */
115 	int		gpt_created:1;	/* Newly created. */
116 	int		gpt_modified:1;	/* Table changes have been made. */
117 	int		gpt_opened:1;	/* Permissions obtained. */
118 	int		gpt_fixgeom:1;	/* Geometry is fixed. */
119 };
120 
121 struct g_part_entry *g_part_new_entry(struct g_part_table *, int, quad_t,
122     quad_t);
123 
124 /* G_PART ctlreq parameters. */
125 #define	G_PART_PARM_ENTRIES	0x0001
126 #define	G_PART_PARM_FLAGS	0x0002
127 #define	G_PART_PARM_GEOM	0x0004
128 #define	G_PART_PARM_INDEX	0x0008
129 #define	G_PART_PARM_LABEL	0x0010
130 #define	G_PART_PARM_OUTPUT	0x0020
131 #define	G_PART_PARM_PROVIDER	0x0040
132 #define	G_PART_PARM_SCHEME	0x0080
133 #define	G_PART_PARM_SIZE	0x0100
134 #define	G_PART_PARM_START	0x0200
135 #define	G_PART_PARM_TYPE	0x0400
136 #define	G_PART_PARM_VERSION	0x0800
137 
138 struct g_part_parms {
139 	unsigned int	gpp_parms;
140 	unsigned int	gpp_entries;
141 	const char	*gpp_flags;
142 	struct g_geom	*gpp_geom;
143 	unsigned int	gpp_index;
144 	const char	*gpp_label;
145 	struct g_provider *gpp_provider;
146 	struct g_part_scheme *gpp_scheme;
147 	quad_t		gpp_size;
148 	quad_t		gpp_start;
149 	const char	*gpp_type;
150 	unsigned int	gpp_version;
151 };
152 
153 void g_part_geometry_heads(off_t, u_int, off_t *, u_int *);
154 
155 #endif /* !_GEOM_PART_H_ */
156