xref: /freebsd/sys/geom/part/g_part_if.m (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1#-
2# Copyright (c) 2006-2009 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
27#include <sys/param.h>
28#include <sys/lock.h>
29#include <sys/malloc.h>
30#include <sys/mutex.h>
31#include <sys/sbuf.h>
32#include <sys/bus.h>
33#include <machine/bus.h>
34#include <sys/systm.h>
35#include <geom/geom.h>
36#include <geom/part/g_part.h>
37
38# The G_PART scheme interface.
39
40INTERFACE g_part;
41
42# Default implementations of methods.
43CODE {
44	static void
45	default_fullname(struct g_part_table *table,
46	    struct g_part_entry *entry, struct sbuf *sb, const char *pfx)
47	{
48		char buf[32];
49
50		sbuf_printf(sb, "%s%s%s", pfx, g_part_separator,
51		    G_PART_NAME(table, entry, buf, sizeof(buf)));
52	}
53
54	static struct g_provider *
55	default_new_provider(struct g_part_table *table, struct g_geom *gp,
56	    struct g_part_entry *entry, const char *pfx)
57	{
58		struct g_provider *ret;
59		struct sbuf *sb;
60
61		sb = sbuf_new_auto();
62		G_PART_FULLNAME(table, entry, sb, pfx);
63		sbuf_finish(sb);
64		ret = g_new_providerf(gp, "%s", sbuf_data(sb));
65		sbuf_delete(sb);
66		return (ret);
67	}
68
69	static void
70	default_add_alias(struct g_part_table *table, struct g_provider *pp,
71	    struct g_part_entry *entry, const char *pfx)
72	{
73		struct sbuf *sb;
74
75		sb = sbuf_new_auto();
76		G_PART_FULLNAME(table, entry, sb, pfx);
77		sbuf_finish(sb);
78		g_provider_add_alias(pp, "%s", sbuf_data(sb));
79		sbuf_delete(sb);
80	}
81
82	static int
83	default_precheck(struct g_part_table *t __unused,
84	    enum g_part_ctl r __unused, struct g_part_parms *p __unused)
85	{
86		return (0);
87	}
88
89	static int
90	default_resize(struct g_part_table *t __unused,
91	    struct g_part_entry *e __unused, struct g_part_parms *p __unused)
92	{
93		return (ENOSYS);
94	}
95
96	static int
97	default_recover(struct g_part_table *t __unused)
98	{
99		return (ENOSYS);
100	}
101
102	static int
103	default_ioctl(struct g_part_table *table __unused, struct g_provider *pp __unused,
104	    u_long cmd __unused, void *data __unused, int fflag __unused,
105	    struct thread *td __unused)
106	{
107		return (ENOIOCTL);
108	}
109
110	static int
111	default_getattr(struct g_part_table *table __unused,
112	    struct g_part_entry *entry __unused, struct bio *bp __unused)
113	{
114		return (ENOIOCTL);
115	}
116};
117
118# add() - scheme specific processing for the add verb.
119METHOD int add {
120	struct g_part_table *table;
121	struct g_part_entry *entry;
122	struct g_part_parms *gpp;
123};
124
125# add_alias() - Create aliases for the partition's provider with the given
126# alias prefixes.
127METHOD void add_alias {
128	struct g_part_table *table;
129	struct g_provider *pp;
130	struct g_part_entry *entry;
131	const char *pfx;
132} DEFAULT default_add_alias;
133
134# bootcode() - scheme specific processing for the bootcode verb.
135METHOD int bootcode {
136	struct g_part_table *table;
137	struct g_part_parms *gpp;
138};
139
140# create() - scheme specific processing for the create verb.
141METHOD int create {
142	struct g_part_table *table;
143	struct g_part_parms *gpp;
144};
145
146# destroy() - scheme specific processing for the destroy verb.
147METHOD int destroy {
148	struct g_part_table *table;
149	struct g_part_parms *gpp;
150};
151
152# dumpconf()
153METHOD void dumpconf {
154	struct g_part_table *table;
155	struct g_part_entry *entry;
156	struct sbuf *sb;
157	const char *indent;
158};
159
160# dumpto() - return whether the partition can be used for kernel dumps.
161METHOD int dumpto {
162	struct g_part_table *table;
163	struct g_part_entry *entry;
164};
165
166# fullname() - write the name of the given partition entry to the sbuf.
167METHOD void fullname {
168	struct g_part_table *table;
169	struct g_part_entry *entry;
170	struct sbuf *sb;
171	const char *pfx;
172} DEFAULT default_fullname;
173
174# ioctl() - implement historic ioctls, perhaps.
175METHOD int ioctl {
176	struct g_part_table *table;
177	struct g_provider *pp;
178	u_long cmd;
179	void *data;
180	int fflag;
181	struct thread *td;
182} DEFAULT default_ioctl;
183
184# modify() - scheme specific processing for the modify verb.
185METHOD int modify {
186	struct g_part_table *table;
187	struct g_part_entry *entry;
188	struct g_part_parms *gpp;
189};
190
191# new_provider() - Create the partition's provider(s).
192METHOD struct g_provider * new_provider {
193	struct g_part_table *table;
194	struct g_geom *gp;
195	struct g_part_entry *entry;
196	const char *pfx;
197} DEFAULT default_new_provider;
198
199# resize() - scheme specific processing for the resize verb.
200METHOD int resize {
201	struct g_part_table *table;
202	struct g_part_entry *entry;
203	struct g_part_parms *gpp;
204} DEFAULT default_resize;
205
206# name() - return the name of the given partition entry.
207# Typical names are "p1", "s0" or "c".
208METHOD const char * name {
209	struct g_part_table *table;
210	struct g_part_entry *entry;
211	char *buf;
212	size_t bufsz;
213};
214
215# precheck() - method to allow schemes to check the parameters given
216# to the mentioned ctl request. This only applies to the requests that
217# operate on a GEOM. In other words, it does not apply to the create
218# request.
219# It is allowed (intended actually) to change the parameters according
220# to the schemes needs before they are used. Returning an error will
221# terminate the request immediately.
222METHOD int precheck {
223	struct g_part_table *table;
224	enum g_part_ctl req;
225	struct g_part_parms *gpp;
226} DEFAULT default_precheck;
227
228# probe() - probe the provider attached to the given consumer for the
229# existence of the scheme implemented by the G_PART interface handler.
230METHOD int probe {
231	struct g_part_table *table;
232	struct g_consumer *cp;
233};
234
235# read() - read the on-disk partition table into memory.
236METHOD int read {
237	struct g_part_table *table;
238	struct g_consumer *cp;
239};
240
241# recover() - scheme specific processing for the recover verb.
242METHOD int recover {
243	struct g_part_table *table;
244} DEFAULT default_recover;
245
246# setunset() - set or unset partition entry attributes.
247METHOD int setunset {
248	struct g_part_table *table;
249	struct g_part_entry *entry;
250	const char *attrib;
251	unsigned int set;
252};
253
254# type() - return a string representation of the partition type.
255# Preferably, the alias names.
256METHOD const char * type {
257        struct g_part_table *table;
258        struct g_part_entry *entry;
259        char *buf;
260        size_t bufsz;
261};
262
263# write() - write the in-memory partition table to disk.
264METHOD int write {
265	struct g_part_table *table;
266	struct g_consumer *cp;
267};
268
269# getattr() - get the specified attribute, if any
270METHOD int getattr {
271	struct g_part_table *table;
272	struct g_part_entry *entry;
273	struct bio *bp;
274} DEFAULT default_getattr;
275