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 length argument should be a multiple of the provider's sectorsize and less than or equal to DFLTPHYS (DFLTPHYS is 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:


🫢 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