2 * Copyright (c) 2006-2008 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 #define G_PART_TRACE(args) g_trace args
34 #define G_PART_PROBE_PRI_LOW -10
35 #define G_PART_PROBE_PRI_NORM -5
36 #define G_PART_PROBE_PRI_HIGH 0
39 G_PART_ALIAS_APPLE_BOOT, /* An Apple boot partition entry. */
40 G_PART_ALIAS_APPLE_HFS, /* An HFS+ file system entry. */
41 G_PART_ALIAS_APPLE_LABEL, /* An Apple label partition entry. */
42 G_PART_ALIAS_APPLE_RAID, /* An Apple RAID partition entry. */
43 G_PART_ALIAS_APPLE_RAID_OFFLINE,/* An Apple RAID (offline) part entry.*/
44 G_PART_ALIAS_APPLE_TV_RECOVERY, /* An Apple TV recovery part entry. */
45 G_PART_ALIAS_APPLE_UFS, /* An Apple UFS partition entry. */
46 G_PART_ALIAS_EFI, /* A EFI system partition entry. */
47 G_PART_ALIAS_FREEBSD, /* A BSD labeled partition entry. */
48 G_PART_ALIAS_FREEBSD_BOOT, /* A FreeBSD boot partition entry. */
49 G_PART_ALIAS_FREEBSD_SWAP, /* A swap partition entry. */
50 G_PART_ALIAS_FREEBSD_UFS, /* A UFS/UFS2 file system entry. */
51 G_PART_ALIAS_FREEBSD_VINUM, /* A Vinum partition entry. */
52 G_PART_ALIAS_FREEBSD_ZFS, /* A ZFS file system entry. */
53 G_PART_ALIAS_MBR, /* A MBR (extended) partition entry. */
54 G_PART_ALIAS_LINUX_DATA, /* A Linux data partition entry. */
55 G_PART_ALIAS_LINUX_LVM, /* A Linux LVM partition entry. */
56 G_PART_ALIAS_LINUX_RAID, /* A Linux RAID partition entry. */
57 G_PART_ALIAS_LINUX_SWAP, /* A Linux swap partition entry. */
58 /* Keep the following last */
62 const char *g_part_alias_name(enum g_part_alias);
64 /* G_PART scheme (KOBJ class). */
65 struct g_part_scheme {
71 TAILQ_ENTRY(g_part_scheme) scheme_list;
75 LIST_ENTRY(g_part_entry) gpe_entry;
76 struct g_provider *gpe_pp; /* Corresponding provider. */
77 off_t gpe_offset; /* Byte offset. */
78 quad_t gpe_start; /* First LBA of partition. */
79 quad_t gpe_end; /* Last LBA of partition. */
81 int gpe_created:1; /* Entry is newly created. */
82 int gpe_deleted:1; /* Entry has been deleted. */
83 int gpe_modified:1; /* Entry has been modified. */
84 int gpe_internal:1; /* Entry is not a used entry. */
87 /* G_PART table (KOBJ instance). */
90 struct g_part_scheme *gpt_scheme;
91 struct g_geom *gpt_gp;
92 LIST_HEAD(, g_part_entry) gpt_entry;
93 quad_t gpt_first; /* First allocatable LBA */
94 quad_t gpt_last; /* Last allocatable LBA */
97 * gpt_smhead and gpt_smtail are bitmaps representing the first
98 * 32 sectors on the disk (gpt_smhead) and the last 32 sectors
99 * on the disk (gpt_smtail). These maps are used by the commit
100 * verb to clear sectors previously used by a scheme after the
101 * partitioning scheme has been destroyed.
106 * gpt_sectors and gpt_heads are the fixed or synchesized number
107 * of sectors per track and heads (resp) that make up a disks
108 * geometry. This is to support partitioning schemes as well as
109 * file systems that work on a geometry. The MBR scheme and the
110 * MS-DOS (FAT) file system come to mind.
111 * We keep track of whether the geometry is fixed or synchesized
112 * so that a partitioning scheme can correct the synthesized
113 * geometry, based on the on-disk metadata.
115 uint32_t gpt_sectors;
118 int gpt_depth; /* Sub-partitioning level. */
119 int gpt_isleaf:1; /* Cannot be sub-partitioned. */
120 int gpt_created:1; /* Newly created. */
121 int gpt_modified:1; /* Table changes have been made. */
122 int gpt_opened:1; /* Permissions obtained. */
123 int gpt_fixgeom:1; /* Geometry is fixed. */
126 struct g_part_entry *g_part_new_entry(struct g_part_table *, int, quad_t,
146 /* G_PART ctlreq parameters. */
147 #define G_PART_PARM_ENTRIES 0x0001
148 #define G_PART_PARM_FLAGS 0x0002
149 #define G_PART_PARM_GEOM 0x0004
150 #define G_PART_PARM_INDEX 0x0008
151 #define G_PART_PARM_LABEL 0x0010
152 #define G_PART_PARM_OUTPUT 0x0020
153 #define G_PART_PARM_PROVIDER 0x0040
154 #define G_PART_PARM_SCHEME 0x0080
155 #define G_PART_PARM_SIZE 0x0100
156 #define G_PART_PARM_START 0x0200
157 #define G_PART_PARM_TYPE 0x0400
158 #define G_PART_PARM_VERSION 0x0800
159 #define G_PART_PARM_BOOTCODE 0x1000
160 #define G_PART_PARM_ATTRIB 0x2000
162 struct g_part_parms {
163 unsigned int gpp_parms;
164 unsigned int gpp_entries;
165 const char *gpp_flags;
166 struct g_geom *gpp_geom;
167 unsigned int gpp_index;
168 const char *gpp_label;
169 struct g_provider *gpp_provider;
170 struct g_part_scheme *gpp_scheme;
173 const char *gpp_type;
174 unsigned int gpp_version;
175 const void *gpp_codeptr;
176 unsigned int gpp_codesize;
177 const char *gpp_attrib;
180 void g_part_geometry_heads(off_t, u_int, off_t *, u_int *);
182 int g_part_modevent(module_t, int, struct g_part_scheme *);
184 #define G_PART_SCHEME_DECLARE(name) \
185 static int name##_modevent(module_t mod, int tp, void *d) \
187 return (g_part_modevent(mod, tp, d)); \
189 static moduledata_t name##_mod = { \
194 DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
196 #endif /* !_GEOM_PART_H_ */