]> git.proxmox.com Git - mirror_qemu.git/blame - block/qcow2.h
qcow2: Fix L1 allocation size in qcow2_snapshot_load_tmp() (CVE-2014-0145)
[mirror_qemu.git] / block / qcow2.h
CommitLineData
f7d0fe02
KW
1/*
2 * Block driver for the QCOW version 2 format
3 *
4 * Copyright (c) 2004-2006 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#ifndef BLOCK_QCOW2_H
26#define BLOCK_QCOW2_H
27
753d9b82 28#include "qemu/aes.h"
737e150e 29#include "block/coroutine.h"
f7d0fe02 30
14899cdf
FN
31//#define DEBUG_ALLOC
32//#define DEBUG_ALLOC2
33//#define DEBUG_EXT
34
f7d0fe02 35#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
f7d0fe02
KW
36
37#define QCOW_CRYPT_NONE 0
38#define QCOW_CRYPT_AES 1
39
40#define QCOW_MAX_CRYPT_CLUSTERS 32
ce48f2f4 41#define QCOW_MAX_SNAPSHOTS 65536
f7d0fe02 42
2b5d5953
KW
43/* 8 MB refcount table is enough for 2 PB images at 64k cluster size
44 * (128 GB for 512 byte clusters, 2 EB for 2 MB clusters) */
45#define QCOW_MAX_REFTABLE_SIZE 0x800000
46
f7d0fe02 47/* indicate that the refcount of the referenced cluster is exactly one. */
127c84e1 48#define QCOW_OFLAG_COPIED (1ULL << 63)
f7d0fe02 49/* indicate that the cluster is compressed (they never have the copied flag) */
127c84e1 50#define QCOW_OFLAG_COMPRESSED (1ULL << 62)
6377af48 51/* The cluster reads as all zeros */
127c84e1 52#define QCOW_OFLAG_ZERO (1ULL << 0)
f7d0fe02
KW
53
54#define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */
55
56#define MIN_CLUSTER_BITS 9
80ee15a6 57#define MAX_CLUSTER_BITS 21
f7d0fe02
KW
58
59#define L2_CACHE_SIZE 16
60
29c1a730
KW
61/* Must be at least 4 to cover all cases of refcount table growth */
62#define REFCOUNT_CACHE_SIZE 4
63
99cce9fa
KW
64#define DEFAULT_CLUSTER_SIZE 65536
65
acdfb480 66
64aa99d3
KW
67#define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
68#define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
69#define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
70#define QCOW2_OPT_DISCARD_OTHER "pass-discard-other"
05de7e86
HR
71#define QCOW2_OPT_OVERLAP "overlap-check"
72#define QCOW2_OPT_OVERLAP_MAIN_HEADER "overlap-check.main-header"
73#define QCOW2_OPT_OVERLAP_ACTIVE_L1 "overlap-check.active-l1"
74#define QCOW2_OPT_OVERLAP_ACTIVE_L2 "overlap-check.active-l2"
75#define QCOW2_OPT_OVERLAP_REFCOUNT_TABLE "overlap-check.refcount-table"
76#define QCOW2_OPT_OVERLAP_REFCOUNT_BLOCK "overlap-check.refcount-block"
77#define QCOW2_OPT_OVERLAP_SNAPSHOT_TABLE "overlap-check.snapshot-table"
78#define QCOW2_OPT_OVERLAP_INACTIVE_L1 "overlap-check.inactive-l1"
79#define QCOW2_OPT_OVERLAP_INACTIVE_L2 "overlap-check.inactive-l2"
acdfb480 80
f7d0fe02
KW
81typedef struct QCowHeader {
82 uint32_t magic;
83 uint32_t version;
84 uint64_t backing_file_offset;
85 uint32_t backing_file_size;
86 uint32_t cluster_bits;
87 uint64_t size; /* in bytes */
88 uint32_t crypt_method;
89 uint32_t l1_size; /* XXX: save number of clusters instead ? */
90 uint64_t l1_table_offset;
91 uint64_t refcount_table_offset;
92 uint32_t refcount_table_clusters;
93 uint32_t nb_snapshots;
94 uint64_t snapshots_offset;
6744cbab
KW
95
96 /* The following fields are only valid for version >= 3 */
97 uint64_t incompatible_features;
98 uint64_t compatible_features;
99 uint64_t autoclear_features;
100
101 uint32_t refcount_order;
102 uint32_t header_length;
c4217f64 103} QEMU_PACKED QCowHeader;
f7d0fe02 104
ce48f2f4
KW
105typedef struct QEMU_PACKED QCowSnapshotHeader {
106 /* header is 8 byte aligned */
107 uint64_t l1_table_offset;
108
109 uint32_t l1_size;
110 uint16_t id_str_size;
111 uint16_t name_size;
112
113 uint32_t date_sec;
114 uint32_t date_nsec;
115
116 uint64_t vm_clock_nsec;
117
118 uint32_t vm_state_size;
119 uint32_t extra_data_size; /* for extension */
120 /* extra data follows */
121 /* id_str follows */
122 /* name follows */
123} QCowSnapshotHeader;
124
125typedef struct QEMU_PACKED QCowSnapshotExtraData {
126 uint64_t vm_state_size_large;
127 uint64_t disk_size;
128} QCowSnapshotExtraData;
129
130
f7d0fe02
KW
131typedef struct QCowSnapshot {
132 uint64_t l1_table_offset;
133 uint32_t l1_size;
134 char *id_str;
135 char *name;
90b27759 136 uint64_t disk_size;
c2c9a466 137 uint64_t vm_state_size;
f7d0fe02
KW
138 uint32_t date_sec;
139 uint32_t date_nsec;
140 uint64_t vm_clock_nsec;
141} QCowSnapshot;
142
49381094
KW
143struct Qcow2Cache;
144typedef struct Qcow2Cache Qcow2Cache;
145
75bab85c
KW
146typedef struct Qcow2UnknownHeaderExtension {
147 uint32_t magic;
148 uint32_t len;
149 QLIST_ENTRY(Qcow2UnknownHeaderExtension) next;
150 uint8_t data[];
151} Qcow2UnknownHeaderExtension;
152
cfcc4c62
KW
153enum {
154 QCOW2_FEAT_TYPE_INCOMPATIBLE = 0,
155 QCOW2_FEAT_TYPE_COMPATIBLE = 1,
156 QCOW2_FEAT_TYPE_AUTOCLEAR = 2,
157};
158
c61d0004
SH
159/* Incompatible feature bits */
160enum {
161 QCOW2_INCOMPAT_DIRTY_BITNR = 0,
69c98726 162 QCOW2_INCOMPAT_CORRUPT_BITNR = 1,
c61d0004 163 QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
69c98726 164 QCOW2_INCOMPAT_CORRUPT = 1 << QCOW2_INCOMPAT_CORRUPT_BITNR,
c61d0004 165
69c98726
HR
166 QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY
167 | QCOW2_INCOMPAT_CORRUPT,
c61d0004
SH
168};
169
bfe8043e
SH
170/* Compatible feature bits */
171enum {
172 QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR = 0,
173 QCOW2_COMPAT_LAZY_REFCOUNTS = 1 << QCOW2_COMPAT_LAZY_REFCOUNTS_BITNR,
174
175 QCOW2_COMPAT_FEAT_MASK = QCOW2_COMPAT_LAZY_REFCOUNTS,
176};
177
6cfcb9b8
KW
178enum qcow2_discard_type {
179 QCOW2_DISCARD_NEVER = 0,
180 QCOW2_DISCARD_ALWAYS,
181 QCOW2_DISCARD_REQUEST,
182 QCOW2_DISCARD_SNAPSHOT,
183 QCOW2_DISCARD_OTHER,
184 QCOW2_DISCARD_MAX
185};
186
cfcc4c62
KW
187typedef struct Qcow2Feature {
188 uint8_t type;
189 uint8_t bit;
190 char name[46];
191} QEMU_PACKED Qcow2Feature;
192
0b919fae
KW
193typedef struct Qcow2DiscardRegion {
194 BlockDriverState *bs;
195 uint64_t offset;
196 uint64_t bytes;
197 QTAILQ_ENTRY(Qcow2DiscardRegion) next;
198} Qcow2DiscardRegion;
199
f7d0fe02 200typedef struct BDRVQcowState {
f7d0fe02
KW
201 int cluster_bits;
202 int cluster_size;
203 int cluster_sectors;
204 int l2_bits;
205 int l2_size;
206 int l1_size;
207 int l1_vm_state_index;
208 int csize_shift;
209 int csize_mask;
210 uint64_t cluster_offset_mask;
211 uint64_t l1_table_offset;
212 uint64_t *l1_table;
29c1a730
KW
213
214 Qcow2Cache* l2_table_cache;
215 Qcow2Cache* refcount_block_cache;
216
f7d0fe02
KW
217 uint8_t *cluster_cache;
218 uint8_t *cluster_data;
219 uint64_t cluster_cache_offset;
72cf2d4f 220 QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs;
f7d0fe02
KW
221
222 uint64_t *refcount_table;
223 uint64_t refcount_table_offset;
224 uint32_t refcount_table_size;
bb572aef
KW
225 uint64_t free_cluster_index;
226 uint64_t free_byte_offset;
f7d0fe02 227
68d100e9
KW
228 CoMutex lock;
229
f7d0fe02
KW
230 uint32_t crypt_method; /* current crypt method, 0 if no key yet */
231 uint32_t crypt_method_header;
232 AES_KEY aes_encrypt_key;
233 AES_KEY aes_decrypt_key;
234 uint64_t snapshots_offset;
235 int snapshots_size;
ce48f2f4 236 unsigned int nb_snapshots;
f7d0fe02 237 QCowSnapshot *snapshots;
06d9260f
AL
238
239 int flags;
6744cbab 240 int qcow_version;
74c4510a 241 bool use_lazy_refcounts;
b6481f37 242 int refcount_order;
6744cbab 243
67af674e
KW
244 bool discard_passthrough[QCOW2_DISCARD_MAX];
245
3e355390
HR
246 int overlap_check; /* bitmask of Qcow2MetadataOverlap values */
247
6744cbab
KW
248 uint64_t incompatible_features;
249 uint64_t compatible_features;
250 uint64_t autoclear_features;
251
252 size_t unknown_header_fields_size;
253 void* unknown_header_fields;
75bab85c 254 QLIST_HEAD(, Qcow2UnknownHeaderExtension) unknown_header_ext;
0b919fae
KW
255 QTAILQ_HEAD (, Qcow2DiscardRegion) discards;
256 bool cache_discards;
f7d0fe02
KW
257} BDRVQcowState;
258
259/* XXX: use std qcow open function ? */
260typedef struct QCowCreateState {
261 int cluster_size;
262 int cluster_bits;
263 uint16_t *refcount_block;
264 uint64_t *refcount_table;
265 int64_t l1_table_offset;
266 int64_t refcount_table_offset;
267 int64_t refcount_block_offset;
268} QCowCreateState;
269
f214978a
KW
270struct QCowAIOCB;
271
593fb83c
KW
272typedef struct Qcow2COWRegion {
273 /**
274 * Offset of the COW region in bytes from the start of the first cluster
275 * touched by the request.
276 */
277 uint64_t offset;
278
279 /** Number of sectors to copy */
280 int nb_sectors;
281} Qcow2COWRegion;
282
f50f88b9
KW
283/**
284 * Describes an in-flight (part of a) write request that writes to clusters
285 * that are not referenced in their L2 table yet.
286 */
45aba42f
KW
287typedef struct QCowL2Meta
288{
1d3afd64 289 /** Guest offset of the first newly allocated cluster */
45aba42f 290 uint64_t offset;
1d3afd64 291
1d3afd64 292 /** Host offset of the first newly allocated cluster */
250196f1 293 uint64_t alloc_offset;
1d3afd64 294
1d3afd64
KW
295 /**
296 * Number of sectors from the start of the first allocated cluster to
297 * the end of the (possibly shortened) request
298 */
45aba42f 299 int nb_available;
1d3afd64
KW
300
301 /** Number of newly allocated clusters */
45aba42f 302 int nb_clusters;
1d3afd64
KW
303
304 /**
305 * Requests that overlap with this allocation and wait to be restarted
306 * when the allocating request has completed.
307 */
68d100e9 308 CoQueue dependent_requests;
f214978a 309
593fb83c
KW
310 /**
311 * The COW Region between the start of the first allocated cluster and the
312 * area the guest actually writes to.
313 */
314 Qcow2COWRegion cow_start;
315
316 /**
317 * The COW Region between the area the guest actually writes to and the
318 * end of the last allocated cluster.
319 */
320 Qcow2COWRegion cow_end;
321
88c6588c
KW
322 /** Pointer to next L2Meta of the same write request */
323 struct QCowL2Meta *next;
324
72cf2d4f 325 QLIST_ENTRY(QCowL2Meta) next_in_flight;
45aba42f
KW
326} QCowL2Meta;
327
68d000a3
KW
328enum {
329 QCOW2_CLUSTER_UNALLOCATED,
330 QCOW2_CLUSTER_NORMAL,
331 QCOW2_CLUSTER_COMPRESSED,
6377af48 332 QCOW2_CLUSTER_ZERO
68d000a3
KW
333};
334
a40f1c2a
HR
335typedef enum QCow2MetadataOverlap {
336 QCOW2_OL_MAIN_HEADER_BITNR = 0,
337 QCOW2_OL_ACTIVE_L1_BITNR = 1,
338 QCOW2_OL_ACTIVE_L2_BITNR = 2,
339 QCOW2_OL_REFCOUNT_TABLE_BITNR = 3,
340 QCOW2_OL_REFCOUNT_BLOCK_BITNR = 4,
341 QCOW2_OL_SNAPSHOT_TABLE_BITNR = 5,
342 QCOW2_OL_INACTIVE_L1_BITNR = 6,
343 QCOW2_OL_INACTIVE_L2_BITNR = 7,
344
345 QCOW2_OL_MAX_BITNR = 8,
346
347 QCOW2_OL_NONE = 0,
348 QCOW2_OL_MAIN_HEADER = (1 << QCOW2_OL_MAIN_HEADER_BITNR),
349 QCOW2_OL_ACTIVE_L1 = (1 << QCOW2_OL_ACTIVE_L1_BITNR),
350 QCOW2_OL_ACTIVE_L2 = (1 << QCOW2_OL_ACTIVE_L2_BITNR),
351 QCOW2_OL_REFCOUNT_TABLE = (1 << QCOW2_OL_REFCOUNT_TABLE_BITNR),
352 QCOW2_OL_REFCOUNT_BLOCK = (1 << QCOW2_OL_REFCOUNT_BLOCK_BITNR),
353 QCOW2_OL_SNAPSHOT_TABLE = (1 << QCOW2_OL_SNAPSHOT_TABLE_BITNR),
354 QCOW2_OL_INACTIVE_L1 = (1 << QCOW2_OL_INACTIVE_L1_BITNR),
355 /* NOTE: Checking overlaps with inactive L2 tables will result in bdrv
356 * reads. */
357 QCOW2_OL_INACTIVE_L2 = (1 << QCOW2_OL_INACTIVE_L2_BITNR),
358} QCow2MetadataOverlap;
359
4a273c39
HR
360/* Perform all overlap checks which can be done in constant time */
361#define QCOW2_OL_CONSTANT \
362 (QCOW2_OL_MAIN_HEADER | QCOW2_OL_ACTIVE_L1 | QCOW2_OL_REFCOUNT_TABLE | \
363 QCOW2_OL_SNAPSHOT_TABLE)
364
a40f1c2a
HR
365/* Perform all overlap checks which don't require disk access */
366#define QCOW2_OL_CACHED \
4a273c39
HR
367 (QCOW2_OL_CONSTANT | QCOW2_OL_ACTIVE_L2 | QCOW2_OL_REFCOUNT_BLOCK | \
368 QCOW2_OL_INACTIVE_L1)
369
370/* Perform all overlap checks */
371#define QCOW2_OL_ALL \
372 (QCOW2_OL_CACHED | QCOW2_OL_INACTIVE_L2)
a40f1c2a 373
46bae927
HT
374#define L1E_OFFSET_MASK 0x00fffffffffffe00ULL
375#define L2E_OFFSET_MASK 0x00fffffffffffe00ULL
68d000a3
KW
376#define L2E_COMPRESSED_OFFSET_SIZE_MASK 0x3fffffffffffffffULL
377
46bae927 378#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
76dc9e0c 379
3b8e2e26
KW
380static inline int64_t start_of_cluster(BDRVQcowState *s, int64_t offset)
381{
382 return offset & ~(s->cluster_size - 1);
383}
384
c37f4cd7
KW
385static inline int64_t offset_into_cluster(BDRVQcowState *s, int64_t offset)
386{
387 return offset & (s->cluster_size - 1);
388}
389
45aba42f 390static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
f7d0fe02
KW
391{
392 return (size + (s->cluster_size - 1)) >> s->cluster_bits;
393}
394
2cf7cfa1 395static inline int64_t size_to_l1(BDRVQcowState *s, int64_t size)
419b19d9
SH
396{
397 int shift = s->cluster_bits + s->l2_bits;
398 return (size + (1ULL << shift) - 1) >> shift;
399}
400
17a71e58
KW
401static inline int offset_to_l2_index(BDRVQcowState *s, int64_t offset)
402{
403 return (offset >> s->cluster_bits) & (s->l2_size - 1);
404}
405
c142442b
KW
406static inline int64_t align_offset(int64_t offset, int n)
407{
408 offset = (offset + n - 1) & ~(n - 1);
409 return offset;
410}
411
1ebf561c
KW
412static inline int64_t qcow2_vm_state_offset(BDRVQcowState *s)
413{
414 return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
415}
416
2b5d5953
KW
417static inline uint64_t qcow2_max_refcount_clusters(BDRVQcowState *s)
418{
419 return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
420}
421
68d000a3
KW
422static inline int qcow2_get_cluster_type(uint64_t l2_entry)
423{
424 if (l2_entry & QCOW_OFLAG_COMPRESSED) {
425 return QCOW2_CLUSTER_COMPRESSED;
6377af48
KW
426 } else if (l2_entry & QCOW_OFLAG_ZERO) {
427 return QCOW2_CLUSTER_ZERO;
68d000a3
KW
428 } else if (!(l2_entry & L2E_OFFSET_MASK)) {
429 return QCOW2_CLUSTER_UNALLOCATED;
430 } else {
431 return QCOW2_CLUSTER_NORMAL;
432 }
433}
434
bfe8043e
SH
435/* Check whether refcounts are eager or lazy */
436static inline bool qcow2_need_accurate_refcounts(BDRVQcowState *s)
437{
438 return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
439}
c142442b 440
65eb2e35
KW
441static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
442{
443 return m->offset + m->cow_start.offset;
444}
445
446static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
447{
448 return m->offset + m->cow_end.offset
449 + (m->cow_end.nb_sectors << BDRV_SECTOR_BITS);
450}
451
f7d0fe02
KW
452// FIXME Need qcow2_ prefix to global functions
453
454/* qcow2.c functions */
bd28f835
KW
455int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
456 int64_t sector_num, int nb_sectors);
280d3735
KW
457
458int qcow2_mark_dirty(BlockDriverState *bs);
69c98726
HR
459int qcow2_mark_corrupt(BlockDriverState *bs);
460int qcow2_mark_consistent(BlockDriverState *bs);
e24e49e6 461int qcow2_update_header(BlockDriverState *bs);
f7d0fe02
KW
462
463/* qcow2-refcount.c functions */
ed6ccf0f
KW
464int qcow2_refcount_init(BlockDriverState *bs);
465void qcow2_refcount_close(BlockDriverState *bs);
f7d0fe02 466
32b6444d
HR
467int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
468 int addend, enum qcow2_discard_type type);
469
bb572aef 470int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
256900b1
KW
471int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
472 int nb_clusters);
ed6ccf0f
KW
473int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
474void qcow2_free_clusters(BlockDriverState *bs,
6cfcb9b8
KW
475 int64_t offset, int64_t size,
476 enum qcow2_discard_type type);
477void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
478 int nb_clusters, enum qcow2_discard_type type);
f7d0fe02 479
ed6ccf0f
KW
480int qcow2_update_snapshot_refcount(BlockDriverState *bs,
481 int64_t l1_table_offset, int l1_size, int addend);
f7d0fe02 482
166acf54
KW
483int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
484 BdrvCheckMode fix);
f7d0fe02 485
0b919fae
KW
486void qcow2_process_discards(BlockDriverState *bs, int ret);
487
231bb267 488int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
a40f1c2a 489 int64_t size);
231bb267 490int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
a40f1c2a
HR
491 int64_t size);
492
45aba42f 493/* qcow2-cluster.c functions */
2cf7cfa1
KW
494int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
495 bool exact_size);
e23e400e 496int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
ed6ccf0f 497void qcow2_l2_cache_reset(BlockDriverState *bs);
66f82cee 498int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
ed6ccf0f 499void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
45aba42f
KW
500 uint8_t *out_buf, const uint8_t *in_buf,
501 int nb_sectors, int enc,
502 const AES_KEY *key);
503
1c46efaa
KW
504int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
505 int *num, uint64_t *cluster_offset);
f4f0d391 506int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
16f0587e 507 int *num, uint64_t *host_offset, QCowL2Meta **m);
ed6ccf0f 508uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
45aba42f
KW
509 uint64_t offset,
510 int compressed_size);
511
148da7ea 512int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m);
5ea929e3 513int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
670df5e3 514 int nb_sectors, enum qcow2_discard_type type);
621f0589 515int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors);
45aba42f 516
32b6444d
HR
517int qcow2_expand_zero_clusters(BlockDriverState *bs);
518
c142442b 519/* qcow2-snapshot.c functions */
ed6ccf0f
KW
520int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);
521int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id);
a89d89d3
WX
522int qcow2_snapshot_delete(BlockDriverState *bs,
523 const char *snapshot_id,
524 const char *name,
525 Error **errp);
ed6ccf0f 526int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab);
7b4c4781
WX
527int qcow2_snapshot_load_tmp(BlockDriverState *bs,
528 const char *snapshot_id,
529 const char *name,
530 Error **errp);
c142442b 531
ed6ccf0f
KW
532void qcow2_free_snapshots(BlockDriverState *bs);
533int qcow2_read_snapshots(BlockDriverState *bs);
c142442b 534
49381094 535/* qcow2-cache.c functions */
6af4e9ea 536Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);
49381094
KW
537int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
538
539void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
540int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
541int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
542 Qcow2Cache *dependency);
3de0a294 543void qcow2_cache_depends_on_flush(Qcow2Cache *c);
49381094 544
e7108fea
HR
545int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c);
546
49381094
KW
547int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
548 void **table);
549int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
550 void **table);
551int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table);
552
f7d0fe02 553#endif