G_GEOM(9)
π G_GEOM(9) β the kernel dev manual, but make it make sense π
okay so bestie, welcome to the g_geom page from the Kernel Developer's Manual. yes it's section 9. yes that's the big-kid section. we're doing geom management today and honestly? it's giving main character energy. π
β¨ NAME β¨
g_new_geomf, g_destroy_geom β geom management
like. that's the whole vibe. making geoms, unmaking geoms. π
π¦ SYNOPSIS π¦
#include <geom/geom.h>
struct g_geom *
g_new_geomf(struct g_class *mp, const char *fmt, ...);
void
g_destroy_geom(struct g_geom *gp);
πΈ DESCRIPTION πΈ
So. A geom (and pls do not confuse βgeomβ with βGEOMβ, they are not the same thing, iykyk) is an instance of a GEOM class. Example time: in a typical i386 FreeBSD system, there's gonna be one geom of class MBR for every single disk. one per disk. that's the whole thing.
And here's the tea β the geom's name is not really important. it's only used in the XML dump and for debugging purposes. There can be many geoms with the same name. no cap. duplicate names everywhere and nobody's mad about it. π«Ά
The g_new_geomf() function creates a new geom, which will be an instance of the class mp. The geom's name gets created in a printf(3)-like way from the rest of the arguments. so it's format-string girlie behaviour. β¨
The g_destroy_geom() function destroys the given geom immediately and cancels all related pending events. instant. no waiting around. π
π the g_geom structure fields π
okay so the g_geom structure has fields that should be set by the caller after geom creation, but before creating any providers or consumers related to this geom. and ngl, not all of them are required β but here's the full list:
g_start_t * startβ Pointer to a function used for I/O processing.g_spoiled_t * spoiledβ Pointer to a function used for consumers spoiling.g_dumpconf_t * dumpconfβ Pointer to a function used for configuration in XML format dumping.g_access_t * accessβ Pointer to a function used for access control.g_orphan_t * orphanβ Pointer to a function used to inform about orphaned consumer.g_ioctl_t * ioctlβ Pointer to a function used for handling ioctl requests.void * softcβ Field for private use.
set them early, bestie. don't be the girl who sets start after making providers. π
π₯ RESTRICTIONS/CONDITIONS π₯
okay this is the rules section and we respect the rules. π«‘
If you intend to use providers in this geom you must set field start of your geom. periodt.
If you are planning to use consumers in your geom you must set fields orphan and access for it. both of them. not one. both. π
β g_new_geomf(): β
- Class
mpmust be valid (registered in GEOM). - The topology lock has to be held.
β g_destroy_geom(): β
- The geom cannot possess any providers.
- The geom cannot possess any consumers.
- The topology lock has to be held.
π¨ bestie listen β if you're still holding providers or consumers when you call destroy, that's not a vibe check you're gonna pass. clean up first.
π RETURN VALUES π
The g_new_geomf() function returns a pointer to the newly created geom. that's it, that's the return. iconic behaviour honestly, no weird error codes to memorise. β¨
π§ EXAMPLES π§
okay so let's create an example geom. watch and learn, babe. π
static void
g_example_start(struct bio *bp)
{
[...]
}
static void
g_example_orphan(struct g_consumer *cp)
{
g_topology_assert();
[...]
}
static void
g_example_spoiled(struct g_consumer *cp)
{
g_topology_assert();
[...]
}
static int
g_example_access(struct g_provider *pp, int dr, int dw, int de)
{
[...]
}
static struct g_geom *
create_example_geom(struct g_class *myclass)
{
struct g_geom *gp;
g_topology_lock();
gp = g_new_geomf(myclass, "example_geom");
g_topology_unlock();
gp->start = g_example_start;
gp->orphan = g_example_orphan;
gp->spoiled = g_example_spoiled;
gp->access = g_example_access;
gp->softc = NULL;
return (gp);
}
static int
destroy_example_geom(struct g_geom *gp)
{
g_topology_lock();
if (!LIST_EMPTY(&gp->provider) ||
!LIST_EMPTY(&gp->consumer)) {
g_topology_unlock();
return (EBUSY);
}
g_destroy_geom(gp);
g_topology_unlock();
return (0);
}
see how we lock, create, unlock, then set the function pointers? that's the order. do not freestyle it. π
and in the destroy path we check LIST_EMPTY(&gp->provider) and LIST_EMPTY(&gp->consumer) first and bail with EBUSY if either one's got stuff in it. queen behaviour. π
π SEE ALSO π
geom(4)DECLARE_GEOM_CLASS(9)g_access(9)g_attach(9)g_bio(9)g_consumer(9)g_data(9)g_event(9)g_provider(9)g_provider_by_name(9)g_wither_geom(9)
go read them. all of them. that's your homework bestie. π
π AUTHORS π
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. king behaviour, we love him for it. π«Ά
and that's the whole page, babe!! πΈ this one's from the Debian crew, dated April 24, 2016, and it lives in section G_GEOM(9) of the Kernel Developer's Manual. go forth and manage your geoms responsibly. 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