#include "libdm-targets.h"
#include "libdm-common.h"
-#include "libdevmapper.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <sys/param.h>
#include <sys/stat.h>
-#include <sys/types.h>
+#include <unistd.h>
#include <errno.h>
-#include <linux/kdev_t.h>
#include <linux/dm-ioctl.h>
+#include <linux/kdev_t.h>
#define DEV_DIR "/dev/"
static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR;
+static int _verbose = 0;
+
/*
* Library users can provide their own logging
* function.
{
va_list ap;
- if (level > _LOG_WARN)
+ if (level > _LOG_WARN && !_verbose)
return;
va_start(ap, f);
- if (level == _LOG_WARN)
- vprintf(f, ap);
- else
+ if (level < _LOG_WARN)
vfprintf(stderr, f, ap);
+ else
+ vprintf(f, ap);
va_end(ap);
- fprintf(stderr, "\n");
+ if (level < _LOG_WARN)
+ fprintf(stderr, "\n");
+ else
+ printf("\n");
}
dm_log_fn _log = _default_log;
_log = fn;
}
+void dm_log_init_verbose(int level)
+{
+ _verbose = level;
+}
+
static void _build_dev_path(char *buffer, size_t len, const char *dev_name)
{
/* If there's a /, assume caller knows what they're doing */
{
struct dm_task *dmt = malloc(sizeof(*dmt));
+ if (!dm_check_version())
+ return NULL;
+
if (!dmt) {
log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
return NULL;
dmt->type = type;
dmt->minor = -1;
+
return dmt;
}
return 1;
}
-int add_dev_node(const char *dev_name, dev_t dev)
+int add_dev_node(const char *dev_name, uint32_t major, uint32_t minor)
{
char path[PATH_MAX];
struct stat info;
+ dev_t dev = MKDEV(major, minor);
_build_dev_path(path, sizeof(path), dev_name);
}
if (unlink(newpath) < 0) {
- if (errno == EPERM) {
+ if (errno == EPERM) {
/* devfs, entry has already been renamed */
return 1;
}
#ifndef LIB_DMCOMMON_H
#define LIB_DMCOMMON_H
+#include "libdevmapper.h"
+
#define _LOG_DEBUG 7
#define _LOG_INFO 6
#define _LOG_NOTICE 5
#define _LOG_ERR 3
#define _LOG_FATAL 2
-dm_log_fn _log;
+extern dm_log_fn _log;
#define log_error(msg, x...) _log(_LOG_ERR, __FILE__, __LINE__, msg, ## x)
#define log_print(msg, x...) _log(_LOG_WARN, __FILE__, __LINE__, msg, ## x)
#define log_debug(msg, x...) _log(_LOG_DEBUG, __FILE__, __LINE__, msg, ## x)
struct target *create_target(uint64_t start,
- uint64_t len,
- const char *type, const char *params);
+ uint64_t len,
+ const char *type, const char *params);
-int add_dev_node(const char *dev_name, dev_t dev);
+int add_dev_node(const char *dev_name, uint32_t minor, uint32_t major);
int rm_dev_node(const char *dev_name);
int rename_dev_node(const char *old_name, const char *new_name);