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;

View File

@@ -213,5 +213,6 @@ int lookup_dm_dev_by_uuid(struct crypt_device *cd, const char *uuid, const char
int dm_is_dm_device(int major);
int dm_is_dm_kernel_name(const char *name);
char *dm_device_path(const char *prefix, int major, int minor);
char *dm_device_name(const char *path);
#endif /* _UTILS_DM_H */