Utils

Utils — library providing utility functions used by the blockdev library and its plugins

Functions

Types and Values

#define BD_UTILS_EXEC_ERROR
enum BDUtilsExecError
#define BD_UTILS_SIZE_ERROR
enum BDUtilsSizeError
#define EXBIBYTE
#define EiB
#define GIBIBYTE
#define GiB
#define KIBIBYTE
#define KiB
#define MEBIBYTE
#define MiB
#define PEBIBYTE
#define PiB
#define TEBIBYTE
#define TiB

Includes

#include <utils.h>

Description

Functions

BDUtilsLogFunc ()

void
(*BDUtilsLogFunc) (gint level,
                   gchar *msg);

Function type for logging function used by the libblockdev's exec utils to log the information about program executing.

Parameters

level

log level (as understood by syslog(3))

 

msg

log message

 

bd_utils_exec_error_quark ()

GQuark
bd_utils_exec_error_quark (void);

bd_utils_exec_and_report_error ()

gboolean
bd_utils_exec_and_report_error (gchar **argv,
                                GError **error);

Parameters

argv

the argv array for the call.

[array zero-terminated=1]

error

place to store error (if any).

[out]

Returns

whether the argv was successfully executed (no error and exit code 0) or not


bd_utils_exec_and_capture_output ()

gboolean
bd_utils_exec_and_capture_output (gchar **argv,
                                  gchar **output,
                                  GError **error);

Parameters

argv

the argv array for the call.

[array zero-terminated=1]

output

variable to store output to.

[out]

error

place to store error (if any).

[out]

Returns

whether the argv was successfully executed capturing the output or not


bd_utils_init_logging ()

gboolean
bd_utils_init_logging (BDUtilsLogFunc new_log_func,
                       GError **error);

Parameters

new_log_func

logging function to use or NULL to reset to default.

[allow-none][scope notified]

error

place to store error (if any).

[out]

Returns

whether logging was successfully initialized or not


bd_utils_size_human_readable ()

gchar *
bd_utils_size_human_readable (guint64 size);

Parameters

size

size to get human readable representation of

 

Returns

human readable representation of the given size


bd_utils_size_from_spec ()

guint64
bd_utils_size_from_spec (gchar *spec,
                         GError **error);

Parameters

spec

human readable size specification (e.g. "512 MiB")

 

error

place to store error (if any).

[out]

Returns

number of bytes equal to the size specification rounded to bytes, if 0, error ) may be set in case of error


bd_utils_check_util_version ()

gboolean
bd_utils_check_util_version (gchar *util,
                             gchar *version,
                             gchar *version_arg,
                             gchar *version_regexp,
                             GError **error);

Parameters

util

name of the utility to check

 

version

minimum required version of the utility or NULL if no version is required.

[allow-none]

version_arg

argument to use with the util to get version info or NULL to use "--version".

[allow-none]

version_regexp

regexp to extract version from the version info or NULL if only version is printed by "$ util version_arg ".

[allow-none]

error

place to store error (if any).

[out]

Returns

whether the util is available in a version >= version or not (error is set in such case).


bd_utils_version_cmp ()

gint
bd_utils_version_cmp (gchar *ver_string1,
                      gchar *ver_string2,
                      GError **error);

Parameters

ver_string1

first version string

 

ver_string2

second version string

 

error

place to store error (if any).

[out]

Returns

-1, 0 or 1 if ver_string1 is lower, the same or higher version as ver_string2 respectively. If an error occurs, returns -2 and error is set.

**ONLY SUPPORTS VERSION STRINGS OF FORMAT X[.Y[.Z[.Z2[.Z3...[-R]]]]] where all components are natural numbers!**

Types and Values

BD_UTILS_EXEC_ERROR

#define BD_UTILS_EXEC_ERROR bd_utils_exec_error_quark ()

enum BDUtilsExecError

Members

BD_UTILS_EXEC_ERROR_FAILED

   

BD_UTILS_EXEC_ERROR_NOOUT

   

BD_UTILS_EXEC_ERROR_INVAL_VER

   

BD_UTILS_EXEC_ERROR_UTIL_UNAVAILABLE

   

BD_UTILS_EXEC_ERROR_UTIL_UNKNOWN_VER

   

BD_UTILS_EXEC_ERROR_UTIL_LOW_VER

   

BD_UTILS_SIZE_ERROR

#define BD_UTILS_SIZE_ERROR bd_utils_size_error_quark ()

enum BDUtilsSizeError

Members

BD_UTILS_SIZE_ERROR_INVALID_SPEC

   

EXBIBYTE

#define EXBIBYTE *1024ULL PEBIBYTE

EiB

#define EiB EXBIBYTE

GIBIBYTE

#define GIBIBYTE *1024ULL MEBIBYTE

GiB

#define GiB GIBIBYTE

KIBIBYTE

#define KIBIBYTE *1024ULL

KiB

#define KiB KIBIBYTE

MEBIBYTE

#define MEBIBYTE *1024ULL KIBIBYTE

MiB

#define MiB MEBIBYTE

PEBIBYTE

#define PEBIBYTE *1024ULL TEBIBYTE

PiB

#define PiB PEBIBYTE

TEBIBYTE

#define TEBIBYTE *1024ULL GIBIBYTE

TiB

#define TiB TEBIBYTE