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.Dd August 13, 2007 26.Dt DECLARE_GEOM_CLASS 9 27.Os 28.Sh NAME 29.Nm DECLARE_GEOM_CLASS 30.Nd "GEOM class declaration macro" 31.Sh SYNOPSIS 32.In geom/geom.h 33.Fn DECLARE_GEOM_CLASS "class" "mod_name" 34.Sh DESCRIPTION 35The 36.Fn DECLARE_GEOM_CLASS 37macro registers a GEOM class in GEOM. 38A GEOM class itself implements one particular kind of transformation. 39Typical examples are: MBR disk partition, 40.Bx 41disklabel 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 -tag -offset indent -width Fa 51.It Fa class 52The 53.Vt g_class 54structure which describes a GEOM class. 55.It Fa mod_name 56A 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 -tag -offset indent -width 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.Pf non- Dv NULL 70it is called in three situations: 71.Pp 72.Bl -dash -compact 73.It 74On class activation, all existing providers are offered for tasting. 75.It 76When new provider is created it is offered for tasting. 77.It 78After last write access to a provider is closed it is offered for retasting 79(on first write open event 80.Dq spoil 81was sent). 82.El 83.It Vt "g_config_t *" Va config 84This field is not used anymore, its functionality was replaced by the 85.Va ctlreq 86field. 87.It Vt "g_ctl_req_t *" Va ctlreq 88Pointer to function used for handling events from userland applications. 89.It Vt "g_init_t *" Va init 90Pointer to function which is called right after class registration. 91.It Vt "g_fini_t *" Va fini 92Pointer to function which is called right before class deregistration. 93.It Vt "g_ctl_destroy_geom_t *" Va destroy_geom 94Pointer to a function which is called for every geom on class unload. 95If this field is not set, the class can not be unloaded. 96.El 97.Pp 98Only a 99.Fa name 100field is required; the rest are optional. 101.Sh RESTRICTIONS/CONDITIONS 102The fields of 103.Vt g_class 104should always be initialized using C99-style field naming 105(see the initialization of 106.Va example_class 107below). 108.Sh EXAMPLES 109Example class declaration. 110.Bd -literal -offset indent 111static struct g_geom * 112g_example_taste(struct g_class *mp, struct g_provider *pp, 113 int flags __unused) 114{ 115 g_topology_assert(); 116 117 [...] 118} 119 120static void 121g_example_ctlreq(struct gctl_req *req, struct g_class *cp, 122 char const *verb) 123{ 124 125 [...] 126} 127 128static int 129g_example_destroy_geom(struct gctl_req *req, struct g_class *cp, 130 struct g_geom *gp) 131{ 132 133 g_topology_assert(); 134 135 [...] 136} 137 138static void 139g_example_init(struct g_class *mp) 140{ 141 142 [...] 143} 144 145static void 146g_example_fini(struct g_class *mp) 147{ 148 149 [...] 150} 151 152struct g_class example_class = { 153 .name = "EXAMPLE", 154 .taste = g_example_taste, 155 .ctlreq = g_example_ctlreq, 156 .init = g_example_init, 157 .fini = g_example_fini, 158 .destroy_geom = g_example_destroy_geom 159}; 160 161DECLARE_GEOM_CLASS(example_class, g_example); 162.Ed 163.Sh SEE ALSO 164.Xr geom 4 , 165.Xr g_attach 9 , 166.Xr g_bio 9 , 167.Xr g_consumer 9 , 168.Xr g_data 9 , 169.Xr g_event 9 , 170.Xr g_geom 9 , 171.Xr g_provider 9 , 172.Xr g_provider_by_name 9 , 173.Xr g_wither_geom 9 174.Sh AUTHORS 175.An -nosplit 176This manual page was written by 177.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org . 178