6eb24c17a95f27faa198029d3fb78e0d79c119c1
[platform/upstream/cryptsetup.git] / lib / utils_dm.h
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-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef _UTILS_DM_H
23 #define _UTILS_DM_H
24
25 /* device-mapper library helpers */
26 #include <inttypes.h>
27
28 struct crypt_device;
29 struct volume_key;
30 struct crypt_params_verity;
31
32 /* Device mapper backend - kernel support flags */
33 #define DM_KEY_WIPE_SUPPORTED (1 << 0)  /* key wipe message */
34 #define DM_LMK_SUPPORTED      (1 << 1)  /* lmk mode */
35 #define DM_SECURE_SUPPORTED   (1 << 2)  /* wipe (secure) buffer flag */
36 #define DM_PLAIN64_SUPPORTED  (1 << 3)  /* plain64 IV */
37 #define DM_DISCARDS_SUPPORTED (1 << 4)  /* discards/TRIM option is supported */
38 #define DM_VERITY_SUPPORTED   (1 << 5)  /* dm-verity target supported */
39 uint32_t dm_flags(void);
40
41 #define DM_ACTIVE_DEVICE        (1 << 0)
42 #define DM_ACTIVE_CIPHER        (1 << 1)
43 #define DM_ACTIVE_UUID          (1 << 2)
44 #define DM_ACTIVE_KEYSIZE       (1 << 3)
45 #define DM_ACTIVE_KEY           (1 << 4)
46
47 struct crypt_dm_active_device {
48         enum { DM_CRYPT = 0, DM_VERITY } target;
49         uint64_t size;          /* active device size */
50         uint32_t flags;         /* activation flags */
51         const char *uuid;
52         union {
53         struct {
54                 const char *device;
55                 const char *cipher;
56
57                 /* Active key for device */
58                 struct volume_key *vk;
59
60                 /* struct crypt_active_device */
61                 uint64_t offset;        /* offset in sectors */
62                 uint64_t iv_offset;     /* IV initilisation sector */
63         } crypt;
64         struct {
65                 const char *data_device;
66                 const char *hash_device;
67
68                 const char *root_hash;
69                 size_t root_hash_size;
70
71                 uint64_t hash_offset;   /* hash offset (not header) */
72         } verity;
73         } u;
74 };
75
76 struct crypt_dm_active_verity {
77         const char *data_device;
78         const char *hash_device;
79
80         const char *root_hash;
81         size_t root_hash_size;
82
83         uint64_t hash_offset;   /* hash offset (not header) */
84         uint64_t size;          /* active device size */
85         uint32_t flags;         /* activation flags */
86 };
87
88 const char *dm_get_dir(void);
89 int dm_init(struct crypt_device *context, int check_kernel);
90 void dm_exit(void);
91 int dm_remove_device(const char *name, int force, uint64_t size);
92 int dm_status_device(const char *name);
93 int dm_status_suspended(const char *name);
94 int dm_status_verity_ok(const char *name);
95 int dm_query_device(const char *name, uint32_t get_flags,
96                     struct crypt_dm_active_device *dmd);
97 int dm_query_verity(const char *name,
98                     struct crypt_dm_active_verity *dmd);
99 int dm_create_device(const char *name,
100                       const char *type,
101                       struct crypt_dm_active_device *dmd,
102                       int reload);
103 int dm_create_verity(const char *name,
104                      struct crypt_params_verity *params,
105                      struct crypt_dm_active_verity *dmd);
106 int dm_suspend_and_wipe_key(const char *name);
107 int dm_resume_and_reinstate_key(const char *name,
108                                 size_t key_size,
109                                 const char *key);
110 char *dm_device_path(const char *prefix, int major, int minor);
111 int dm_is_dm_device(int major, int minor);
112 int dm_is_dm_kernel_name(const char *name);
113 int dm_check_segment(const char *name, uint64_t offset, uint64_t size);
114
115 #endif /* _UTILS_DM_H */