block.c (3590b27c7a2be7a24b4b265e2e9458b3761103e1) block.c (6d49d3a859b0f19226dbb0df5e7f50267b42f45c)
1/*
2 * QEMU Crypto block device encryption
3 *
4 * Copyright (c) 2015-2016 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either

--- 101 unchanged lines hidden (view full) ---

110 }
111
112 qemu_mutex_init(&block->mutex);
113
114 return block;
115}
116
117
1/*
2 * QEMU Crypto block device encryption
3 *
4 * Copyright (c) 2015-2016 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either

--- 101 unchanged lines hidden (view full) ---

110 }
111
112 qemu_mutex_init(&block->mutex);
113
114 return block;
115}
116
117
118static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
119 size_t headerlen, void *opaque, Error **errp)
120{
121 size_t *headerlenp = opaque;
122
123 /* Stash away the payload size */
124 *headerlenp = headerlen;
125 return 0;
126}
127
128
129static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
130 size_t offset, const uint8_t *buf, size_t buflen,
131 void *opaque, Error **errp)
132{
133 /* Discard the bytes, we're not actually writing to an image */
134 return buflen;
135}
136
137
138bool
139qcrypto_block_calculate_payload_offset(QCryptoBlockCreateOptions *create_opts,
140 const char *optprefix,
141 size_t *len,
142 Error **errp)
143{
144 /* Fake LUKS creation in order to determine the payload size */
145 g_autoptr(QCryptoBlock) crypto =
146 qcrypto_block_create(create_opts, optprefix,
147 qcrypto_block_headerlen_hdr_init_func,
148 qcrypto_block_headerlen_hdr_write_func,
149 len, errp);
150 return crypto != NULL;
151}
152
153
118QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
119 Error **errp)
120{
121 QCryptoBlockInfo *info = g_new0(QCryptoBlockInfo, 1);
122
123 info->format = block->format;
124
125 if (block->driver->get_info &&

--- 285 unchanged lines hidden ---
154QCryptoBlockInfo *qcrypto_block_get_info(QCryptoBlock *block,
155 Error **errp)
156{
157 QCryptoBlockInfo *info = g_new0(QCryptoBlockInfo, 1);
158
159 info->format = block->format;
160
161 if (block->driver->get_info &&

--- 285 unchanged lines hidden ---