2 * qcow2.h --- structures and function prototypes for qcow2.c to generate
3 * qcow2 formatted disk images. This format is used originally by QEMU
4 * for virtual machines, and stores the filesystem data on disk in a
5 * packed format to avoid creating sparse image files that need lots of
6 * seeking to read and write.
8 * The qcow2 format supports zlib compression, but that is not yet
11 * It is possible to directly mount a qcow2 image using qemu-nbd:
13 * [root]# modprobe nbd max_part=63
14 * [root]# qemu-nbd -c /dev/nbd0 image.img
15 * [root]# mount /dev/nbd0p1 /mnt/qemu
17 * Format details at http://people.gnome.org/~markmc/qcow-image-format.html
19 * Copyright (C) 2010 Red Hat, Inc., Lukas Czerner <lczerner@redhat.com>
22 * This file may be redistributed under the terms of the GNU Public
27 /* Number of l2 tables in memory before writeback */
28 #define L2_CACHE_PREALLOC 512
31 #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
32 #define QCOW_VERSION 2
33 #define QCOW_OFLAG_COPIED (1ULL << 63)
34 #define QCOW_OFLAG_COMPRESSED (1ULL << 62)
36 #define QCOW_COMPRESSED 1
37 #define QCOW_ENCRYPTED 2
38 #define QCOW_CORRUPTED 3
40 struct ext2_qcow2_hdr {
44 __u64 backing_file_offset;
45 __u32 backing_file_size;
52 __u64 l1_table_offset;
54 __u64 refcount_table_offset;
55 __u32 refcount_table_clusters;
58 __u64 snapshots_offset;
61 typedef struct ext2_qcow2_l2_table L2_CACHE_HEAD;
63 struct ext2_qcow2_l2_table {
70 struct ext2_qcow2_l2_cache {
71 L2_CACHE_HEAD *used_head;
72 L2_CACHE_HEAD *used_tail;
73 L2_CACHE_HEAD *free_head;
79 struct ext2_qcow2_refcount {
80 __u64 *refcount_table;
81 __u64 refcount_table_offset;
82 __u64 refcount_block_offset;
84 __u32 refcount_table_clusters;
85 __u32 refcount_table_index;
86 __u32 refcount_block_index;
88 __u16 *refcount_block;
91 struct ext2_qcow2_image {
93 struct ext2_qcow2_hdr *hdr;
94 struct ext2_qcow2_l2_cache *l2_cache;
95 struct ext2_qcow2_refcount refcount;
107 /* Function prototypes */
111 /* Functions for converting qcow2 image into raw image */
112 struct ext2_qcow2_hdr *qcow2_read_header(int);
113 int qcow2_write_raw_image(int, int, struct ext2_qcow2_hdr *);