G_DATA(9)
πΎ G_DATA(9) β bestie's guide to reading & writing GEOM data π
okay so this is the g_data page from the Kernel Developer's Manual, and it's literally the moment your GEOM consumer finally gets to talk to its provider. reading and writing, the whole vibe. let's get into it π«Ά
β¨ NAME β¨
g_read_data, g_write_data β read/write data from/to GEOM consumer, no cap π«
πΈ 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);
like, you include the header, you call the function, you slay. that's the whole thing π
π¦ DESCRIPTION π¦
the read one π
g_read_data() reads length bytes of data from the provider attached to consumer cp, starting at offset offset. iconic behaviour honestly.
the buffer it returns is allocated with g_malloc(), so you (yes, you, the caller) have to free it with g_free() after use. don't be that person who leaks π«
if the operation fails, an error value gets stored in the error argument β but only if error isn't NULL. so like, pass it or don't, your call, but passing it is giving responsible main character energy β¨
the write one π
g_write_data() writes length bytes of data from the buffer pointed to by ptr to the provider attached to consumer cp, starting at offset offset. same energy, opposite direction. π«
π RESTRICTIONS/CONDITIONS π
okay here's the vibe check, and you cannot skip this part:
- the
lengthargument should be a multiple of the provider's sectorsize β like, non-negotiable, that's the rule π - and it should be less than or equal to
DFLTPHYS(side note:DFLTPHYSis defined in<sys/param.h>, iykyk) - the topology lock must not be held. like, at all. don't even think about it π
bestie please respect the sectorsize thing. the kernel is not gonna be cute about it. π
β RETURN VALUES β
g_read_data() hands you back a pointer to a data buffer, or NULL if something went wrong π. in that failure case, an error value lands in the error argument β unless error is NULL, in which case it just goes nowhere, which is honestly kind of sad but that's the design.
g_write_data() returns 0 if it worked (slay π); otherwise it returns an error code. so like, 0 = good, anything else = go read the errors section.
π₯ ERRORS π₯
possible errors, spelled out for you:
[EIO]β an I/O error occurred while reading from or writing to the consumer. the disk said no π[EINTEGRITY]β corrupted data was detected while reading from the consumer. your data arrived and it was not it. π¬
π§ SEE ALSO π§
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)
like, the whole GEOM friend group honestly π
π AUTHORS π
this manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. credit where credit is due, king π
and that's the page!! this one's from the FreeBSD kernel developer world β the Debian build of it is dated March 30, 2020 β so go forth, read some sectors, write some sectors, free your buffers, and stay hydrated bestie ππ
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms