aaaa824609bd1da80e03f21bc7f2890e1a0010fd
[platform/upstream/cryptsetup.git] / lib / utils_storage_wrappers.h
1 /*
2  * Generic wrapper for storage functions
3  * (experimental only)
4  *
5  * Copyright (C) 2018-2020, Ondrej Kozina
6  *
7  * This file is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This file 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 GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this file; 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_STORAGE_WRAPPERS_H
23 #define _UTILS_STORAGE_WRAPPERS_H
24
25 struct crypt_storage_wrapper;
26 struct device;
27 struct volume_key;
28 struct crypt_device;
29
30 #define DISABLE_USPACE  (1 << 0)
31 #define DISABLE_KCAPI   (1 << 1)
32 #define DISABLE_DMCRYPT (1 << 2)
33 #define OPEN_READONLY   (1 << 3)
34
35 typedef enum {
36         NONE = 0,
37         USPACE,
38         DMCRYPT
39 } crypt_storage_wrapper_type;
40
41 int crypt_storage_wrapper_init(struct crypt_device *cd,
42         struct crypt_storage_wrapper **cw,
43         struct device *device,
44         uint64_t data_offset,
45         uint64_t iv_start,
46         int sector_size,
47         const char *cipher,
48         struct volume_key *vk,
49         uint32_t flags);
50
51 void crypt_storage_wrapper_destroy(struct crypt_storage_wrapper *cw);
52
53 /* !!! when doing 'read' or 'write' all offset values are RELATIVE to data_offset !!! */
54 ssize_t crypt_storage_wrapper_read(struct crypt_storage_wrapper *cw,
55                 off_t offset, void *buffer, size_t buffer_length);
56 ssize_t crypt_storage_wrapper_read_decrypt(struct crypt_storage_wrapper *cw,
57                 off_t offset, void *buffer, size_t buffer_length);
58 ssize_t crypt_storage_wrapper_decrypt(struct crypt_storage_wrapper *cw,
59                 off_t offset, void *buffer, size_t buffer_length);
60
61 ssize_t crypt_storage_wrapper_write(struct crypt_storage_wrapper *cw,
62                 off_t offset, void *buffer, size_t buffer_length);
63 ssize_t crypt_storage_wrapper_encrypt_write(struct crypt_storage_wrapper *cw,
64                 off_t offset, void *buffer, size_t buffer_length);
65 ssize_t crypt_storage_wrapper_encrypt(struct crypt_storage_wrapper *cw,
66                 off_t offset, void *buffer, size_t buffer_length);
67
68 int crypt_storage_wrapper_datasync(const struct crypt_storage_wrapper *cw);
69
70 crypt_storage_wrapper_type crypt_storage_wrapper_get_type(const struct crypt_storage_wrapper *cw);
71 #endif