blockdev library

blockdev library — a library for doing low-level operations with block devices

Functions

Types and Values

#define BD_INIT_ERROR
enum BDInitError

Includes

#include <blockdev.h>

Description

Functions

bd_init ()

gboolean
bd_init (BDPluginSpec **require_plugins,
         BDUtilsLogFunc log_func,
         GError **error);

Parameters

require_plugins

NULL-terminated list of plugins that should be loaded (if no so_name is specified for the plugin, the default is used) or NULL to load all plugins.

[nullable][array zero-terminated=1]

log_func

logging function to use.

[nullable][scope notified]

error

place to store error (if any).

[out]

Returns

whether the library was successfully initialized with all the required or default (see require_plugins ) plugins or not

Example of libblockdev initialization with 'fs' and 'lvm' plugins. Specific version of the lvm plugin is required:

1
2
3
4
5
6
GError *error = NULL;
gboolean ret = FALSE;
BDPluginSpec fs_plugin = {BD_PLUGIN_FS, NULL};
BDPluginSpec lvm_plugin = {BD_PLUGIN_LVM, "libbd_lvm.so.2"};
BDPluginSpec *plugins[] = {&fs_plugin, &lvm_plugin, NULL};
ret = bd_init (plugins, NULL, &error);


bd_ensure_init ()

gboolean
bd_ensure_init (BDPluginSpec **require_plugins,
                BDUtilsLogFunc log_func,
                GError **error);

Checks the state of the library and if it is uninitialized or not all the require_plugins plugins are available, tries to (re)initialize it. Otherwise just returns early. The difference between:

1
2
if (!bd_is_initialized())
    bd_init(None, None, &error);

and this function is that this function does the check and init in an atomic way (holding the lock preventing other threads from doing changes in between).

Parameters

require_plugins

NULL-terminated list of plugins that should be loaded (if no so_name is specified for the plugin, the default is used) or NULL to load all plugins.

[nullable][array zero-terminated=1]

log_func

logging function to use.

[nullable][scope notified]

error

place to store error (if any).

[out]

Returns

whether the library was successfully initialized with all the required or default (see require_plugins ) plugins or not either before or by this call


bd_try_init ()

gboolean
bd_try_init (BDPluginSpec **request_plugins,
             BDUtilsLogFunc log_func,
             gchar ***loaded_plugin_names,
             GError **error);

Parameters

request_plugins

NULL-terminated list of plugins that should be loaded (if no so_name is specified for the plugin, the default is used) or NULL to load all plugins.

[nullable][array zero-terminated=1]

log_func

logging function to use.

[nullable][scope notified]

loaded_plugin_names

names of the successfully loaded plugins.

[optional][out][transfer container][array zero-terminated=1]

error

place to store error (if any).

[out]

Returns

whether the library was successfully initialized with all the required or default (see require_plugins ) plugins or not

*UNLIKE IN CASE OF bd_init() AND bd_ensure_init(), FAILURE TO LOAD A PLUGIN IS NOT CONSIDERED ERROR*


bd_reinit ()

gboolean
bd_reinit (BDPluginSpec **require_plugins,
           gboolean reload,
           BDUtilsLogFunc log_func,
           GError **error);

Parameters

require_plugins

NULL-terminated list of plugins that should be loaded (if no so_name is specified for the plugin, the default is used) or NULL to load all plugins.

[nullable][array zero-terminated=1]

reload

whether to reload the already loaded plugins or not

 

log_func

logging function to use or NULL to keep the old one.

[nullable][scope notified]

error

place to store error (if any).

[out]

Returns

whether the library was successfully initialized or not

If reload is TRUE all the plugins are closed and reloaded otherwise only the missing plugins are loaded.


bd_try_reinit ()

gboolean
bd_try_reinit (BDPluginSpec **require_plugins,
               gboolean reload,
               BDUtilsLogFunc log_func,
               gchar ***loaded_plugin_names,
               GError **error);

Parameters

require_plugins

NULL-terminated list of plugins that should be loaded (if no so_name is specified for the plugin, the default is used) or NULL to load all plugins.

[nullable][array zero-terminated=1]

reload

whether to reload the already loaded plugins or not

 

log_func

logging function to use or NULL to keep the old one.

[nullable][scope notified]

loaded_plugin_names

names of the successfully loaded plugins.

[optional][out][transfer container][array zero-terminated=1]

error

place to store error (if any).

[out]

Returns

whether the library was successfully initialized or not

If reload is TRUE all the plugins are closed and reloaded otherwise only the missing plugins are loaded.

*UNLIKE IN CASE OF bd_init() AND bd_ensure_init(), FAILURE TO LOAD A PLUGIN IS NOT CONSIDERED ERROR*


bd_is_initialized ()

gboolean
bd_is_initialized (void);

Returns

whether the library is initialized or not

The library is considered initialized if some of the *init*() functions was/were called and either at least one plugin is loaded or 0 plugins are loaded after an explicit call that requested 0 plugins to be loaded.


bd_switch_init_checks ()

gboolean
bd_switch_init_checks (gboolean enable,
                       GError **error);

Enables or disables plugins' init checks based on enable .

Note: The current implementation (un)sets the LIBBLOCKDEV_SKIP_DEP_CHECKS environment variable.

Parameters

enable

whether to enable init checks (TRUE) or not (FALSE)

 

error

place to store error (if any).

[out]

bd_init_error_quark ()

GQuark
bd_init_error_quark (void);

[skip]

Types and Values

BD_INIT_ERROR

#define BD_INIT_ERROR bd_init_error_quark ()

enum BDInitError

Members

BD_INIT_ERROR_PLUGINS_FAILED

   

BD_INIT_ERROR_NOT_IMPLEMENTED

   

BD_INIT_ERROR_FAILED