Add copyright line for files I have written or modified.
[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  * Copyright (C) 2009-2012, 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  * version 2 as published by the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef _UTILS_DM_H
24 #define _UTILS_DM_H
25
26 /* device-mapper library helpers */
27 #include <inttypes.h>
28
29 struct crypt_device;
30 struct volume_key;
31 struct crypt_params_verity;
32 struct device;
33
34 /* Device mapper backend - kernel support flags */
35 #define DM_KEY_WIPE_SUPPORTED (1 << 0)  /* key wipe message */
36 #define DM_LMK_SUPPORTED      (1 << 1)  /* lmk mode */
37 #define DM_SECURE_SUPPORTED   (1 << 2)  /* wipe (secure) buffer flag */
38 #define DM_PLAIN64_SUPPORTED  (1 << 3)  /* plain64 IV */
39 #define DM_DISCARDS_SUPPORTED (1 << 4)  /* discards/TRIM option is supported */
40 #define DM_VERITY_SUPPORTED   (1 << 5)  /* dm-verity target supported */
41 uint32_t dm_flags(void);
42
43 #define DM_ACTIVE_DEVICE        (1 << 0)
44 #define DM_ACTIVE_UUID          (1 << 1)
45
46 #define DM_ACTIVE_CRYPT_CIPHER  (1 << 2)
47 #define DM_ACTIVE_CRYPT_KEYSIZE (1 << 3)
48 #define DM_ACTIVE_CRYPT_KEY     (1 << 4)
49
50 #define DM_ACTIVE_VERITY_ROOT_HASH      (1 << 5)
51 #define DM_ACTIVE_VERITY_HASH_DEVICE    (1 << 6)
52 #define DM_ACTIVE_VERITY_PARAMS         (1 << 7)
53
54 struct crypt_dm_active_device {
55         enum { DM_CRYPT = 0, DM_VERITY } target;
56         uint64_t size;          /* active device size */
57         uint32_t flags;         /* activation flags */
58         const char *uuid;
59         struct device *data_device;
60         union {
61         struct {
62                 const char *cipher;
63
64                 /* Active key for device */
65                 struct volume_key *vk;
66
67                 /* struct crypt_active_device */
68                 uint64_t offset;        /* offset in sectors */
69                 uint64_t iv_offset;     /* IV initilisation sector */
70         } crypt;
71         struct {
72                 struct device *hash_device;
73
74                 const char *root_hash;
75                 uint32_t root_hash_size;
76
77                 uint64_t hash_offset;   /* hash offset in blocks (not header) */
78                 struct crypt_params_verity *vp;
79         } verity;
80         } u;
81 };
82
83 void dm_backend_init(void);
84 void dm_backend_exit(void);
85
86 int dm_remove_device(struct crypt_device *cd, const char *name,
87                      int force, uint64_t size);
88 int dm_status_device(struct crypt_device *cd, const char *name);
89 int dm_status_suspended(struct crypt_device *cd, const char *name);
90 int dm_status_verity_ok(struct crypt_device *cd, const char *name);
91 int dm_query_device(struct crypt_device *cd, const char *name,
92                     uint32_t get_flags, struct crypt_dm_active_device *dmd);
93 int dm_create_device(struct crypt_device *cd, const char *name,
94                      const char *type, struct crypt_dm_active_device *dmd,
95                      int reload);
96 int dm_suspend_and_wipe_key(struct crypt_device *cd, const char *name);
97 int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
98                                 size_t key_size, const char *key);
99
100 const char *dm_get_dir(void);
101
102 #endif /* _UTILS_DM_H */