Lines Matching refs:header

63 #define HEADER_MAGIC(header) be32toh((header)->magic)
64 #define HEADER_VERSION(header) be32toh((header)->version)
65 #define HEADER_CLUSTER_BITS(header) be32toh((header)->cluster_bits)
66 #define HEADER_CLUSTER_SIZE(header) (1ULL << HEADER_CLUSTER_BITS(header))
67 #define HEADER_L2_BITS(header) (HEADER_CLUSTER_BITS(header) - 3)
68 #define HEADER_SIZE(header) be64toh((header)->size)
69 #define HEADER_CRYPT_METHOD(header) be32toh((header)->crypt_method)
70 #define HEADER_L1_SIZE(header) be32toh((header)->l1_size)
71 #define HEADER_L2_SIZE(header) (HEADER_CLUSTER_SIZE(header)/sizeof(uint64_t))
72 #define HEADER_L1_TABLE_OFFSET(header) be64toh((header)->l1_table_offset)
165 const Header *header,
181 csize_shift = 64 - 2 - (HEADER_CLUSTER_BITS(header) - 8);
182 csize_mask = (1ULL << (HEADER_CLUSTER_BITS(header) - 8)) - 1;
210 static int verify_header(const Header *header) {
211 assert(header);
213 if (HEADER_MAGIC(header) != QCOW2_MAGIC)
216 if (HEADER_VERSION(header) != 2 &&
217 HEADER_VERSION(header) != 3)
220 if (HEADER_CRYPT_METHOD(header) != 0)
223 if (HEADER_CLUSTER_BITS(header) < 9) /* 512K */
226 if (HEADER_CLUSTER_BITS(header) > 21) /* 2MB */
229 if (HEADER_SIZE(header) % HEADER_CLUSTER_SIZE(header) != 0)
232 if (HEADER_L1_SIZE(header) > 32*1024*1024) /* 32MB */
235 if (HEADER_VERSION(header) == 3) {
237 if (header->incompatible_features != 0)
240 if (HEADER_HEADER_LENGTH(header) < sizeof(Header))
251 Header header;
255 l = pread(qcow2_fd, &header, sizeof(header), 0);
258 if (l != sizeof(header))
261 r = verify_header(&header);
265 l1_table = new(be64_t, HEADER_L1_SIZE(&header));
269 l2_table = malloc(HEADER_CLUSTER_SIZE(&header));
273 buffer1 = malloc(HEADER_CLUSTER_SIZE(&header));
277 buffer2 = malloc(HEADER_CLUSTER_SIZE(&header));
285 if (ftruncate(raw_fd, HEADER_SIZE(&header)) < 0)
288 sz = sizeof(uint64_t) * HEADER_L1_SIZE(&header);
289 l = pread(qcow2_fd, l1_table, sz, HEADER_L1_TABLE_OFFSET(&header));
295 for (i = 0; i < HEADER_L1_SIZE(&header); i ++) {
298 r = normalize_offset(&header, l1_table[i], &l2_begin, NULL, NULL);
304 l = pread(qcow2_fd, l2_table, HEADER_CLUSTER_SIZE(&header), l2_begin);
307 if ((uint64_t) l != HEADER_CLUSTER_SIZE(&header))
310 for (j = 0; j < HEADER_L2_SIZE(&header); j++) {
314 p = ((i << HEADER_L2_BITS(&header)) + j) << HEADER_CLUSTER_BITS(&header);
316 r = normalize_offset(&header, l2_table[j], &data_begin, &compressed, &compressed_size);
326 compressed_size, HEADER_CLUSTER_SIZE(&header),
332 HEADER_CLUSTER_SIZE(&header), buffer1);