Imported upstream version 1.6.7
[platform/upstream/cryptsetup.git] / lib / utils_dm.h
1 /*
2  * libdevmapper - device-mapper backend for cryptsetup
3  *
4  * Copyright (C) 2004, Jana Saout <jana@saout.de>
5  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
6  * Copyright (C) 2009-2015, Red Hat, Inc. All rights reserved.
7  * Copyright (C) 2009-2015, Milan Broz
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #ifndef _UTILS_DM_H
25 #define _UTILS_DM_H
26
27 /* device-mapper library helpers */
28 #include <inttypes.h>
29
30 struct crypt_device;
31 struct volume_key;
32 struct crypt_params_verity;
33 struct device;
34
35 /* Device mapper backend - kernel support flags */
36 #define DM_KEY_WIPE_SUPPORTED (1 << 0)  /* key wipe message */
37 #define DM_LMK_SUPPORTED      (1 << 1)  /* lmk mode */
38 #define DM_SECURE_SUPPORTED   (1 << 2)  /* wipe (secure) buffer flag */
39 #define DM_PLAIN64_SUPPORTED  (1 << 3)  /* plain64 IV */
40 #define DM_DISCARDS_SUPPORTED (1 << 4)  /* discards/TRIM option is supported */
41 #define DM_VERITY_SUPPORTED   (1 << 5)  /* dm-verity target supported */
42 #define DM_TCW_SUPPORTED      (1 << 6)  /* tcw (TCRYPT CBC with whitening) */
43 #define DM_SAME_CPU_CRYPT_SUPPORTED (1 << 7) /* same_cpu_crypt */
44 #define DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED (1 << 8) /* submit_from_crypt_cpus */
45
46 uint32_t dm_flags(void);
47
48 #define DM_ACTIVE_DEVICE        (1 << 0)
49 #define DM_ACTIVE_UUID          (1 << 1)
50
51 #define DM_ACTIVE_CRYPT_CIPHER  (1 << 2)
52 #define DM_ACTIVE_CRYPT_KEYSIZE (1 << 3)
53 #define DM_ACTIVE_CRYPT_KEY     (1 << 4)
54
55 #define DM_ACTIVE_VERITY_ROOT_HASH      (1 << 5)
56 #define DM_ACTIVE_VERITY_HASH_DEVICE    (1 << 6)
57 #define DM_ACTIVE_VERITY_PARAMS         (1 << 7)
58
59 struct crypt_dm_active_device {
60         enum { DM_CRYPT = 0, DM_VERITY } target;
61         uint64_t size;          /* active device size */
62         uint32_t flags;         /* activation flags */
63         const char *uuid;
64         struct device *data_device;
65         union {
66         struct {
67                 const char *cipher;
68
69                 /* Active key for device */
70                 struct volume_key *vk;
71
72                 /* struct crypt_active_device */
73                 uint64_t offset;        /* offset in sectors */
74                 uint64_t iv_offset;     /* IV initilisation sector */
75         } crypt;
76         struct {
77                 struct device *hash_device;
78
79                 const char *root_hash;
80                 uint32_t root_hash_size;
81
82                 uint64_t hash_offset;   /* hash offset in blocks (not header) */
83                 struct crypt_params_verity *vp;
84         } verity;
85         } u;
86 };
87
88 void dm_backend_init(void);
89 void dm_backend_exit(void);
90
91 int dm_remove_device(struct crypt_device *cd, const char *name,
92                      int force, uint64_t size);
93 int dm_status_device(struct crypt_device *cd, const char *name);
94 int dm_status_suspended(struct crypt_device *cd, const char *name);
95 int dm_status_verity_ok(struct crypt_device *cd, const char *name);
96 int dm_query_device(struct crypt_device *cd, const char *name,
97                     uint32_t get_flags, struct crypt_dm_active_device *dmd);
98 int dm_create_device(struct crypt_device *cd, const char *name,
99                      const char *type, struct crypt_dm_active_device *dmd,
100                      int reload);
101 int dm_suspend_and_wipe_key(struct crypt_device *cd, const char *name);
102 int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
103                                 size_t key_size, const char *key);
104
105 const char *dm_get_dir(void);
106
107 /* These are DM helpers used only by utils_devpath file */
108 int dm_is_dm_device(int major, int minor);
109 int dm_is_dm_kernel_name(const char *name);
110 char *dm_device_path(const char *prefix, int major, int minor);
111
112 #endif /* _UTILS_DM_H */