Move devpath scan to separate file.
[platform/upstream/cryptsetup.git] / lib / libdevmapper.c
1 /*
2  * libdevmapper - device-mapper backend for cryptsetup
3  *
4  * Copyright (C) 2004, Christophe Saout <christophe@saout.de>
5  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
6  * Copyright (C) 2009-2011, Red Hat, Inc. All rights reserved.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdio.h>
23 #include <dirent.h>
24 #include <errno.h>
25 #include <libdevmapper.h>
26 #include <fcntl.h>
27 #include <linux/fs.h>
28 #include <uuid/uuid.h>
29
30 #include "internal.h"
31 #include "luks.h"
32
33 #define DM_UUID_LEN             129
34 #define DM_UUID_PREFIX          "CRYPT-"
35 #define DM_UUID_PREFIX_LEN      6
36 #define DM_CRYPT_TARGET         "crypt"
37 #define RETRY_COUNT             5
38
39 /* Set if dm-crypt version was probed */
40 static int _dm_crypt_checked = 0;
41 static uint32_t _dm_crypt_flags = 0;
42
43 static int _dm_use_count = 0;
44 static struct crypt_device *_context = NULL;
45
46 /* Check if we have DM flag to instruct kernel to force wipe buffers */
47 #if !HAVE_DECL_DM_TASK_SECURE_DATA
48 static int dm_task_secure_data(struct dm_task *dmt) { return 1; }
49 #endif
50
51 /* Compatibility for old device-mapper without udev support */
52 #if HAVE_DECL_DM_UDEV_DISABLE_DISK_RULES_FLAG
53 #define CRYPT_TEMP_UDEV_FLAGS   DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG | \
54                                 DM_UDEV_DISABLE_DISK_RULES_FLAG | \
55                                 DM_UDEV_DISABLE_OTHER_RULES_FLAG
56 #define _dm_task_set_cookie     dm_task_set_cookie
57 #define _dm_udev_wait           dm_udev_wait
58 #else
59 #define CRYPT_TEMP_UDEV_FLAGS   0
60 static int _dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags) { return 0; }
61 static int _dm_udev_wait(uint32_t cookie) { return 0; };
62 #endif
63
64 static int _dm_use_udev(void)
65 {
66 #ifdef USE_UDEV /* cannot be enabled if devmapper is too old */
67         return dm_udev_get_sync_support();
68 #else
69         return 0;
70 #endif
71 }
72
73 __attribute__((format(printf, 4, 5)))
74 static void set_dm_error(int level,
75                          const char *file __attribute__((unused)),
76                          int line __attribute__((unused)),
77                          const char *f, ...)
78 {
79         char *msg = NULL;
80         va_list va;
81
82         va_start(va, f);
83         if (vasprintf(&msg, f, va) > 0) {
84                 if (level < 4) {
85                         log_err(_context, msg);
86                         log_err(_context, "\n");
87                 } else
88                         log_dbg(msg);
89         }
90         free(msg);
91         va_end(va);
92 }
93
94 static int _dm_simple(int task, const char *name, int udev_wait);
95
96 static void _dm_set_crypt_compat(const char *dm_version, unsigned crypt_maj,
97                                  unsigned crypt_min, unsigned crypt_patch)
98 {
99         unsigned dm_maj, dm_min, dm_patch;
100
101         if (sscanf(dm_version, "%u.%u.%u", &dm_maj, &dm_min, &dm_patch) != 3)
102                 dm_maj = dm_min = dm_patch = 0;
103
104         log_dbg("Detected dm-crypt version %i.%i.%i, dm-ioctl version %u.%u.%u.",
105                 crypt_maj, crypt_min, crypt_patch, dm_maj, dm_min, dm_patch);
106
107         if (crypt_maj >= 1 && crypt_min >= 2)
108                 _dm_crypt_flags |= DM_KEY_WIPE_SUPPORTED;
109         else
110                 log_dbg("Suspend and resume disabled, no wipe key support.");
111
112         if (crypt_maj >= 1 && crypt_min >= 10)
113                 _dm_crypt_flags |= DM_LMK_SUPPORTED;
114
115         if (dm_maj >= 4 && dm_min >= 20)
116                 _dm_crypt_flags |= DM_SECURE_SUPPORTED;
117
118         /* not perfect, 2.6.33 supports with 1.7.0 */
119         if (crypt_maj >= 1 && crypt_min >= 8)
120                 _dm_crypt_flags |= DM_PLAIN64_SUPPORTED;
121
122         /* Repeat test if dm-crypt is not present */
123         if (crypt_maj > 0)
124                 _dm_crypt_checked = 1;
125 }
126
127 static int _dm_check_versions(void)
128 {
129         struct dm_task *dmt;
130         struct dm_versions *target, *last_target;
131         char dm_version[16];
132
133         if (_dm_crypt_checked)
134                 return 1;
135
136         /* FIXME: add support to DM so it forces crypt target module load here */
137         if (!(dmt = dm_task_create(DM_DEVICE_LIST_VERSIONS)))
138                 return 0;
139
140         if (!dm_task_run(dmt)) {
141                 dm_task_destroy(dmt);
142                 return 0;
143         }
144
145         if (!dm_task_get_driver_version(dmt, dm_version, sizeof(dm_version))) {
146                 dm_task_destroy(dmt);
147                 return 0;
148         }
149
150         target = dm_task_get_versions(dmt);
151         do {
152                 last_target = target;
153                 if (!strcmp(DM_CRYPT_TARGET, target->name)) {
154                         _dm_set_crypt_compat(dm_version,
155                                              (unsigned)target->version[0],
156                                              (unsigned)target->version[1],
157                                              (unsigned)target->version[2]);
158                 }
159                 target = (struct dm_versions *)((char *) target + target->next);
160         } while (last_target != target);
161
162         dm_task_destroy(dmt);
163         return 1;
164 }
165
166 uint32_t dm_flags(void)
167 {
168         if (!_dm_crypt_checked)
169                 _dm_check_versions();
170
171         return _dm_crypt_flags;
172 }
173
174 int dm_init(struct crypt_device *context, int check_kernel)
175 {
176         if (!_dm_use_count++) {
177                 log_dbg("Initialising device-mapper backend%s, UDEV is %sabled.",
178                         check_kernel ? "" : " (NO kernel check requested)",
179                         _dm_use_udev() ? "en" : "dis");
180                 if (check_kernel && !_dm_check_versions()) {
181                         log_err(context, _("Cannot initialize device-mapper. Is dm_mod kernel module loaded?\n"));
182                         return -1;
183                 }
184                 if (getuid() || geteuid())
185                         log_dbg(("WARNING: Running as a non-root user. Functionality may be unavailable."));
186                 dm_log_init(set_dm_error);
187                 dm_log_init_verbose(10);
188         }
189
190         // FIXME: global context is not safe
191         if (context)
192                 _context = context;
193
194         return 1;       /* unsafe memory */
195 }
196
197 void dm_exit(void)
198 {
199         if (_dm_use_count && (!--_dm_use_count)) {
200                 log_dbg("Releasing device-mapper backend.");
201                 dm_log_init_verbose(0);
202                 dm_log_init(NULL);
203                 dm_lib_release();
204                 _context = NULL;
205         }
206 }
207
208 /* Return path to DM device */
209 char *dm_device_path(const char *dev_id)
210 {
211         int major, minor;
212         struct dm_task *dmt;
213         const char *name;
214         char path[PATH_MAX];
215
216         if (sscanf(dev_id, "%d:%d", &major, &minor) != 2)
217                 return NULL;
218
219         if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
220                 return NULL;
221         if (!dm_task_set_minor(dmt, minor) ||
222             !dm_task_set_major(dmt, major) ||
223             !dm_task_run(dmt) ||
224             !(name = dm_task_get_name(dmt))) {
225                 dm_task_destroy(dmt);
226                 return NULL;
227         }
228
229         if (snprintf(path, sizeof(path), "/dev/mapper/%s", name) < 0)
230                 path[0] = '\0';
231
232         dm_task_destroy(dmt);
233
234         return strdup(path);
235 }
236
237 static void hex_key(char *hexkey, size_t key_size, const char *key)
238 {
239         unsigned i;
240
241         for(i = 0; i < key_size; i++)
242                 sprintf(&hexkey[i * 2], "%02x", (unsigned char)key[i]);
243 }
244
245 static char *get_params(const char *device, uint64_t skip, uint64_t offset,
246                         const char *cipher, size_t key_size, const char *key)
247 {
248         char *params;
249         char *hexkey;
250
251         hexkey = crypt_safe_alloc(key_size * 2 + 1);
252         if (!hexkey)
253                 return NULL;
254
255         hex_key(hexkey, key_size, key);
256
257         params = crypt_safe_alloc(strlen(hexkey) + strlen(cipher) + strlen(device) + 64);
258         if (!params)
259                 goto out;
260
261         sprintf(params, "%s %s %" PRIu64 " %s %" PRIu64,
262                 cipher, hexkey, skip, device, offset);
263
264 out:
265         crypt_safe_free(hexkey);
266         return params;
267 }
268
269 /* DM helpers */
270 static int _dm_simple(int task, const char *name, int udev_wait)
271 {
272         int r = 0;
273         struct dm_task *dmt;
274         uint32_t cookie = 0;
275
276         if (!_dm_use_udev())
277                 udev_wait = 0;
278
279         if (!(dmt = dm_task_create(task)))
280                 return 0;
281
282         if (name && !dm_task_set_name(dmt, name))
283                 goto out;
284
285         if (udev_wait && !_dm_task_set_cookie(dmt, &cookie, 0))
286                 goto out;
287
288         r = dm_task_run(dmt);
289
290         if (udev_wait)
291                 (void)_dm_udev_wait(cookie);
292
293       out:
294         dm_task_destroy(dmt);
295         return r;
296 }
297
298 static int _error_device(const char *name, size_t size)
299 {
300         struct dm_task *dmt;
301         int r = 0;
302
303         if (!(dmt = dm_task_create(DM_DEVICE_RELOAD)))
304                 return 0;
305
306         if (!dm_task_set_name(dmt, name))
307                 goto error;
308
309         if (!dm_task_add_target(dmt, UINT64_C(0), size, "error", ""))
310                 goto error;
311
312         if (!dm_task_set_ro(dmt))
313                 goto error;
314
315         if (!dm_task_no_open_count(dmt))
316                 goto error;
317
318         if (!dm_task_run(dmt))
319                 goto error;
320
321         if (!_dm_simple(DM_DEVICE_RESUME, name, 1)) {
322                 _dm_simple(DM_DEVICE_CLEAR, name, 0);
323                 goto error;
324         }
325
326         r = 1;
327
328 error:
329         dm_task_destroy(dmt);
330         return r;
331 }
332
333 int dm_remove_device(const char *name, int force, uint64_t size)
334 {
335         int r = -EINVAL;
336         int retries = force ? RETRY_COUNT : 1;
337         int error_target = 0;
338
339         if (!name || (force && !size))
340                 return -EINVAL;
341
342         do {
343                 r = _dm_simple(DM_DEVICE_REMOVE, name, 1) ? 0 : -EINVAL;
344                 if (--retries && r) {
345                         log_dbg("WARNING: other process locked internal device %s, %s.",
346                                 name, retries ? "retrying remove" : "giving up");
347                         if (force && (crypt_get_debug_level() == CRYPT_LOG_DEBUG))
348                                 debug_processes_using_device(name);
349                         sleep(1);
350                         if (force && !error_target) {
351                                 /* If force flag is set, replace device with error, read-only target.
352                                  * it should stop processes from reading it and also removed underlying
353                                  * device from mapping, so it is usable again.
354                                  * Force flag should be used only for temporary devices, which are
355                                  * intended to work inside cryptsetup only!
356                                  * Anyway, if some process try to read temporary cryptsetup device,
357                                  * it is bug - no other process should try touch it (e.g. udev).
358                                  */
359                                 _error_device(name, size);
360                                 error_target = 1;
361                         }
362                 }
363         } while (r == -EINVAL && retries);
364
365         dm_task_update_nodes();
366
367         return r;
368 }
369
370 #define UUID_LEN 37 /* 36 + \0, libuuid ... */
371 /*
372  * UUID has format: CRYPT-<devicetype>-[<uuid>-]<device name>
373  * CRYPT-PLAIN-name
374  * CRYPT-LUKS1-00000000000000000000000000000000-name
375  * CRYPT-TEMP-name
376  */
377 static void dm_prepare_uuid(const char *name, const char *type, const char *uuid, char *buf, size_t buflen)
378 {
379         char *ptr, uuid2[UUID_LEN] = {0};
380         uuid_t uu;
381         unsigned i = 0;
382
383         /* Remove '-' chars */
384         if (uuid && !uuid_parse(uuid, uu)) {
385                 for (ptr = uuid2, i = 0; i < UUID_LEN; i++)
386                         if (uuid[i] != '-') {
387                                 *ptr = uuid[i];
388                                 ptr++;
389                         }
390         }
391
392         i = snprintf(buf, buflen, DM_UUID_PREFIX "%s%s%s%s%s",
393                 type ?: "", type ? "-" : "",
394                 uuid2[0] ? uuid2 : "", uuid2[0] ? "-" : "",
395                 name);
396
397         log_dbg("DM-UUID is %s", buf);
398         if (i >= buflen)
399                 log_err(NULL, _("DM-UUID for device %s was truncated.\n"), name);
400 }
401
402 int dm_create_device(const char *name,
403                      const char *device,
404                      const char *cipher,
405                      const char *type,
406                      const char *uuid,
407                      uint64_t size,
408                      uint64_t skip,
409                      uint64_t offset,
410                      size_t key_size,
411                      const char *key,
412                      int read_only,
413                      int reload)
414 {
415         struct dm_task *dmt = NULL;
416         struct dm_info dmi;
417         char *params = NULL;
418         char *error = NULL;
419         char dev_uuid[DM_UUID_LEN] = {0};
420         int r = -EINVAL;
421         uint32_t read_ahead = 0;
422         uint32_t cookie = 0;
423         uint16_t udev_flags = 0;
424
425         params = get_params(device, skip, offset, cipher, key_size, key);
426         if (!params)
427                 goto out_no_removal;
428
429         if (type && !strncmp(type, "TEMP", 4))
430                 udev_flags = CRYPT_TEMP_UDEV_FLAGS;
431
432         /* All devices must have DM_UUID, only resize on old device is exception */
433         if (reload) {
434                 if (!(dmt = dm_task_create(DM_DEVICE_RELOAD)))
435                         goto out_no_removal;
436
437                 if (!dm_task_set_name(dmt, name))
438                         goto out_no_removal;
439         } else {
440                 dm_prepare_uuid(name, type, uuid, dev_uuid, sizeof(dev_uuid));
441
442                 if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
443                         goto out_no_removal;
444
445                 if (!dm_task_set_name(dmt, name))
446                         goto out_no_removal;
447
448                 if (!dm_task_set_uuid(dmt, dev_uuid))
449                         goto out_no_removal;
450
451                 if (_dm_use_udev() && !_dm_task_set_cookie(dmt, &cookie, udev_flags))
452                         goto out_no_removal;
453         }
454
455         if ((dm_flags() & DM_SECURE_SUPPORTED) && !dm_task_secure_data(dmt))
456                 goto out_no_removal;
457         if (read_only && !dm_task_set_ro(dmt))
458                 goto out_no_removal;
459         if (!dm_task_add_target(dmt, 0, size, DM_CRYPT_TARGET, params))
460                 goto out_no_removal;
461
462 #ifdef DM_READ_AHEAD_MINIMUM_FLAG
463         if (device_read_ahead(device, &read_ahead) &&
464             !dm_task_set_read_ahead(dmt, read_ahead, DM_READ_AHEAD_MINIMUM_FLAG))
465                 goto out_no_removal;
466 #endif
467
468         if (!dm_task_run(dmt))
469                 goto out_no_removal;
470
471         if (reload) {
472                 dm_task_destroy(dmt);
473                 if (!(dmt = dm_task_create(DM_DEVICE_RESUME)))
474                         goto out;
475                 if (!dm_task_set_name(dmt, name))
476                         goto out;
477                 if (uuid && !dm_task_set_uuid(dmt, dev_uuid))
478                         goto out;
479                 if (_dm_use_udev() && !_dm_task_set_cookie(dmt, &cookie, udev_flags))
480                         goto out;
481                 if (!dm_task_run(dmt))
482                         goto out;
483         }
484
485         if (!dm_task_get_info(dmt, &dmi))
486                 goto out;
487
488         r = 0;
489 out:
490         if (_dm_use_udev()) {
491                 (void)_dm_udev_wait(cookie);
492                 cookie = 0;
493         }
494
495         if (r < 0 && !reload) {
496                 if (get_error())
497                         error = strdup(get_error());
498
499                 dm_remove_device(name, 0, 0);
500
501                 if (error) {
502                         set_error(error);
503                         free(error);
504                 }
505         }
506
507 out_no_removal:
508         if (cookie && _dm_use_udev())
509                 (void)_dm_udev_wait(cookie);
510
511         if (params)
512                 crypt_safe_free(params);
513         if (dmt)
514                 dm_task_destroy(dmt);
515
516         dm_task_update_nodes();
517         return r;
518 }
519
520 int dm_status_device(const char *name)
521 {
522         struct dm_task *dmt;
523         struct dm_info dmi;
524         uint64_t start, length;
525         char *target_type, *params;
526         void *next = NULL;
527         int r = -EINVAL;
528
529         if (!(dmt = dm_task_create(DM_DEVICE_STATUS)))
530                 goto out;
531
532         if (!dm_task_set_name(dmt, name))
533                 goto out;
534
535         if (!dm_task_run(dmt))
536                 goto out;
537
538         if (!dm_task_get_info(dmt, &dmi))
539                 goto out;
540
541         if (!dmi.exists) {
542                 r = -ENODEV;
543                 goto out;
544         }
545
546         next = dm_get_next_target(dmt, next, &start, &length,
547                                   &target_type, &params);
548         if (!target_type || strcmp(target_type, DM_CRYPT_TARGET) != 0 ||
549             start != 0 || next)
550                 r = -EINVAL;
551         else
552                 r = (dmi.open_count > 0);
553 out:
554         if (dmt)
555                 dm_task_destroy(dmt);
556
557         return r;
558 }
559
560 int dm_query_device(const char *name,
561                     char **device,
562                     uint64_t *size,
563                     uint64_t *skip,
564                     uint64_t *offset,
565                     char **cipher,
566                     int *key_size,
567                     char **key,
568                     int *read_only,
569                     int *suspended,
570                     char **uuid)
571 {
572         struct dm_task *dmt;
573         struct dm_info dmi;
574         uint64_t start, length, val64;
575         char *target_type, *params, *rcipher, *key_, *rdevice, *endp, buffer[3];
576         const char *tmp_uuid;
577         void *next = NULL;
578         int i, r = -EINVAL;
579
580         if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
581                 goto out;
582         if ((dm_flags() & DM_SECURE_SUPPORTED) && !dm_task_secure_data(dmt))
583                 goto out;
584         if (!dm_task_set_name(dmt, name))
585                 goto out;
586         r = -ENODEV;
587         if (!dm_task_run(dmt))
588                 goto out;
589
590         r = -EINVAL;
591         if (!dm_task_get_info(dmt, &dmi))
592                 goto out;
593
594         if (!dmi.exists) {
595                 r = -ENODEV;
596                 goto out;
597         }
598
599         next = dm_get_next_target(dmt, next, &start, &length,
600                                   &target_type, &params);
601         if (!target_type || strcmp(target_type, DM_CRYPT_TARGET) != 0 ||
602             start != 0 || next)
603                 goto out;
604
605         if (size)
606                 *size = length;
607
608         rcipher = strsep(&params, " ");
609         /* cipher */
610         if (cipher)
611                 *cipher = strdup(rcipher);
612
613         /* skip */
614         key_ = strsep(&params, " ");
615         if (!params)
616                 goto out;
617         val64 = strtoull(params, &params, 10);
618         if (*params != ' ')
619                 goto out;
620         params++;
621         if (skip)
622                 *skip = val64;
623
624         /* device */
625         rdevice = strsep(&params, " ");
626         if (device)
627                 *device = crypt_lookup_dev(rdevice);
628
629         /*offset */
630         if (!params)
631                 goto out;
632         val64 = strtoull(params, &params, 10);
633         if (*params)
634                 goto out;
635         if (offset)
636                 *offset = val64;
637
638         /* key_size */
639         if (key_size)
640                 *key_size = strlen(key_) / 2;
641
642         /* key */
643         if (key_size && key) {
644                 *key = crypt_safe_alloc(*key_size);
645                 if (!*key) {
646                         r = -ENOMEM;
647                         goto out;
648                 }
649
650                 buffer[2] = '\0';
651                 for(i = 0; i < *key_size; i++) {
652                         memcpy(buffer, &key_[i * 2], 2);
653                         (*key)[i] = strtoul(buffer, &endp, 16);
654                         if (endp != &buffer[2]) {
655                                 crypt_safe_free(key);
656                                 *key = NULL;
657                                 goto out;
658                         }
659                 }
660         }
661         memset(key_, 0, strlen(key_));
662
663         if (read_only)
664                 *read_only = dmi.read_only;
665
666         if (suspended)
667                 *suspended = dmi.suspended;
668
669         if (uuid && (tmp_uuid = dm_task_get_uuid(dmt)) &&
670             !strncmp(tmp_uuid, DM_UUID_PREFIX, DM_UUID_PREFIX_LEN))
671                 *uuid = strdup(tmp_uuid + DM_UUID_PREFIX_LEN);
672
673         r = (dmi.open_count > 0);
674 out:
675         if (dmt)
676                 dm_task_destroy(dmt);
677
678         return r;
679 }
680
681 static int _dm_message(const char *name, const char *msg)
682 {
683         int r = 0;
684         struct dm_task *dmt;
685
686         if (!(dmt = dm_task_create(DM_DEVICE_TARGET_MSG)))
687                 return 0;
688
689         if ((dm_flags() & DM_SECURE_SUPPORTED) && !dm_task_secure_data(dmt))
690                 goto out;
691
692         if (name && !dm_task_set_name(dmt, name))
693                 goto out;
694
695         if (!dm_task_set_sector(dmt, (uint64_t) 0))
696                 goto out;
697
698         if (!dm_task_set_message(dmt, msg))
699                 goto out;
700
701         r = dm_task_run(dmt);
702
703       out:
704         dm_task_destroy(dmt);
705         return r;
706 }
707
708 int dm_suspend_and_wipe_key(const char *name)
709 {
710         if (!_dm_check_versions())
711                 return -ENOTSUP;
712
713         if (!(_dm_crypt_flags & DM_KEY_WIPE_SUPPORTED))
714                 return -ENOTSUP;
715
716         if (!_dm_simple(DM_DEVICE_SUSPEND, name, 0))
717                 return -EINVAL;
718
719         if (!_dm_message(name, "key wipe")) {
720                 _dm_simple(DM_DEVICE_RESUME, name, 1);
721                 return -EINVAL;
722         }
723
724         return 0;
725 }
726
727 int dm_resume_and_reinstate_key(const char *name,
728                                 size_t key_size,
729                                 const char *key)
730 {
731         int msg_size = key_size * 2 + 10; // key set <key>
732         char *msg;
733         int r = 0;
734
735         if (!_dm_check_versions())
736                 return -ENOTSUP;
737
738         if (!(_dm_crypt_flags & DM_KEY_WIPE_SUPPORTED))
739                 return -ENOTSUP;
740
741         msg = crypt_safe_alloc(msg_size);
742         if (!msg)
743                 return -ENOMEM;
744
745         memset(msg, 0, msg_size);
746         strcpy(msg, "key set ");
747         hex_key(&msg[8], key_size, key);
748
749         if (!_dm_message(name, msg) ||
750             !_dm_simple(DM_DEVICE_RESUME, name, 1))
751                 r = -EINVAL;
752
753         crypt_safe_free(msg);
754         return r;
755 }
756
757 const char *dm_get_dir(void)
758 {
759         return dm_dir();
760 }
761
762 int dm_is_dm_device(int major)
763 {
764         return dm_is_dm_major((uint32_t)major);
765 }