From 8f8cf896d629b06fe1128346c1594fd0ced42b9a Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 21 Nov 2001 17:08:37 +0000 Subject: [PATCH] o You can now specify the dev directory for libdm o dm_dir() returns the full path to the device-mapper dir (eg, /dev/device-mapper). o put stat in on _rm_node --- libdm/libdevmapper.h | 3 ++- libdm/libdm.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index dc35129ee..82b685521 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -74,8 +74,9 @@ int dm_task_add_target(struct dm_task *dmt, int dm_task_run(struct dm_task *dmt); /* - * Return the device-mapper directory + * Configure the device-mapper directory */ +int dm_set_dev_dir(const char *dir); const char *dm_dir(void); #endif /* LIB_DEVICE_MAPPER_H */ diff --git a/libdm/libdm.c b/libdm/libdm.c index 7e46a99eb..ebd92707b 100644 --- a/libdm/libdm.c +++ b/libdm/libdm.c @@ -23,6 +23,8 @@ #define DEV_DIR "/dev/" #define ALIGNMENT sizeof(int) +static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR; + /* * Library users can provide their own logging * function. @@ -292,9 +294,13 @@ static int _add_dev_node(const char *dev_name, dev_t dev) static int _rm_dev_node(const char *dev_name) { char path[PATH_MAX]; + struct stat info; _build_dev_path(path, sizeof(path), dev_name); + if (stat(path, &info) < 0) + return 1; + if (unlink(path) < 0) { log("Unable to unlink device node for '%s'", dev_name); return 0; @@ -308,13 +314,16 @@ int dm_task_run(struct dm_task *dmt) int fd = -1; struct dm_ioctl *dmi = _flatten(dmt); unsigned int command; + char control[PATH_MAX]; if (!dmi) { log("Couldn't create ioctl argument"); return 0; } - if ((fd = open(DEV_DIR DM_DIR "/control", O_RDWR)) < 0) { + snprintf(control, sizeof(control), "%s/control", _dm_dir); + + if ((fd = open(control, O_RDWR)) < 0) { log("Couldn't open device-mapper control device"); goto bad; } @@ -376,7 +385,13 @@ int dm_task_run(struct dm_task *dmt) return 0; } +int dm_set_dev_dir(const char *dir) +{ + snprintf(_dm_dir, sizeof(_dm_dir), "%s/%s", dir, DM_DIR); + return 1; +} + const char *dm_dir(void) { - return DM_DIR; + return _dm_dir; } -- 2.43.5