---
name: "DECLARE_GEOM_CLASS"
section: "9"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/DECLARE_GEOM_CLASS"
---

# DECLARE\_GEOM\_CLASS(9)

GEOM class declaration macro

## NAME

**DECLARE\_GEOM\_CLASS** – GEOM class declaration macro

## SYNOPSIS

**#include \<geom/geom.h\>**

**DECLARE\_GEOM\_CLASS**(*class*, *mod\_name*);

## DESCRIPTION

The **DECLARE\_GEOM\_CLASS**() macro registers a GEOM class in GEOM. A GEOM class itself implements one particular kind of transformation. Typical examples are: MBR disk partition, BSD disklabel and RAID5 classes. **DECLARE\_GEOM\_CLASS**() can be used both for compiled in and loaded as [kld(4)](/kld/4.md) modules GEOM classes and it is the only official way for class registration.

The arguments to **DECLARE\_GEOM\_CLASS**() are:

- *class*

  The *g\_class* structure which describes a GEOM class.

- *mod\_name*

  A kernel module name (not a class name!).

Structure *g\_class* contains data describing the class. They are:

- *const char \** *name*

  Class name.

- *g\_taste\_t \** *taste*

  Pointer to function used for taste event handling. If it is non-NULL it is called in three situations:

  - On class activation, all existing providers are offered for tasting.

  - When new provider is created it is offered for tasting.

  - After last write access to a provider is closed it is offered for retasting (on first write open event “spoil” was sent).

- *g\_config\_t \** *config*

  This field is not used anymore, its functionality was replaced by the *ctlreq* field.

- *g\_ctl\_req\_t \** *ctlreq*

  Pointer to function used for handling events from userland applications.

- *g\_init\_t \** *init*

  Pointer to function which is called right after class registration.

- *g\_fini\_t \** *fini*

  Pointer to function which is called right before class deregistration.

- *g\_ctl\_destroy\_geom\_t \** *destroy\_geom*

  Pointer to a function which is called for every geom on class unload. If this field is not set, the class can not be unloaded.

Only a *name* field is required; the rest are optional.

## RESTRICTIONS/CONDITIONS

The fields of *g\_class* should always be initialized using C99-style field naming (see the initialization of *example\_class* below).

## EXAMPLES

Example class declaration.

```
static struct geom *
g_example_taste(struct g_class *mp, struct g_provider *pp,
    int flags __unused)
{
	g_topology_assert();
	[...]
}
static void
g_example_ctlreq(struct gctl_req *req, struct g_class *cp,
    char const *verb)
{
	[...]
}
static int
g_example_destroy_geom(struct gctl_req *req, struct g_class *cp,
    struct g_geom *gp)
{
	g_topology_assert();
	[...]
}
static void
g_example_init(struct g_class *mp)
{
	[...]
}
static void
g_example_fini(struct g_class *mp)
{
	[...]
}
struct g_class example_class = {
	.name = "EXAMPLE",
	.taste = g_example_taste,
	.ctlreq = g_example_ctlreq,
	.init = g_example_init,
	.fini = g_example_fini,
	.destroy_geom = g_example_destroy_geom
};
DECLARE_GEOM_CLASS(example_class, g_example);
```

## SEE ALSO

[geom(4)](/geom/4.md), [g\_attach(9)](/g_attach/9.md), [g\_bio(9)](/g_bio/9.md), [g\_consumer(9)](/g_consumer/9.md), [g\_data(9)](/g_data/9.md), [g\_event(9)](/g_event/9.md), [g\_geom(9)](/g_geom/9.md), [g\_provider(9)](/g_provider/9.md), [g\_provider\_by\_name(9)](/g_provider_by_name/9.md), [g\_wither\_geom(9)](/g_wither_geom/9.md)

## AUTHORS

This manual page was written by Pawel Jakub Dawidek ⟨pjd@FreeBSD.org⟩.
