nbd_set_private_data(3)

✨ nbd_set_private_data β€” set the per-handle private data ✨

okay so this is nbd_set_private_data(3) from the libnbd manual, bestie, and it's genuinely one of the chillest little functions you'll ever meet πŸ’…


🌸 SYNOPSIS 🌸

#include <libnbd.h>

uintptr_t nbd_set_private_data (
            struct nbd_handle *h, uintptr_t private_data
          );

πŸ’– DESCRIPTION πŸ’–

So every handle has this little stash spot in it β€” a private data field β€” and it's literally there for you, the application, to use for absolutely any purpose you want. No rules, no vibe check from libnbd, it's yours πŸŽ€

This function sets the value of that field, and β€” plot twist β€” it returns the old value (or 0 if it was never set before). Cute, right? It's giving "here's your stuff back."

When you're calling libnbd from C, the type of this field is uintptr_t, so you can use it to store an unsigned integer or a pointer. Both slay.

In non-C bindings, you can use it to store an unsigned integer. That's it, that's the range πŸ¦‹

Now, the important part, no cap: libnbd does not use or interpret the value at all β€” the only thing it ever does with it is hand it back to you when you call nbd_get_private_data(3). And in particular: if that value is a pointer, it is not freed when the handle is closed 🫢 So if you were hoping libnbd would clean up after your pointer, it won't. If you want that behaviour, go look at nbd_add_close_callback(3) instead β€” that's the friend who'll actually do the cleanup for you.


⭐ RETURN VALUE ⭐

This call returns a uintptr_t. (The old value, remember? πŸ’œ)


🌈 ERRORS 🌈

This function does not fail. Not even a little. It literally cannot fail, iconic behaviour, we stan 😌

The following parameters must not be NULL: h. For more information see "Non-NULL parameters" in libnbd(3).


πŸŽ€ VERSION πŸŽ€

This function first appeared in libnbd 1.8.

If you need to test if this function is available at compile time, check if the following macro is defined:

#define LIBNBD_HAVE_NBD_SET_PRIVATE_DATA 1

πŸ¦‹ SEE ALSO πŸ¦‹

nbd_add_close_callback(3), nbd_create(3), nbd_get_private_data(3), libnbd(3).


πŸ‘‘ AUTHORS πŸ‘‘

Eric Blake

Richard W.M. Jones


Copyright Red Hat


🌸 LICENSE 🌸

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


kk that's the whole page πŸ“ this one's from libnbd-1.25.8, dated 2026-10-13, and it's nbd_set_private_data(3) β€” go store something unhinged in your handle's private data field, you've earned it πŸ’–βœ¨

πŸ“¦ where this page comes from