1.\" 2.\" Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org> 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.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.Dd January 16, 2004 28.Dt DECLARE_GEOM_CLASS 9 29.Os 30.Sh NAME 31.Nm DECLARE_GEOM_CLASS 32.Nd "GEOM class declaration macro" 33.Sh SYNOPSIS 34.In geom/geom.h 35.Fn DECLARE_GEOM_CLASS "class" "mod_name" 36.Sh DESCRIPTION 37The 38.Fn DECLARE_GEOM_CLASS 39macro registers a GEOM class in GEOM. 40A GEOM class itself implements one particular kind of transformation. 41Typical examples are: MBR disk partition, BSD disklabel and RAID5 classes. 42.Fn DECLARE_GEOM_CLASS 43can be used both for compiled in and loaded as 44.Xr kld 4 45modules GEOM classes and it is the only official way for class registration. 46.Pp 47The arguments to 48.Fn DECLARE_GEOM_CLASS 49are: 50.Bl -inset -offset indent 51.It Em class 52is the 53.Vt g_class 54structure which describes a GEOM class. 55.It Em mod_name 56is a kernel module name (not a class name!). 57.El 58.Pp 59Structure 60.Vt g_class 61contains data describing the class. 62They are: 63.Bl -inset -offset indent 64.It Vt "const char *" Va name 65Class name. 66.It Vt "g_taste_t *" Va taste 67Pointer to function used for taste event handling. 68If it is 69.No non- Ns Dv NULL 70it is called in three situations: 71.Bl -dash -offset indent -compact 72.It 73On class activation, all existing providers are offered for tasting. 74.It 75When new provider is created it is offered for tasting. 76.It 77After last write access to a provider is closed it is offered for retasting 78(on first write open event 79.Dq spoil 80was sent). 81.El 82.It Vt "g_config_t *" Va config 83This field is not used anymore, its functionality was replaced by the 84.Va ctlreq 85field. 86.It Vt "g_ctl_req_t *" Va ctlreq 87Pointer to function used for handling events from userland applications. 88.It Vt "g_init_t *" Va init 89Pointer to function which is called right after class registration. 90.It Vt "g_fini_t *" Va fini 91Pointer to function which is called right before class deregistration. 92.It Vt "g_ctl_destroy_geom_t *" Va destroy_geom 93Pointer to a function which is called for every geom on class unload. 94If this field is not set, the class can not be unloaded. 95.El 96.Pp 97Only field 98.Fa name 99is required, the rest is optional. 100.Pp 101.Sh RESTRICTIONS/CONDITIONS 102In the 103.Vt g_class 104initialization one must use C99 initialization (just like in the example below). 105.Pp 106.Sh EXAMPLES 107Example class declaration. 108.Bd -literal -offset indent 109static struct geom * 110g_example_taste(struct g_class *mp, struct g_provider *pp, 111 int flags __unused) 112{ 113 g_topology_assert(); 114 115 [...] 116} 117 118static void 119g_example_ctlreq(struct gctl_req *req, struct g_class *cp, 120 char const *verb) 121{ 122 123 [...] 124} 125 126static int 127g_example_destroy_geom(struct gctl_req *req, struct g_class *cp, 128 struct g_geom *gp) 129{ 130 131 g_topology_assert(); 132 133 [...] 134} 135 136static void 137g_example_init(struct g_class *mp) 138{ 139 140 [...] 141} 142 143static void 144g_example_fini(struct g_class *mp) 145{ 146 147 [...] 148} 149 150struct g_class example_class = { 151 .name = "EXAMPLE", 152 .taste = g_example_taste, 153 .ctlreq = g_example_ctlreq, 154 .init = g_example_init, 155 .fini = g_example_fini, 156 .destroy_geom = g_example_destroy_geom 157}; 158 159DECLARE_GEOM_CLASS(example_class, g_example); 160.Ed 161.Sh SEE ALSO 162.Xr geom 4 , 163.Xr g_attach 9 , 164.Xr g_bio 9 , 165.Xr g_consumer 9 , 166.Xr g_data 9 , 167.Xr g_event 9 , 168.Xr g_geom 9 , 169.Xr g_provider 9 , 170.Xr g_provider_by_name 9 , 171.Xr g_wither_geom 9 172.Sh AUTHORS 173.An -nosplit 174This manual page was written by 175.An Pawel Jakub Dawidek Aq pjd@FreeBSD.org . 176