nbdkit_realpath(3)

✨ nbdkit_realpath β€” convert relative to absolute paths, bestie edition ✨

okay so this is a page from the nbdkit manual, section 3, and it's about two lil functions that save your plugin from the classic "wait why is it looking in /" situation. it's giving path therapy. πŸ’…

🌸 NAME 🌸

nbdkit_realpath, nbdkit_absolute_path β€” turn relative paths into absolute paths, for nbdkit 🫢

πŸŽ€ SYNOPSIS πŸŽ€

#include <nbdkit-plugin.h>

char *nbdkit_realpath (const char *filename);
char *nbdkit_absolute_path (const char *filename);

πŸ’– DESCRIPTION πŸ’–

so here's the tea, bestie: nbdkit(1) usually (not always!!) changes directory to / before it starts serving connections. which means any relative paths you passed during configuration are just... not gonna work once the server is up and running. πŸ’€

in a naive implementation of a plugin, a configuration like

nbdkit plugin file=disk.img

might go and try to open /disk.img instead of the file in the user's current directory. the audacity, honestly. 😭

to avoid this whole problem, you can:

  • convert relative paths to absolute paths using one of the functions described here, or
  • open the file at configure time and store the file descriptor.

πŸ¦‹ nbdkit_realpath πŸ¦‹

the utility function nbdkit_realpath converts any path to an absolute path, and it resolves symlinks while it's at it. under the hood it uses the realpath(3) function, which means it fails if the path does not exist, or if it's not possible to access components of the path. no cap, it needs the path to actually be real. ✨

this function works only when used in the .config, .config_complete and .get_ready callbacks.

🧚 nbdkit_absolute_path 🧚

the utility function nbdkit_absolute_path converts any path to an absolute path too: if it's relative, then all this function does is prepend the current working directory to the path, with no extra checks.

unlike nbdkit_realpath, this function does not check that the file exists. it's the chill, low-effort cousin. πŸ™ˆ

this function works only when used in the .config, .config_complete and .get_ready callbacks.


πŸ‘‘ RETURN VALUE πŸ‘‘

on success these functions return a newly allocated string. the returned string must be freed by the caller β€” yes, that's on you, bestie, don't leave it hanging. πŸŽ€

on error these call nbdkit_error(3) and return NULL.

🌈 LANGUAGE BINDINGS 🌈

in nbdkit-ocaml-plugin(3):

NBDKit.realpath : string -> string

⭐ HISTORY ⭐

nbdkit_absolute_path was present in nbdkit 0.1.0. it's been here since the dawn of time, basically.

nbdkit_realpath was added in nbdkit 1.4. a little later to the party but we love her. πŸ’œ

πŸ”₯ SEE ALSO πŸ”₯

nbdkit(1), nbdkit-plugin(3), nbdkit-filter(3).

πŸ’ AUTHORS πŸ’

Richard W.M. Jones

Copyright Red Hat

πŸ“œ LICENSE πŸ“œ

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Red Hat nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


and that's the whole page, periodt πŸ’– this was nbdkit version 1.48.1, dated 2026-08-29, from the nbdkit_realpath(3) manual. stay absolute, bestie πŸ¦‹βœ¨

πŸ“¦ where this page comes from