Utils

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

Synopsis

#include <utils.h>

void                (*BDUtilsLogFunc)                   (gint level,
                                                         gchar *msg);
GQuark              bd_utils_exec_error_quark           (void);
#define             BD_UTILS_EXEC_ERROR
enum                BDUtilsExecError;
gboolean            bd_utils_exec_and_report_error      (gchar **argv,
                                                         GError **error);
gboolean            bd_utils_exec_and_capture_output    (gchar **argv,
                                                         gchar **output,
                                                         GError **error);
gboolean            bd_utils_init_logging               (BDUtilsLogFunc new_log_func,
                                                         GError **error);
#define             BD_UTILS_SIZE_ERROR
enum                BDUtilsSizeError;
gchar *             bd_utils_size_human_readable        (guint64 size);
guint64             bd_utils_size_from_spec             (gchar *spec,
                                                         GError **error);
gboolean            bd_utils_check_util_version         (gchar *util,
                                                         gchar *version,
                                                         gchar *version_arg,
                                                         gchar *version_regexp,
                                                         GError **error);
gint                bd_utils_version_cmp                (gchar *ver_string1,
                                                         gchar *ver_string2,
                                                         GError **error);
#define             EXBIBYTE
#define             EiB
#define             GIBIBYTE
#define             GiB
#define             KIBIBYTE
#define             KiB
#define             MEBIBYTE
#define             MiB
#define             PEBIBYTE
#define             PiB
#define             TEBIBYTE
#define             TiB

Description

Details

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.

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_ERROR

#define BD_UTILS_EXEC_ERROR bd_utils_exec_error_quark ()

enum BDUtilsExecError

typedef enum {
    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,
} BDUtilsExecError;

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_exec_and_report_error ()

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

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);

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);

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_ERROR

#define BD_UTILS_SIZE_ERROR bd_utils_size_error_quark ()

enum BDUtilsSizeError

typedef enum {
    BD_UTILS_SIZE_ERROR_INVALID_SPEC,
} BDUtilsSizeError;

BD_UTILS_SIZE_ERROR_INVALID_SPEC


bd_utils_size_human_readable ()

gchar *             bd_utils_size_human_readable        (guint64 size);

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);

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);

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);

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!**

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