DNV(9)

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

✨ DNV(9) ✨

okay so bestie, welcome to the dnv(9) era β€” this is the Kernel Developer's Manual page for the FreeBSD dnv API, and honestly? it's giving "default value but make it fashion" πŸ’…


🌸 LIBRARY 🌸

library "libnv" β€” yeah she's from libnv, iconic behavior only πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

not me about to dump all these function signatures on you but fr fr they're all important so pay attention bestie:

#include <sys/dnv.h>

bool
dnvlist_get_bool(const nvlist_t *nvl, const char *name, bool defval);

uint64_t
dnvlist_get_number(const nvlist_t *nvl, const char *name,
    uint64_t defval);

char *
dnvlist_get_string(const nvlist_t *nvl, const char *name,
    const char *defval);

nvlist_t *
dnvlist_get_nvlist(const nvlist_t *nvl, const char *name,
    nvlist_t *defval);

int
dnvlist_get_descriptor(const nvlist_t *nvl, const char *name,
    int defval);

void *
dnvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep,
    void *defval, size_t defsize);

bool
dnvlist_take_bool(const nvlist_t *nvl, const char *name, bool defval);

uint64_t
dnvlist_take_number(const nvlist_t *nvl, const char *name,
    uint64_t defval);

char *
dnvlist_take_string(const nvlist_t *nvl, const char *name,
    const char *defval);

nvlist_t *
dnvlist_take_nvlist(const nvlist_t *nvl, const char *name,
    nvlist_t *defval);

int
dnvlist_take_descriptor(const nvlist_t *nvl, const char *name,
    int defval);

void *
dnvlist_take_binary(const nvlist_t *nvl, const char *name,
    size_t *sizep, void *defval, size_t defsize);

like yes there's a lot but they're all basically the same vibe with different data types, iykyk 🌈


πŸ’– DESCRIPTION πŸ’–

so the libnv library? it's the moment. it lets you manage name/value pairs SO easily and can send and receive them over sockets. for more deets, go check out nv(9) β€” she's the big sister page 🫢

✨ the dnvlist_get girlies ✨

the dnvlist_get functions return the value associated with name. slay. but if an element named name doesn't exist? no stress β€” the function returns the value you passed in as defval. it's giving "backup plan" energy πŸ’…

⚠️ BESTIE LISTEN TO ME β€” returned strings, nvlists, descriptors, binaries, or arrays must not be modified by the user, because they still belong to the nvlist. she's not yours, don't touch her. and if the nvlist is in an error state, attempts to use any of these functions will cause the program to abort. like literally dead. πŸ’€

πŸ”₯ the dnvlist_take girlies πŸ”₯

the dnvlist_take functions return the value associated with name AND remove the associated element from nvl. she's taking it and she's not giving it back, periodt. if an element named name doesn't exist, the value provided in defval is returned β€” same deal as the get functions.

but here's where it gets real, bestie β€” the memory management is ON YOU:

  • when the value is a string, binary, or array value β†’ the caller is responsible for freeing returned memory with free(3) πŸ—‘οΈ
  • when the value is an nvlist β†’ the caller is responsible for destroying the returned nvlist with nvlist_destroy() πŸ’”
  • when the value is a descriptor β†’ the caller is responsible for closing the returned descriptor with close(2) πŸšͺ

like she'll hand you the goods but you gotta clean up after yourself, no cap 😭


🌟 SEE ALSO 🌟

all the linked besties, go say hi πŸ’œ


πŸŽ€ HISTORY πŸŽ€

the dnv API appeared in FreeBSD 11.0. she's been iconic since day one, we been knew πŸ‘‘


⭐ AUTHORS ⭐

the dnv API was implemented by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation β€” king behavior honestly 🌈

this manual page was written by Adam Starak <starak.adam@gmail.com> β€” thank you for your service, legend 🫑


okay that's the whole page bestie, you're now officially dnv-literate, go forth and slay those name/value pairs πŸ’–βœ¨

Debian Β· January 3, 2025 Β· dnv(9) β€” mwah, love u, bye πŸŽ€

πŸ“¦ where this page comes from