Scroll to navigation

nbdkit_realpath(3) NBDKIT nbdkit_realpath(3)

NAME

nbdkit_realpath, nbdkit_absolute_path - convert relative to absolute paths for nbdkit

SYNOPSIS

 #include <nbdkit-plugin.h>
 char *nbdkit_realpath (const char *filename);
 char *nbdkit_absolute_path (const char *filename);

DESCRIPTION

nbdkit(1) usually (not always) changes directory to / before it starts serving connections. This means that any relative paths passed during configuration will not work when the server is running. In a naive implementation of a plugin, a configuration like

 nbdkit plugin file=disk.img

might attempt to open /disk.img instead of the file in the user's current directory.

To avoid this 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, resolving symlinks. Under the hood it uses the realpath(3) function, and thus it fails if the path does not exist, or it is not possible to access components of the path.

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: if it is 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.

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.

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.

"nbdkit_realpath" was added in nbdkit 1.4.

SEE ALSO

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

AUTHORS

Richard W.M. Jones

COPYRIGHT

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.

2024-10-30 nbdkit-1.40.4