G_DATA(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’Ύ 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 length argument 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: DFLTPHYS is 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