2 # Copyright (c) 2006-2009 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.
28 #include <sys/param.h>
30 #include <sys/malloc.h>
31 #include <sys/mutex.h>
34 #include <machine/bus.h>
35 #include <sys/systm.h>
36 #include <geom/geom.h>
37 #include <geom/part/g_part.h>
39 # The G_PART scheme interface.
43 # Default implementations of methods.
46 default_fullname(struct g_part_table *table,
47 struct g_part_entry *entry, struct sbuf *sb, const char *pfx)
51 sbuf_printf(sb, "%s%s%s", pfx, g_part_separator,
52 G_PART_NAME(table, entry, buf, sizeof(buf)));
55 static struct g_provider *
56 default_new_provider(struct g_part_table *table, struct g_geom *gp,
57 struct g_part_entry *entry, const char *pfx)
59 struct g_provider *ret;
63 G_PART_FULLNAME(table, entry, sb, pfx);
65 ret = g_new_providerf(gp, "%s", sbuf_data(sb));
71 default_add_alias(struct g_part_table *table, struct g_provider *pp,
72 struct g_part_entry *entry, const char *pfx)
77 G_PART_FULLNAME(table, entry, sb, pfx);
79 g_provider_add_alias(pp, "%s", sbuf_data(sb));
84 default_precheck(struct g_part_table *t __unused,
85 enum g_part_ctl r __unused, struct g_part_parms *p __unused)
91 default_resize(struct g_part_table *t __unused,
92 struct g_part_entry *e __unused, struct g_part_parms *p __unused)
98 default_recover(struct g_part_table *t __unused)
104 default_ioctl(struct g_part_table *table __unused, struct g_provider *pp __unused,
105 u_long cmd __unused, void *data __unused, int fflag __unused,
106 struct thread *td __unused)
112 # add() - scheme specific processing for the add verb.
114 struct g_part_table *table;
115 struct g_part_entry *entry;
116 struct g_part_parms *gpp;
119 # add_alias() - Create aliases for the partition's provider with the given
121 METHOD void add_alias {
122 struct g_part_table *table;
123 struct g_provider *pp;
124 struct g_part_entry *entry;
126 } DEFAULT default_add_alias;
128 # bootcode() - scheme specific processing for the bootcode verb.
129 METHOD int bootcode {
130 struct g_part_table *table;
131 struct g_part_parms *gpp;
134 # create() - scheme specific processing for the create verb.
136 struct g_part_table *table;
137 struct g_part_parms *gpp;
140 # destroy() - scheme specific processing for the destroy verb.
142 struct g_part_table *table;
143 struct g_part_parms *gpp;
147 METHOD void dumpconf {
148 struct g_part_table *table;
149 struct g_part_entry *entry;
154 # dumpto() - return whether the partition can be used for kernel dumps.
156 struct g_part_table *table;
157 struct g_part_entry *entry;
160 # fullname() - write the name of the given partition entry to the sbuf.
161 METHOD void fullname {
162 struct g_part_table *table;
163 struct g_part_entry *entry;
166 } DEFAULT default_fullname;
168 # ioctl() - implement historic ioctls, perhaps.
170 struct g_part_table *table;
171 struct g_provider *pp;
176 } DEFAULT default_ioctl;
178 # modify() - scheme specific processing for the modify verb.
180 struct g_part_table *table;
181 struct g_part_entry *entry;
182 struct g_part_parms *gpp;
185 # new_provider() - Create the partition's provider(s).
186 METHOD struct g_provider * new_provider {
187 struct g_part_table *table;
189 struct g_part_entry *entry;
191 } DEFAULT default_new_provider;
193 # resize() - scheme specific processing for the resize verb.
195 struct g_part_table *table;
196 struct g_part_entry *entry;
197 struct g_part_parms *gpp;
198 } DEFAULT default_resize;
200 # name() - return the name of the given partition entry.
201 # Typical names are "p1", "s0" or "c".
202 METHOD const char * name {
203 struct g_part_table *table;
204 struct g_part_entry *entry;
209 # precheck() - method to allow schemes to check the parameters given
210 # to the mentioned ctl request. This only applies to the requests that
211 # operate on a GEOM. In other words, it does not apply to the create
213 # It is allowed (intended actually) to change the parameters according
214 # to the schemes needs before they are used. Returning an error will
215 # terminate the request immediately.
216 METHOD int precheck {
217 struct g_part_table *table;
219 struct g_part_parms *gpp;
220 } DEFAULT default_precheck;
222 # probe() - probe the provider attached to the given consumer for the
223 # existence of the scheme implemented by the G_PART interface handler.
225 struct g_part_table *table;
226 struct g_consumer *cp;
229 # read() - read the on-disk partition table into memory.
231 struct g_part_table *table;
232 struct g_consumer *cp;
235 # recover() - scheme specific processing for the recover verb.
237 struct g_part_table *table;
238 } DEFAULT default_recover;
240 # setunset() - set or unset partition entry attributes.
241 METHOD int setunset {
242 struct g_part_table *table;
243 struct g_part_entry *entry;
248 # type() - return a string representation of the partition type.
249 # Preferably, the alias names.
250 METHOD const char * type {
251 struct g_part_table *table;
252 struct g_part_entry *entry;
257 # write() - write the in-memory partition table to disk.
259 struct g_part_table *table;
260 struct g_consumer *cp;