G_ACCESS(9)
๐ G_ACCESS(9) ๐
okay bestie, gather round, because today we're talking about g_access โ a page straight out of the Kernel Developer's Manual, and it's literally the bouncer at the club that is your GEOM provider. let's get into it โจ
๐ธ NAME ๐ธ
g_access โ control access to GEOM consumers and their providers
โจ SYNOPSIS โจ
#include <geom/geom.h>
int
g_access(struct g_consumer *cp, int dcr, int dcw, int dce);
๐ฆ DESCRIPTION ๐ฆ
so the g_access() function is your girl for opening, closing, and generally messing with access to the provider that's attached to the consumer cp you handed her. she's flexible like that ๐
the three args โ dcr, dcw, and dce โ are the relative changes to the read, write, and exclusive access counts. read and write are pretty self-explanatory bestie, like obviously. and exclusive access counts? those deny write access to other interested parties. no sharing, no gatecrashing, periodt. ๐ฅ
also important: a provider's access count is the sum of the access counts of all attached consumers. math! ๐งฎ
and listen โ after you attach a consumer to a provider with g_attach(9), you have to call g_access() on that consumer before you start doing any I/O requests. no skipping steps, bestie, that's not the vibe ๐
๐ RESTRICTIONS/CONDITIONS ๐
the rules, the non-negotiables, the vibe check:
- the consumer has to be attached to a provider. non-optional.
- the intended change must not result in a negative access count. don't go below zero, it's giving undefined chaos.
- no-operation is not permitted (
dcr = dcw = dce = 0). doing nothing is not a flex here. - the provider's geom must have an access method defined (e.g.,
gp->access). it needs the method, bestie. - the topology lock has to be held. hold it. hold it tight. ๐ซถ
๐ RETURN VALUES ๐
g_access() returns 0 if everything slayed; otherwise you get an error code back. ๐ญ
and here's a cute lil note: g_access() cannot fail when the arguments dcr, dcw, and dce are less than or equal to 0. so closing down? always safe. iconic behaviour honestly.
๐ EXAMPLES ๐
okay so here's the whole main-character arc: create a consumer, attach it to a given provider, gain read access, and read the first sector. watch her work:
void
some_function(struct g_geom *mygeom, struct g_provider *pp)
{
struct g_consumer *cp;
void *ptr;
int error;
g_topology_assert();
/* Create new consumer on 'mygeom' geom. */
cp = g_new_consumer(mygeom);
/* Attach newly created consumer to given provider. */
if (g_attach(cp, pp) != 0) {
g_destroy_consumer(cp);
return;
}
/* Open provider for reading through our consumer. */
error = g_access(cp, 1, 0, 0);
if (error != 0) {
printf("Cannot access provider: %s\n", error);
g_detach(cp);
g_destroy_consumer(cp);
return;
}
/*
* Don't hold topology lock while reading.
*/
g_topology_unlock();
ptr = g_read_data(cp, 0, pp->sectorsize, &error);
if (ptr == NULL)
printf("Error while reading: %d\n", error);
/*
* Do something useful with data.
*/
g_topology_lock();
/* Disconnect from provider (release access count). */
g_access(cp, -1, 0, 0);
/* Detach from provider. */
g_detach(cp);
/* Destroy consumer. */
g_destroy_consumer(cp);
}
likeโฆ the cleanup arc alone? chef's kiss. notice how she unlocks the topology lock while reading and locks it right back after? that's the etiquette bestie, don't read while holding the lock ๐
๐ ERRORS ๐
possible errors, and yes we're naming names:
[EPERM]โ the function is trying to open a provider with an exclusive access count, but it is already open for writing. awkward![EPERM]โ the function is trying to open a provider for writing, but it is already exclusively open. also awkward!
plus: any other error that can be returned by the provider's access method. so like, whatever the provider's method decides to throw at you, that's fair game. ๐คท
๐ SEE ALSO ๐
go read these next, i'm obsessed:
geom(4), DECLARE_GEOM_CLASS(9), 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)
๐ AUTHORS ๐
this manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. thank you for your service, king ๐ซก
and that's the whole page bestie!! this little cutie comes from the Debian side of the world, dated January 16, 2004 โ old but gold, fr fr. now go hold that topology lock and slay ๐ โจ๐ธ
๐ฆ 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