Add dm_device_name helper.

Gets dm name from absolute device path.
This commit is contained in:
Ondrej Kozina
2019-07-31 14:41:50 +02:00
parent 7380731bf7
commit 4054f26c4d
2 changed files with 11 additions and 0 deletions

View File

@@ -383,6 +383,16 @@ char *dm_device_path(const char *prefix, int major, int minor)
return strdup(path);
}
char *dm_device_name(const char *path)
{
struct stat st;
if (stat(path, &st) < 0 || !S_ISBLK(st.st_mode))
return NULL;
return dm_device_path(NULL, major(st.st_rdev), minor(st.st_rdev));
}
static void hex_key(char *hexkey, size_t key_size, const char *key)
{
unsigned i;