root / include / vhd.h @ abdb293f
History | View | Annotate | Download (9.8 kB)
1 |
/*
|
---|---|
2 |
* Copyright (c) 2007, XenSource Inc.
|
3 |
* Copyright (c) 2010, Citrix Systems, Inc.
|
4 |
* All rights reserved.
|
5 |
*
|
6 |
* Redistribution and use in source and binary forms, with or without
|
7 |
* modification, are permitted provided that the following conditions are met:
|
8 |
* * Redistributions of source code must retain the above copyright
|
9 |
* notice, this list of conditions and the following disclaimer.
|
10 |
* * Redistributions in binary form must reproduce the above copyright
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
12 |
* documentation and/or other materials provided with the distribution.
|
13 |
* * Neither the name of XenSource Inc. nor the names of its contributors
|
14 |
* may be used to endorse or promote products derived from this software
|
15 |
* without specific prior written permission.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
21 |
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
22 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
23 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
24 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
25 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
26 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28 |
*/
|
29 |
|
30 |
#ifndef __VHD_H__
|
31 |
#define __VHD_H__
|
32 |
|
33 |
#include <inttypes.h> |
34 |
#include <uuid/uuid.h> |
35 |
|
36 |
#define DEBUG 1 |
37 |
|
38 |
/* ---------------------------------------------------------------------- */
|
39 |
/* General definitions. */
|
40 |
/* ---------------------------------------------------------------------- */
|
41 |
|
42 |
#define VHD_SECTOR_SIZE 512 |
43 |
#define VHD_SECTOR_SHIFT 9 |
44 |
|
45 |
/* ---------------------------------------------------------------------- */
|
46 |
/* This is the generic disk footer, used by all disks. */
|
47 |
/* ---------------------------------------------------------------------- */
|
48 |
|
49 |
struct hd_ftr {
|
50 |
char cookie[8]; /* Identifies original creator of the disk */ |
51 |
uint32_t features; /* Feature Support -- see below */
|
52 |
uint32_t ff_version; /* (major,minor) version of disk file */
|
53 |
uint64_t data_offset; /* Abs. offset from SOF to next structure */
|
54 |
uint32_t timestamp; /* Creation time. secs since 1/1/2000GMT */
|
55 |
char crtr_app[4]; /* Creator application */ |
56 |
uint32_t crtr_ver; /* Creator version (major,minor) */
|
57 |
uint32_t crtr_os; /* Creator host OS */
|
58 |
uint64_t orig_size; /* Size at creation (bytes) */
|
59 |
uint64_t curr_size; /* Current size of disk (bytes) */
|
60 |
uint32_t geometry; /* Disk geometry */
|
61 |
uint32_t type; /* Disk type */
|
62 |
uint32_t checksum; /* 1's comp sum of this struct. */
|
63 |
uuid_t uuid; /* Unique disk ID, used for naming parents */
|
64 |
char saved; /* one-bit -- is this disk/VM in a saved state? */ |
65 |
char hidden; /* tapdisk-specific field: is this vdi hidden? */ |
66 |
char reserved[426]; /* padding */ |
67 |
}; |
68 |
|
69 |
/* VHD cookie string. */
|
70 |
static const char HD_COOKIE[9] = "conectix"; |
71 |
|
72 |
/* Feature fields in hd_ftr */
|
73 |
#define HD_NO_FEATURES 0x00000000 |
74 |
#define HD_TEMPORARY 0x00000001 /* disk can be deleted on shutdown */ |
75 |
#define HD_RESERVED 0x00000002 /* NOTE: must always be set */ |
76 |
|
77 |
/* Version field in hd_ftr */
|
78 |
#define HD_FF_VERSION 0x00010000 |
79 |
|
80 |
/* Known creator OS type fields in hd_ftr.crtr_os */
|
81 |
#define HD_CR_OS_WINDOWS 0x5769326B /* (Wi2k) */ |
82 |
#define HD_CR_OS_MACINTOSH 0x4D616320 /* (Mac ) */ |
83 |
|
84 |
/*
|
85 |
* version 0.1: little endian bitmaps
|
86 |
* version 1.1: big endian bitmaps; batmap
|
87 |
* version 1.2: libvhd
|
88 |
* version 1.3: batmap version bump to 1.2
|
89 |
*/
|
90 |
#define VHD_VERSION(major, minor) (((major) << 16) | ((minor) & 0x0000FFFF)) |
91 |
#define VHD_CURRENT_VERSION VHD_VERSION(1, 3) |
92 |
|
93 |
/* Disk geometry accessor macros. */
|
94 |
/* Geometry is a triple of (cylinders (2 bytes), tracks (1 byte), and
|
95 |
* secotrs-per-track (1 byte))
|
96 |
*/
|
97 |
#define GEOM_GET_CYLS(_g) (((_g) >> 16) & 0xffff) |
98 |
#define GEOM_GET_HEADS(_g) (((_g) >> 8) & 0xff) |
99 |
#define GEOM_GET_SPT(_g) ((_g) & 0xff) |
100 |
|
101 |
#define GEOM_ENCODE(_c, _h, _s) (((_c) << 16) | ((_h) << 8) | (_s)) |
102 |
|
103 |
/* type field in hd_ftr */
|
104 |
#define HD_TYPE_NONE 0 |
105 |
#define HD_TYPE_FIXED 2 /* fixed-allocation disk */ |
106 |
#define HD_TYPE_DYNAMIC 3 /* dynamic disk */ |
107 |
#define HD_TYPE_DIFF 4 /* differencing disk */ |
108 |
#define HD_TYPE_MAX 6 |
109 |
|
110 |
struct prt_loc {
|
111 |
uint32_t code; /* Platform code -- see defines below. */
|
112 |
uint32_t data_space; /* Number of 512-byte sectors to store locator */
|
113 |
uint32_t data_len; /* Actual length of parent locator in bytes */
|
114 |
uint32_t res; /* Must be zero */
|
115 |
uint64_t data_offset; /* Absolute offset of locator data (bytes) */
|
116 |
}; |
117 |
|
118 |
/* Platform Codes */
|
119 |
#define PLAT_CODE_NONE 0x0 |
120 |
#define PLAT_CODE_WI2R 0x57693272 /* deprecated */ |
121 |
#define PLAT_CODE_WI2K 0x5769326B /* deprecated */ |
122 |
#define PLAT_CODE_W2RU 0x57327275 /* Windows relative path (UTF-16) */ |
123 |
#define PLAT_CODE_W2KU 0x57326B75 /* Windows absolute path (UTF-16) */ |
124 |
#define PLAT_CODE_MAC 0x4D616320 /* MacOS alias stored as a blob. */ |
125 |
#define PLAT_CODE_MACX 0x4D616358 /* File URL (UTF-8), see RFC 2396. */ |
126 |
|
127 |
/* ---------------------------------------------------------------------- */
|
128 |
/* This is the dynamic disk header. */
|
129 |
/* ---------------------------------------------------------------------- */
|
130 |
|
131 |
struct dd_hdr {
|
132 |
char cookie[8]; /* Should contain "cxsparse" */ |
133 |
uint64_t data_offset; /* Byte offset of next record. (Unused) 0xffs */
|
134 |
uint64_t table_offset; /* Absolute offset to the BAT. */
|
135 |
uint32_t hdr_ver; /* Version of the dd_hdr (major,minor) */
|
136 |
uint32_t max_bat_size; /* Maximum number of entries in the BAT */
|
137 |
uint32_t block_size; /* Block size in bytes. Must be power of 2. */
|
138 |
uint32_t checksum; /* Header checksum. 1's comp of all fields. */
|
139 |
uuid_t prt_uuid; /* ID of the parent disk. */
|
140 |
uint32_t prt_ts; /* Modification time of the parent disk */
|
141 |
uint32_t res1; /* Reserved. */
|
142 |
char prt_name[512]; /* Parent unicode name. */ |
143 |
struct prt_loc loc[8]; /* Parent locator entries. */ |
144 |
char res2[256]; /* Reserved. */ |
145 |
}; |
146 |
|
147 |
/* VHD cookie string. */
|
148 |
static const char DD_COOKIE[9] = "cxsparse"; |
149 |
|
150 |
/* Version field in hd_ftr */
|
151 |
#define DD_VERSION 0x00010000 |
152 |
|
153 |
/* Default blocksize is 2 meg. */
|
154 |
#define DD_BLOCKSIZE_DEFAULT 0x00200000 |
155 |
|
156 |
#define DD_BLK_UNUSED 0xFFFFFFFF |
157 |
|
158 |
struct dd_batmap_hdr {
|
159 |
char cookie[8]; /* should contain "tdbatmap" */ |
160 |
uint64_t batmap_offset; /* byte offset to batmap */
|
161 |
uint32_t batmap_size; /* batmap size in sectors */
|
162 |
uint32_t batmap_version; /* version of batmap */
|
163 |
uint32_t checksum; /* batmap checksum -- 1's complement of batmap */
|
164 |
char marker; /* generic marker field */ |
165 |
}; |
166 |
|
167 |
static const char VHD_BATMAP_COOKIE[9] = "tdbatmap"; |
168 |
|
169 |
/*
|
170 |
* version 1.1: signed char checksum
|
171 |
*/
|
172 |
#define VHD_BATMAP_VERSION(major, minor) (((major) << 16) | ((minor) & 0x0000FFFF)) |
173 |
#define VHD_BATMAP_CURRENT_VERSION VHD_BATMAP_VERSION(1, 2) |
174 |
|
175 |
/* Layout of a dynamic disk:
|
176 |
*
|
177 |
* +-------------------------------------------------+
|
178 |
* | Mirror image of HD footer (hd_ftr) (512 bytes) |
|
179 |
* +-------------------------------------------------+
|
180 |
* | Sparse drive header (dd_hdr) (1024 bytes) |
|
181 |
* +-------------------------------------------------+
|
182 |
* | BAT (Block allocation table) |
|
183 |
* | - Array of absolute sector offsets into the |
|
184 |
* | file (uint32_t). |
|
185 |
* | - Rounded up to a sector boundary. |
|
186 |
* | - Unused entries are marked as 0xFFFFFFFF |
|
187 |
* | - max entries in dd_hdr->max_bat_size |
|
188 |
* +-------------------------------------------------+
|
189 |
* | Data Block 0 |
|
190 |
* | Bitmap (padded to 512 byte sector boundary) |
|
191 |
* | - each bit indicates whether the associated |
|
192 |
* | sector within this block is used. |
|
193 |
* | Data |
|
194 |
* | - power-of-two multiple of sectors. |
|
195 |
* | - default 2MB (4096 * 512) |
|
196 |
* | - Any entries with zero in bitmap should be |
|
197 |
* | zero on disk |
|
198 |
* +-------------------------------------------------+
|
199 |
* | Data Block 1 |
|
200 |
* +-------------------------------------------------+
|
201 |
* | ... |
|
202 |
* +-------------------------------------------------+
|
203 |
* | Data Block n |
|
204 |
* +-------------------------------------------------+
|
205 |
* | HD Footer (511 bytes) |
|
206 |
* +-------------------------------------------------+
|
207 |
*/
|
208 |
|
209 |
#endif
|