xref: /freebsd/sys/geom/part/g_part_if.m (revision 830940567b49bb0c08dfaed40418999e76616909)
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
63# add() - scheme specific processing for the add verb.
64METHOD int add {
65	struct g_part_table *table;
66	struct g_part_entry *entry;
67	struct g_part_parms *gpp;
68};
69
70# bootcode() - scheme specific processing for the bootcode verb.
71METHOD int bootcode {
72	struct g_part_table *table;
73	struct g_part_parms *gpp;
74};
75
76# create() - scheme specific processing for the create verb.
77METHOD int create {
78	struct g_part_table *table;
79	struct g_part_parms *gpp;
80};
81
82# destroy() - scheme specific processing for the destroy verb.
83METHOD int destroy {
84	struct g_part_table *table;
85	struct g_part_parms *gpp;
86};
87
88# dumpconf()
89METHOD void dumpconf {
90	struct g_part_table *table;
91	struct g_part_entry *entry;
92	struct sbuf *sb;
93	const char *indent;
94};
95
96# dumpto() - return whether the partiton can be used for kernel dumps.
97METHOD int dumpto {
98	struct g_part_table *table;
99	struct g_part_entry *entry;
100};
101
102# fullname() - write the name of the given partition entry to the sbuf.
103METHOD void fullname {
104	struct g_part_table *table;
105	struct g_part_entry *entry;
106	struct sbuf *sb;
107	const char *pfx;
108} DEFAULT default_fullname;
109
110# modify() - scheme specific processing for the modify verb.
111METHOD int modify {
112	struct g_part_table *table;
113	struct g_part_entry *entry;
114	struct g_part_parms *gpp;
115};
116
117# name() - return the name of the given partition entry.
118# Typical names are "p1", "s0" or "c".
119METHOD const char * name {
120	struct g_part_table *table;
121	struct g_part_entry *entry;
122	char *buf;
123	size_t bufsz;
124};
125
126# precheck() - method to allow schemes to check the parameters given
127# to the mentioned ctl request. This only applies to the requests that
128# operate on a GEOM. In other words, it does not apply to the create
129# request.
130# It is allowed (intended actually) to change the parameters according
131# to the schemes needs before they are used. Returning an error will
132# terminate the request immediately.
133METHOD int precheck {
134	struct g_part_table *table;
135	enum g_part_ctl req;
136	struct g_part_parms *gpp;
137} DEFAULT default_precheck;
138
139# probe() - probe the provider attached to the given consumer for the
140# existence of the scheme implemented by the G_PART interface handler.
141METHOD int probe {
142	struct g_part_table *table;
143	struct g_consumer *cp;
144};
145
146# read() - read the on-disk partition table into memory.
147METHOD int read {
148	struct g_part_table *table;
149	struct g_consumer *cp;
150};
151
152# setunset() - set or unset partition entry attributes.
153METHOD int setunset {
154	struct g_part_table *table;
155	struct g_part_entry *entry;
156	const char *attrib;
157	unsigned int set;
158};
159
160# type() - return a string representation of the partition type.
161# Preferrably, the alias names.
162METHOD const char * type {
163        struct g_part_table *table;
164        struct g_part_entry *entry;
165        char *buf;
166        size_t bufsz;
167};
168
169# write() - write the in-memory partition table to disk.
170METHOD int write {
171	struct g_part_table *table;
172	struct g_consumer *cp;
173};
174