DECLARE_GEOM_CLASS(9)
π DECLARE_GEOM_CLASS(9) β the DECLARE_GEOM_CLASS manual page, but make it cute π
okay so bestie, welcome to DECLARE_GEOM_CLASS(9) from the Kernel Developer's Manual β¨ this is the one that teaches you how to declare a GEOM class, and it is literally the official way, no cap. pull up a chair, grab a strawberry π, let's go.
πΈ NAME πΈ
DECLARE_GEOM_CLASS β the GEOM class declaration macro. that's it, that's the whole vibe. π
π SYNOPSIS π
#include <geom/geom.h>
DECLARE_GEOM_CLASS(class, mod_name);
β¨ DESCRIPTION β¨
so the DECLARE_GEOM_CLASS() macro registers a GEOM class in GEOM. and a GEOM class? it implements one particular kind of transformation. one job, main character energy, we love that for it. π¦
typical examples are: MBR disk partition, BSD disklabel and RAID5 classes. iconic lineup honestly.
and here's the tea β: DECLARE_GEOM_CLASS() can be used both for compiled in and for loaded as kld(4) modules GEOM classes. and it is the only official way for class registration. periodt. no sneaky backdoors, no DIY, this is the door. πͺ
π§ the arguments, bestie π§
classβ theg_classstructure which describes a GEOM class.mod_nameβ a kernel module name (not a class name!). yes girl, read that twice. it's the module name, not the class name. π
π structure g_class π
the g_class structure 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 thectlreqfield. rip to it, it's giving deprecated πͺ¦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.
and the best part?? only a name field is required β the rest are optional. so you can absolutely start with just a name and vibe, then add the rest when you're ready. lowkey freeing. π«Ά
π RESTRICTIONS/CONDITIONS π
The fields of g_class should always be initialized using C99-style field naming (see the initialization of example_class below). not optional, bestie. do it properly or the compiler will simply look at you. π
π₯ EXAMPLES π₯
Example class declaration. copy this energy, not the code (well, also the code, it's literally the example):
static struct g_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 how every field is named?? C99-style field naming, exactly like the restrictions said. she practices what she preaches. π β¨
π SEE ALSO π
geom(4)g_attach(9)g_bio(9)g_consumer(9)g_data(9)g_event(9)g_geom(9)g_provider(9)g_provider_by_name(9)g_wither_geom(9)
go read them, they're all besties in the same friend group. πΈ
π«Ά AUTHORS π«Ά
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. thank you king for the lore π
and that's the whole page bestie!! π this was the Debian version, dated August 13, 2007, filed under DECLARE_GEOM_CLASS(9). go declare a class, slay, and remember: name is required, everything else is optional, and mod_name is the module name. iykyk. mwah ππβ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms