G_DATA(9)
π G_DATA(9) π
okay bestie so we're in the Kernel Developer's Manual rn and this page is literally called G_DATA(9) and it's about the two lil helper functions that let you yank data off a GEOM consumer and shove data back onto it π yes it's kernel stuff, yes it's iconic, no you don't need to be scared, i got you π«Ά
β¨ NAME β¨
g_read_data, g_write_data β read/write data from/to GEOM consumer
πΈ SYNOPSIS πΈ
#include <geom/geom.h>
void *
g_read_data(struct g_consumer *cp, off_t offset, off_t length,
int *error);
int
g_write_data(struct g_consumer *cp, off_t offset, void *ptr,
off_t length);
π DESCRIPTION π
so the way this works is two functions, one for reading, one for writing, and they're both extremely straightforward bestie, no cap.
The g_read_data() function reads length bytes of data from the provider attached to consumer cp, starting at offset offset. That's it, that's the vibe π¦
And listen β the buffer that comes back from g_read_data() is allocated with g_malloc(), so you, the caller, have to free it with g_free() after use. don't be the person who leaks memory, that's not main character energy π
If the operation fails, an error value will be stored in the error argument β but only if it's not NULL. so if you passed NULL in there, you get nothing, no notes, that's on you π
The g_write_data() function writes length bytes of data from the buffer pointed to by ptr to the provider attached to consumer cp, starting at offset offset. push it out into the world, slay β¨
β οΈ RESTRICTIONS/CONDITIONS β οΈ
okay this is the part where you actually pay attention, bestie, because these are the rules and they are not optional π¨
- The
lengthargument should be a multiple of the provider's sectorsize and less than or equal toDFLTPHYS(DFLTPHYSis defined in<sys/param.h>). fr fr, check it before you call. - The topology lock must not be held. like, do not. that's it, that's the whole rule π
π RETURN VALUES π
The g_read_data() function returns a pointer to a data buffer or NULL if an error occurred. In that case an error value is stored in the error argument unless it is NULL. so NULL means something went wrong, and if you handed it an error pointer it'll tell you what π€
The g_write_data() function returns 0 if successful; otherwise an error code is returned. zero is the good number, we love zero, zero ate π
π ERRORS π
Possible errors, and yes these are the real ones:
[EIO]β An I/O error occurred while reading from or writing to the consumer. the hardware said no, basically.[EINTEGRITY]β Corrupted data was detected while reading from the consumer. the data showed up and it was Not Okay π
π₯ SEE ALSO π₯
all the besties this page hangs out with:
geom(4)DECLARE_GEOM_CLASS(9)g_access(9)g_attach(9)g_bio(9)g_consumer(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 π«‘π
quick reminder bestie: read the RESTRICTIONS section twice. the topology lock thing is not a joke. π
and that's the whole page, we're done!! this one came out of Debian and it's dated March 30, 2020 β G_DATA(9), periodt πβ¨π
π¦ 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-2005 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