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 (1LL << 63)
34 #define QCOW_OFLAG_COMPRESSED (1LL << 62)
36 #define QCOW_COMPRESSED 1
37 #define QCOW_ENCRYPTED 2
39 struct ext2_qcow2_hdr {
43 __u64 backing_file_offset;
44 __u32 backing_file_size;
51 __u64 l1_table_offset;
53 __u64 refcount_table_offset;
54 __u32 refcount_table_clusters;
57 __u64 snapshots_offset;
60 typedef struct ext2_qcow2_l2_table L2_CACHE_HEAD;
62 struct ext2_qcow2_l2_table {
69 struct ext2_qcow2_l2_cache {
70 L2_CACHE_HEAD *used_head;
71 L2_CACHE_HEAD *used_tail;
72 L2_CACHE_HEAD *free_head;
78 struct ext2_qcow2_refcount {
79 __u64 *refcount_table;
80 __u64 refcount_table_offset;
81 __u64 refcount_block_offset;
83 __u32 refcount_table_clusters;
84 __u32 refcount_table_index;
85 __u32 refcount_block_index;
87 __u16 *refcount_block;
90 struct ext2_qcow2_image {
92 struct ext2_qcow2_hdr *hdr;
93 struct ext2_qcow2_l2_cache *l2_cache;
94 struct ext2_qcow2_refcount refcount;
106 /* Function prototypes */
110 /* Functions for converting qcow2 image into raw image */
111 struct ext2_qcow2_hdr *qcow2_read_header(int);
112 int qcow2_write_raw_image(int, int, struct ext2_qcow2_hdr *);