2 * Block driver for the VMDK format
4 * Copyright (c) 2004 Fabrice Bellard
5 * Copyright (c) 2005 Filip Navara
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "block_int.h"
29 #define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
30 #define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
35 uint32_t disk_sectors
;
37 uint32_t l1dir_offset
;
39 uint32_t file_sectors
;
42 uint32_t sectors_per_track
;
52 int32_t num_gtes_per_gte
;
58 } __attribute__((packed
)) VMDK4Header
;
60 #define L2_CACHE_SIZE 16
62 typedef struct BDRVVmdkState
{
64 int64_t l1_table_offset
;
65 int64_t l1_backup_table_offset
;
67 uint32_t *l1_backup_table
;
69 uint32_t l1_entry_sectors
;
73 uint32_t l2_cache_offsets
[L2_CACHE_SIZE
];
74 uint32_t l2_cache_counts
[L2_CACHE_SIZE
];
76 unsigned int cluster_sectors
;
81 DiskIOStatistics
vmdk_io_statistics(BlockDriverState
*bs
)
83 BDRVVmdkState
*s
= bs
->opaque
;
84 // return disk I/O counters
88 static int vmdk_probe(const uint8_t *buf
, int buf_size
, const char *filename
)
94 magic
= be32_to_cpu(*(uint32_t *)buf
);
95 if (magic
== VMDK3_MAGIC
||
104 #define SECTOR_SIZE 512
105 #define DESC_SIZE 20*SECTOR_SIZE // 20 sectors of 512 bytes each
106 #define HEADER_SIZE 512 // first sector of 512 bytes
108 static uint32_t vmdk_read_cid(BlockDriverState
*bs
, int parent
)
110 BDRVVmdkState
*s
= bs
->opaque
;
111 char desc
[DESC_SIZE
];
113 char *p_name
, *cid_str
;
116 /* the descriptor offset = 0x200 */
117 if (bdrv_pread(s
->hd
, 0x200, desc
, DESC_SIZE
) != DESC_SIZE
)
121 cid_str
= "parentCID";
122 cid_str_size
= sizeof("parentCID");
125 cid_str_size
= sizeof("CID");
128 if ((p_name
= strstr(desc
,cid_str
)) != 0) {
129 p_name
+= cid_str_size
;
130 sscanf(p_name
,"%x",&cid
);
136 static int vmdk_write_cid(BlockDriverState
*bs
, uint32_t cid
)
138 BDRVVmdkState
*s
= bs
->opaque
;
139 char desc
[DESC_SIZE
], tmp_desc
[DESC_SIZE
];
140 char *p_name
, *tmp_str
;
142 /* the descriptor offset = 0x200 */
143 if (bdrv_pread(s
->hd
, 0x200, desc
, DESC_SIZE
) != DESC_SIZE
)
146 tmp_str
= strstr(desc
,"parentCID");
147 strcpy(tmp_desc
, tmp_str
);
148 if ((p_name
= strstr(desc
,"CID")) != 0) {
149 p_name
+= sizeof("CID");
150 sprintf(p_name
,"%x\n",cid
);
151 strcat(desc
,tmp_desc
);
154 if (bdrv_pwrite(s
->hd
, 0x200, desc
, DESC_SIZE
) != DESC_SIZE
)
159 static int vmdk_is_cid_valid(BlockDriverState
*bs
)
162 BDRVVmdkState
*s
= bs
->opaque
;
163 BlockDriverState
*p_bs
= s
->hd
->backing_hd
;
167 cur_pcid
= vmdk_read_cid(p_bs
,0);
168 if (s
->parent_cid
!= cur_pcid
)
177 static int vmdk_snapshot_create(const char *filename
, const char *backing_file
)
181 char *p_name
, *gd_buf
, *rgd_buf
;
182 const char *real_filename
, *temp_str
;
184 uint32_t gde_entries
, gd_size
;
185 int64_t gd_offset
, rgd_offset
, capacity
, gt_size
;
186 char p_desc
[DESC_SIZE
], s_desc
[DESC_SIZE
], hdr
[HEADER_SIZE
];
187 char *desc_template
=
188 "# Disk DescriptorFile\n"
192 "createType=\"monolithicSparse\"\n"
193 "parentFileNameHint=\"%s\"\n"
195 "# Extent description\n"
196 "RW %lu SPARSE \"%s\"\n"
198 "# The Disk Data Base \n"
202 snp_fd
= open(filename
, O_RDWR
| O_CREAT
| O_TRUNC
| O_BINARY
| O_LARGEFILE
, 0644);
205 p_fd
= open(backing_file
, O_RDONLY
| O_BINARY
| O_LARGEFILE
);
211 /* read the header */
212 if (lseek(p_fd
, 0x0, SEEK_SET
) == -1)
214 if (read(p_fd
, hdr
, HEADER_SIZE
) != HEADER_SIZE
)
217 /* write the header */
218 if (lseek(snp_fd
, 0x0, SEEK_SET
) == -1)
220 if (write(snp_fd
, hdr
, HEADER_SIZE
) == -1)
223 memset(&header
, 0, sizeof(header
));
224 memcpy(&header
,&hdr
[4], sizeof(header
)); // skip the VMDK4_MAGIC
226 ftruncate(snp_fd
, header
.grain_offset
<< 9);
227 /* the descriptor offset = 0x200 */
228 if (lseek(p_fd
, 0x200, SEEK_SET
) == -1)
230 if (read(p_fd
, p_desc
, DESC_SIZE
) != DESC_SIZE
)
233 if ((p_name
= strstr(p_desc
,"CID")) != 0) {
234 p_name
+= sizeof("CID");
235 sscanf(p_name
,"%x",&p_cid
);
238 real_filename
= filename
;
239 if ((temp_str
= strrchr(real_filename
, '\\')) != NULL
)
240 real_filename
= temp_str
+ 1;
241 if ((temp_str
= strrchr(real_filename
, '/')) != NULL
)
242 real_filename
= temp_str
+ 1;
243 if ((temp_str
= strrchr(real_filename
, ':')) != NULL
)
244 real_filename
= temp_str
+ 1;
246 sprintf(s_desc
, desc_template
, p_cid
, p_cid
, backing_file
247 , (uint32_t)header
.capacity
, real_filename
);
249 /* write the descriptor */
250 if (lseek(snp_fd
, 0x200, SEEK_SET
) == -1)
252 if (write(snp_fd
, s_desc
, strlen(s_desc
)) == -1)
255 gd_offset
= header
.gd_offset
* SECTOR_SIZE
; // offset of GD table
256 rgd_offset
= header
.rgd_offset
* SECTOR_SIZE
; // offset of RGD table
257 capacity
= header
.capacity
* SECTOR_SIZE
; // Extent size
259 * Each GDE span 32M disk, means:
260 * 512 GTE per GT, each GTE points to grain
262 gt_size
= (int64_t)header
.num_gtes_per_gte
* header
.granularity
* SECTOR_SIZE
;
265 gde_entries
= (uint32_t)(capacity
/ gt_size
); // number of gde/rgde
266 gd_size
= gde_entries
* sizeof(uint32_t);
269 rgd_buf
= qemu_malloc(gd_size
);
272 if (lseek(p_fd
, rgd_offset
, SEEK_SET
) == -1)
274 if (read(p_fd
, rgd_buf
, gd_size
) != gd_size
)
276 if (lseek(snp_fd
, rgd_offset
, SEEK_SET
) == -1)
278 if (write(snp_fd
, rgd_buf
, gd_size
) == -1)
283 gd_buf
= qemu_malloc(gd_size
);
286 if (lseek(p_fd
, gd_offset
, SEEK_SET
) == -1)
288 if (read(p_fd
, gd_buf
, gd_size
) != gd_size
)
290 if (lseek(snp_fd
, gd_offset
, SEEK_SET
) == -1)
292 if (write(snp_fd
, gd_buf
, gd_size
) == -1)
310 static void vmdk_parent_close(BlockDriverState
*bs
)
313 bdrv_close(bs
->backing_hd
);
317 static int vmdk_parent_open(BlockDriverState
*bs
, const char * filename
)
319 BDRVVmdkState
*s
= bs
->opaque
;
321 char desc
[DESC_SIZE
];
322 char parent_img_name
[1024];
324 /* the descriptor offset = 0x200 */
325 if (bdrv_pread(s
->hd
, 0x200, desc
, DESC_SIZE
) != DESC_SIZE
)
328 if ((p_name
= strstr(desc
,"parentFileNameHint")) != 0) {
330 struct stat file_buf
;
332 p_name
+= sizeof("parentFileNameHint") + 1;
333 if ((end_name
= strchr(p_name
,'\"')) == 0)
336 strncpy(s
->hd
->backing_file
, p_name
, end_name
- p_name
);
337 if (stat(s
->hd
->backing_file
, &file_buf
) != 0) {
338 path_combine(parent_img_name
, sizeof(parent_img_name
),
339 filename
, s
->hd
->backing_file
);
341 strcpy(parent_img_name
, s
->hd
->backing_file
);
344 s
->hd
->backing_hd
= bdrv_new("");
345 if (!s
->hd
->backing_hd
) {
350 if (bdrv_open(s
->hd
->backing_hd
, parent_img_name
, 0) < 0)
357 static int vmdk_open(BlockDriverState
*bs
, const char *filename
, int flags
)
359 BDRVVmdkState
*s
= bs
->opaque
;
363 ret
= bdrv_file_open(&s
->hd
, filename
, flags
);
366 if (bdrv_pread(s
->hd
, 0, &magic
, sizeof(magic
)) != sizeof(magic
))
369 magic
= be32_to_cpu(magic
);
370 if (magic
== VMDK3_MAGIC
) {
373 if (bdrv_pread(s
->hd
, sizeof(magic
), &header
, sizeof(header
)) != sizeof(header
))
375 s
->cluster_sectors
= le32_to_cpu(header
.granularity
);
378 bs
->total_sectors
= le32_to_cpu(header
.disk_sectors
);
379 s
->l1_table_offset
= le32_to_cpu(header
.l1dir_offset
) << 9;
380 s
->l1_backup_table_offset
= 0;
381 s
->l1_entry_sectors
= s
->l2_size
* s
->cluster_sectors
;
382 } else if (magic
== VMDK4_MAGIC
) {
385 if (bdrv_pread(s
->hd
, sizeof(magic
), &header
, sizeof(header
)) != sizeof(header
))
387 bs
->total_sectors
= le64_to_cpu(header
.capacity
);
388 s
->cluster_sectors
= le64_to_cpu(header
.granularity
);
389 s
->l2_size
= le32_to_cpu(header
.num_gtes_per_gte
);
390 s
->l1_entry_sectors
= s
->l2_size
* s
->cluster_sectors
;
391 if (s
->l1_entry_sectors
<= 0)
393 s
->l1_size
= (bs
->total_sectors
+ s
->l1_entry_sectors
- 1)
394 / s
->l1_entry_sectors
;
395 s
->l1_table_offset
= le64_to_cpu(header
.rgd_offset
) << 9;
396 s
->l1_backup_table_offset
= le64_to_cpu(header
.gd_offset
) << 9;
398 // try to open parent images, if exist
399 if (vmdk_parent_open(bs
, filename
) != 0)
401 // write the CID once after the image creation
402 s
->parent_cid
= vmdk_read_cid(bs
,1);
407 /* read the L1 table */
408 l1_size
= s
->l1_size
* sizeof(uint32_t);
409 s
->l1_table
= qemu_malloc(l1_size
);
412 if (bdrv_pread(s
->hd
, s
->l1_table_offset
, s
->l1_table
, l1_size
) != l1_size
)
414 for(i
= 0; i
< s
->l1_size
; i
++) {
415 le32_to_cpus(&s
->l1_table
[i
]);
418 if (s
->l1_backup_table_offset
) {
419 s
->l1_backup_table
= qemu_malloc(l1_size
);
420 if (!s
->l1_backup_table
)
422 if (bdrv_pread(s
->hd
, s
->l1_backup_table_offset
, s
->l1_backup_table
, l1_size
) != l1_size
)
424 for(i
= 0; i
< s
->l1_size
; i
++) {
425 le32_to_cpus(&s
->l1_backup_table
[i
]);
429 s
->l2_cache
= qemu_malloc(s
->l2_size
* L2_CACHE_SIZE
* sizeof(uint32_t));
434 qemu_free(s
->l1_backup_table
);
435 qemu_free(s
->l1_table
);
436 qemu_free(s
->l2_cache
);
441 static uint64_t get_cluster_offset(BlockDriverState
*bs
, uint64_t offset
, int allocate
);
443 static int get_whole_cluster(BlockDriverState
*bs
, uint64_t cluster_offset
,
444 uint64_t offset
, int allocate
)
446 uint64_t parent_cluster_offset
;
447 BDRVVmdkState
*s
= bs
->opaque
;
448 uint8_t whole_grain
[s
->cluster_sectors
*512]; // 128 sectors * 512 bytes each = grain size 64KB
450 // we will be here if it's first write on non-exist grain(cluster).
451 // try to read from parent image, if exist
452 if (s
->hd
->backing_hd
) {
453 BDRVVmdkState
*ps
= s
->hd
->backing_hd
->opaque
;
455 if (!vmdk_is_cid_valid(bs
))
457 parent_cluster_offset
= get_cluster_offset(s
->hd
->backing_hd
, offset
, allocate
);
458 if (bdrv_pread(ps
->hd
, parent_cluster_offset
, whole_grain
, ps
->cluster_sectors
*512) !=
459 ps
->cluster_sectors
*512)
462 if (bdrv_pwrite(s
->hd
, cluster_offset
<< 9, whole_grain
, sizeof(whole_grain
)) !=
469 static uint64_t get_cluster_offset(BlockDriverState
*bs
,
470 uint64_t offset
, int allocate
)
472 BDRVVmdkState
*s
= bs
->opaque
;
473 unsigned int l1_index
, l2_offset
, l2_index
;
475 uint32_t min_count
, *l2_table
, tmp
;
476 uint64_t cluster_offset
;
478 l1_index
= (offset
>> 9) / s
->l1_entry_sectors
;
479 if (l1_index
>= s
->l1_size
)
481 l2_offset
= s
->l1_table
[l1_index
];
484 for(i
= 0; i
< L2_CACHE_SIZE
; i
++) {
485 if (l2_offset
== s
->l2_cache_offsets
[i
]) {
486 /* increment the hit count */
487 if (++s
->l2_cache_counts
[i
] == 0xffffffff) {
488 for(j
= 0; j
< L2_CACHE_SIZE
; j
++) {
489 s
->l2_cache_counts
[j
] >>= 1;
492 l2_table
= s
->l2_cache
+ (i
* s
->l2_size
);
496 /* not found: load a new entry in the least used one */
498 min_count
= 0xffffffff;
499 for(i
= 0; i
< L2_CACHE_SIZE
; i
++) {
500 if (s
->l2_cache_counts
[i
] < min_count
) {
501 min_count
= s
->l2_cache_counts
[i
];
505 l2_table
= s
->l2_cache
+ (min_index
* s
->l2_size
);
506 if (bdrv_pread(s
->hd
, (int64_t)l2_offset
* 512, l2_table
, s
->l2_size
* sizeof(uint32_t)) !=
507 s
->l2_size
* sizeof(uint32_t))
510 s
->l2_cache_offsets
[min_index
] = l2_offset
;
511 s
->l2_cache_counts
[min_index
] = 1;
513 l2_index
= ((offset
>> 9) / s
->cluster_sectors
) % s
->l2_size
;
514 cluster_offset
= le32_to_cpu(l2_table
[l2_index
]);
515 if (!cluster_offset
) {
516 struct stat file_buf
;
520 stat(s
->hd
->filename
, &file_buf
);
521 cluster_offset
= file_buf
.st_size
;
522 bdrv_truncate(s
->hd
, cluster_offset
+ (s
->cluster_sectors
<< 9));
524 cluster_offset
>>= 9;
525 /* update L2 table */
526 tmp
= cpu_to_le32(cluster_offset
);
527 l2_table
[l2_index
] = tmp
;
528 if (bdrv_pwrite(s
->hd
, ((int64_t)l2_offset
* 512) + (l2_index
* sizeof(tmp
)),
529 &tmp
, sizeof(tmp
)) != sizeof(tmp
))
531 /* update backup L2 table */
532 if (s
->l1_backup_table_offset
!= 0) {
533 l2_offset
= s
->l1_backup_table
[l1_index
];
534 if (bdrv_pwrite(s
->hd
, ((int64_t)l2_offset
* 512) + (l2_index
* sizeof(tmp
)),
535 &tmp
, sizeof(tmp
)) != sizeof(tmp
))
539 if (get_whole_cluster(bs
, cluster_offset
, offset
, allocate
) == -1)
542 cluster_offset
<<= 9;
543 return cluster_offset
;
546 static int vmdk_is_allocated(BlockDriverState
*bs
, int64_t sector_num
,
547 int nb_sectors
, int *pnum
)
549 BDRVVmdkState
*s
= bs
->opaque
;
550 int index_in_cluster
, n
;
551 uint64_t cluster_offset
;
553 cluster_offset
= get_cluster_offset(bs
, sector_num
<< 9, 0);
554 index_in_cluster
= sector_num
% s
->cluster_sectors
;
555 n
= s
->cluster_sectors
- index_in_cluster
;
559 return (cluster_offset
!= 0);
562 static int vmdk_read(BlockDriverState
*bs
, int64_t sector_num
,
563 uint8_t *buf
, int nb_sectors
)
565 BDRVVmdkState
*s
= bs
->opaque
;
566 int index_in_cluster
, n
, ret
;
567 uint64_t cluster_offset
;
569 while (nb_sectors
> 0) {
570 cluster_offset
= get_cluster_offset(bs
, sector_num
<< 9, 0);
571 index_in_cluster
= sector_num
% s
->cluster_sectors
;
572 n
= s
->cluster_sectors
- index_in_cluster
;
575 if (!cluster_offset
) {
576 // try to read from parent image, if exist
577 if (s
->hd
->backing_hd
) {
578 if (!vmdk_is_cid_valid(bs
))
580 ret
= bdrv_read(s
->hd
->backing_hd
, sector_num
, buf
, n
);
584 memset(buf
, 0, 512 * n
);
587 if(bdrv_pread(s
->hd
, cluster_offset
+ index_in_cluster
* 512, buf
, n
* 512) != n
* 512)
593 s
->io
.read_byte_counter
+= (uint64_t)(n
*512);
598 static int vmdk_write(BlockDriverState
*bs
, int64_t sector_num
,
599 const uint8_t *buf
, int nb_sectors
)
601 BDRVVmdkState
*s
= bs
->opaque
;
602 int index_in_cluster
, n
;
603 uint64_t cluster_offset
;
604 static int cid_update
= 0;
606 while (nb_sectors
> 0) {
607 index_in_cluster
= sector_num
& (s
->cluster_sectors
- 1);
608 n
= s
->cluster_sectors
- index_in_cluster
;
611 cluster_offset
= get_cluster_offset(bs
, sector_num
<< 9, 1);
614 if (bdrv_pwrite(s
->hd
, cluster_offset
+ index_in_cluster
* 512, buf
, n
* 512) != n
* 512)
619 s
->io
.write_byte_counter
+= (uint64_t)(n
*512);
621 // update CID on the first write every time the virtual disk is opened
623 vmdk_write_cid(bs
, time(NULL
));
630 static int vmdk_create(const char *filename
, int64_t total_size
,
631 const char *backing_file
, int flags
)
635 uint32_t tmp
, magic
, grains
, gd_size
, gt_size
, gt_count
;
636 char *desc_template
=
637 "# Disk DescriptorFile\n"
640 "parentCID=ffffffff\n"
641 "createType=\"monolithicSparse\"\n"
643 "# Extent description\n"
644 "RW %lu SPARSE \"%s\"\n"
646 "# The Disk Data Base \n"
649 "ddb.virtualHWVersion = \"4\"\n"
650 "ddb.geometry.cylinders = \"%lu\"\n"
651 "ddb.geometry.heads = \"16\"\n"
652 "ddb.geometry.sectors = \"63\"\n"
653 "ddb.adapterType = \"ide\"\n";
655 const char *real_filename
, *temp_str
;
657 /* XXX: add support for backing file */
659 return vmdk_snapshot_create(filename
, backing_file
);
662 fd
= open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
| O_LARGEFILE
,
666 magic
= cpu_to_be32(VMDK4_MAGIC
);
667 memset(&header
, 0, sizeof(header
));
668 header
.version
= cpu_to_le32(1);
669 header
.flags
= cpu_to_le32(3); /* ?? */
670 header
.capacity
= cpu_to_le64(total_size
);
671 header
.granularity
= cpu_to_le64(128);
672 header
.num_gtes_per_gte
= cpu_to_le32(512);
674 grains
= (total_size
+ header
.granularity
- 1) / header
.granularity
;
675 gt_size
= ((header
.num_gtes_per_gte
* sizeof(uint32_t)) + 511) >> 9;
676 gt_count
= (grains
+ header
.num_gtes_per_gte
- 1) / header
.num_gtes_per_gte
;
677 gd_size
= (gt_count
* sizeof(uint32_t) + 511) >> 9;
679 header
.desc_offset
= 1;
680 header
.desc_size
= 20;
681 header
.rgd_offset
= header
.desc_offset
+ header
.desc_size
;
682 header
.gd_offset
= header
.rgd_offset
+ gd_size
+ (gt_size
* gt_count
);
683 header
.grain_offset
=
684 ((header
.gd_offset
+ gd_size
+ (gt_size
* gt_count
) +
685 header
.granularity
- 1) / header
.granularity
) *
688 header
.desc_offset
= cpu_to_le64(header
.desc_offset
);
689 header
.desc_size
= cpu_to_le64(header
.desc_size
);
690 header
.rgd_offset
= cpu_to_le64(header
.rgd_offset
);
691 header
.gd_offset
= cpu_to_le64(header
.gd_offset
);
692 header
.grain_offset
= cpu_to_le64(header
.grain_offset
);
694 header
.check_bytes
[0] = 0xa;
695 header
.check_bytes
[1] = 0x20;
696 header
.check_bytes
[2] = 0xd;
697 header
.check_bytes
[3] = 0xa;
699 /* write all the data */
700 write(fd
, &magic
, sizeof(magic
));
701 write(fd
, &header
, sizeof(header
));
703 ftruncate(fd
, header
.grain_offset
<< 9);
705 /* write grain directory */
706 lseek(fd
, le64_to_cpu(header
.rgd_offset
) << 9, SEEK_SET
);
707 for (i
= 0, tmp
= header
.rgd_offset
+ gd_size
;
708 i
< gt_count
; i
++, tmp
+= gt_size
)
709 write(fd
, &tmp
, sizeof(tmp
));
711 /* write backup grain directory */
712 lseek(fd
, le64_to_cpu(header
.gd_offset
) << 9, SEEK_SET
);
713 for (i
= 0, tmp
= header
.gd_offset
+ gd_size
;
714 i
< gt_count
; i
++, tmp
+= gt_size
)
715 write(fd
, &tmp
, sizeof(tmp
));
717 /* compose the descriptor */
718 real_filename
= filename
;
719 if ((temp_str
= strrchr(real_filename
, '\\')) != NULL
)
720 real_filename
= temp_str
+ 1;
721 if ((temp_str
= strrchr(real_filename
, '/')) != NULL
)
722 real_filename
= temp_str
+ 1;
723 if ((temp_str
= strrchr(real_filename
, ':')) != NULL
)
724 real_filename
= temp_str
+ 1;
725 sprintf(desc
, desc_template
, time(NULL
), (unsigned long)total_size
,
726 real_filename
, total_size
/ (63 * 16));
728 /* write the descriptor */
729 lseek(fd
, le64_to_cpu(header
.desc_offset
) << 9, SEEK_SET
);
730 write(fd
, desc
, strlen(desc
));
736 static void vmdk_close(BlockDriverState
*bs
)
738 BDRVVmdkState
*s
= bs
->opaque
;
740 qemu_free(s
->l1_table
);
741 qemu_free(s
->l2_cache
);
743 // try to close parent image, if exist
744 vmdk_parent_close(s
->hd
);
747 static void vmdk_flush(BlockDriverState
*bs
)
749 BDRVVmdkState
*s
= bs
->opaque
;
753 BlockDriver bdrv_vmdk
= {
755 sizeof(BDRVVmdkState
),