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