2 * Generic wrapper for storage functions
5 * Copyright (C) 2018-2023 Ondrej Kozina
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.
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.
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.
22 #ifndef _UTILS_STORAGE_WRAPPERS_H
23 #define _UTILS_STORAGE_WRAPPERS_H
26 #include <sys/types.h>
28 struct crypt_storage_wrapper;
33 #define DISABLE_USPACE (1 << 0)
34 #define DISABLE_KCAPI (1 << 1)
35 #define DISABLE_DMCRYPT (1 << 2)
36 #define OPEN_READONLY (1 << 3)
37 #define LARGE_IV (1 << 4)
43 } crypt_storage_wrapper_type;
45 int crypt_storage_wrapper_init(struct crypt_device *cd,
46 struct crypt_storage_wrapper **cw,
47 struct device *device,
52 struct volume_key *vk,
55 void crypt_storage_wrapper_destroy(struct crypt_storage_wrapper *cw);
57 /* !!! when doing 'read' or 'write' all offset values are RELATIVE to data_offset !!! */
58 ssize_t crypt_storage_wrapper_read(struct crypt_storage_wrapper *cw,
59 off_t offset, void *buffer, size_t buffer_length);
60 ssize_t crypt_storage_wrapper_read_decrypt(struct crypt_storage_wrapper *cw,
61 off_t offset, void *buffer, size_t buffer_length);
62 ssize_t crypt_storage_wrapper_decrypt(struct crypt_storage_wrapper *cw,
63 off_t offset, void *buffer, size_t buffer_length);
65 ssize_t crypt_storage_wrapper_write(struct crypt_storage_wrapper *cw,
66 off_t offset, void *buffer, size_t buffer_length);
67 ssize_t crypt_storage_wrapper_encrypt_write(struct crypt_storage_wrapper *cw,
68 off_t offset, void *buffer, size_t buffer_length);
69 ssize_t crypt_storage_wrapper_encrypt(struct crypt_storage_wrapper *cw,
70 off_t offset, void *buffer, size_t buffer_length);
72 int crypt_storage_wrapper_datasync(const struct crypt_storage_wrapper *cw);
74 crypt_storage_wrapper_type crypt_storage_wrapper_get_type(const struct crypt_storage_wrapper *cw);