Add --enable-discards option to allow discards/TRIM requests.
[platform/upstream/cryptsetup.git] / lib / utils_dm.h
1 #ifndef _UTILS_DM_H
2 #define _UTILS_DM_H
3
4 /* device-mapper library helpers */
5 #include <inttypes.h>
6
7 struct crypt_device;
8 struct volume_key;
9
10 /* Device mapper backend - kernel support flags */
11 #define DM_KEY_WIPE_SUPPORTED (1 << 0)  /* key wipe message */
12 #define DM_LMK_SUPPORTED      (1 << 1)  /* lmk mode */
13 #define DM_SECURE_SUPPORTED   (1 << 2)  /* wipe (secure) buffer flag */
14 #define DM_PLAIN64_SUPPORTED  (1 << 3)  /* plain64 IV */
15 #define DM_DISCARDS_SUPPORTED (1 << 4)  /* discards/TRIM option is supported */
16 uint32_t dm_flags(void);
17
18 #define DM_ACTIVE_DEVICE        (1 << 0)
19 #define DM_ACTIVE_CIPHER        (1 << 1)
20 #define DM_ACTIVE_UUID          (1 << 2)
21 #define DM_ACTIVE_KEY           (1 << 3)
22
23 #define DM_ACTIVE_ALL ( \
24         DM_ACTIVE_DEVICE | \
25         DM_ACTIVE_CIPHER | \
26         DM_ACTIVE_UUID | \
27         DM_ACTIVE_KEY)
28
29 struct crypt_dm_active_device {
30         const char *device;
31         const char *cipher;
32         const char *uuid;
33
34         /* Active key for device */
35         struct volume_key *vk;
36
37         /* struct crypt_active_device */
38         uint64_t offset;        /* offset in sectors */
39         uint64_t iv_offset;     /* IV initilisation sector */
40         uint64_t size;          /* active device size */
41         uint32_t flags;         /* activation flags */
42 };
43
44 const char *dm_get_dir(void);
45 int dm_init(struct crypt_device *context, int check_kernel);
46 void dm_exit(void);
47 int dm_remove_device(const char *name, int force, uint64_t size);
48 int dm_status_device(const char *name);
49 int dm_status_suspended(const char *name);
50 int dm_query_device(const char *name, uint32_t get_flags,
51                     struct crypt_dm_active_device *dmd);
52 int dm_create_device(const char *name,
53                       const char *type,
54                       struct crypt_dm_active_device *dmd,
55                       int reload);
56 int dm_suspend_and_wipe_key(const char *name);
57 int dm_resume_and_reinstate_key(const char *name,
58                                 size_t key_size,
59                                 const char *key);
60 char *dm_device_path(const char *prefix, int major, int minor);
61 int dm_is_dm_device(int major, int minor);
62 int dm_is_dm_kernel_name(const char *name);
63 int dm_check_segment(const char *name, uint64_t offset, uint64_t size);
64
65 #endif /* _UTILS_DM_H */