VirtualBox

source: vbox/trunk/src/VBox/Storage/VDICore.h@ 35753

Last change on this file since 35753 was 35346, checked in by vboxsync, 14 years ago

VMM reorg: Moving the public include files from include/VBox to include/VBox/vmm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.9 KB
Line 
1/* $Id: VDICore.h 35346 2010-12-27 16:13:13Z vboxsync $ */
2/** @file
3 * Virtual Disk Image (VDI), Core Code Header (internal).
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___VDICore_h___
19
20
21/*******************************************************************************
22* Header Files *
23*******************************************************************************/
24#include <VBox/vd.h>
25#ifndef VBOX_VDICORE_VD
26# include <VBox/vmm/pdm.h>
27#endif
28#include <VBox/err.h>
29
30#include <VBox/log.h>
31#include <iprt/alloc.h>
32#include <iprt/assert.h>
33#include <iprt/uuid.h>
34#include <iprt/string.h>
35#include <iprt/asm.h>
36
37
38/*******************************************************************************
39* Constants And Macros, Structures and Typedefs *
40*******************************************************************************/
41
42/** Image info, not handled anyhow.
43 * Must be less than 64 bytes in length, including the trailing 0.
44 */
45#define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n"
46
47/** The Sector size.
48 * Currently we support only 512 bytes sectors.
49 */
50#define VDI_GEOMETRY_SECTOR_SIZE (512)
51/** 512 = 2^^9 */
52#define VDI_GEOMETRY_SECTOR_SHIFT (9)
53
54/**
55 * Harddisk geometry.
56 */
57#pragma pack(1)
58typedef struct VDIDISKGEOMETRY
59{
60 /** Cylinders. */
61 uint32_t cCylinders;
62 /** Heads. */
63 uint32_t cHeads;
64 /** Sectors per track. */
65 uint32_t cSectors;
66 /** Sector size. (bytes per sector) */
67 uint32_t cbSector;
68} VDIDISKGEOMETRY, *PVDIDISKGEOMETRY;
69#pragma pack()
70
71/** Image signature. */
72#define VDI_IMAGE_SIGNATURE (0xbeda107f)
73
74/**
75 * Pre-Header to be stored in image file - used for version control.
76 */
77#pragma pack(1)
78typedef struct VDIPREHEADER
79{
80 /** Just text info about image type, for eyes only. */
81 char szFileInfo[64];
82 /** The image signature (VDI_IMAGE_SIGNATURE). */
83 uint32_t u32Signature;
84 /** The image version (VDI_IMAGE_VERSION). */
85 uint32_t u32Version;
86} VDIPREHEADER, *PVDIPREHEADER;
87#pragma pack()
88
89/**
90 * Size of szComment field of HDD image header.
91 */
92#define VDI_IMAGE_COMMENT_SIZE 256
93
94/**
95 * Header to be stored in image file, VDI_IMAGE_VERSION_MAJOR = 0.
96 * Prepended by VDIPREHEADER.
97 */
98#pragma pack(1)
99typedef struct VDIHEADER0
100{
101 /** The image type (VDI_IMAGE_TYPE_*). */
102 uint32_t u32Type;
103 /** Image flags (VDI_IMAGE_FLAGS_*). */
104 uint32_t fFlags;
105 /** Image comment. (UTF-8) */
106 char szComment[VDI_IMAGE_COMMENT_SIZE];
107 /** Legacy image geometry (previous code stored PCHS there). */
108 VDIDISKGEOMETRY LegacyGeometry;
109 /** Size of disk (in bytes). */
110 uint64_t cbDisk;
111 /** Block size. (For instance VDI_IMAGE_BLOCK_SIZE.) */
112 uint32_t cbBlock;
113 /** Number of blocks. */
114 uint32_t cBlocks;
115 /** Number of allocated blocks. */
116 uint32_t cBlocksAllocated;
117 /** UUID of image. */
118 RTUUID uuidCreate;
119 /** UUID of image's last modification. */
120 RTUUID uuidModify;
121 /** Only for secondary images - UUID of primary image. */
122 RTUUID uuidLinkage;
123} VDIHEADER0, *PVDIHEADER0;
124#pragma pack()
125
126/**
127 * Header to be stored in image file, VDI_IMAGE_VERSION_MAJOR = 1,
128 * VDI_IMAGE_VERSION_MINOR = 1. Prepended by VDIPREHEADER.
129 */
130#pragma pack(1)
131typedef struct VDIHEADER1
132{
133 /** Size of this structure in bytes. */
134 uint32_t cbHeader;
135 /** The image type (VDI_IMAGE_TYPE_*). */
136 uint32_t u32Type;
137 /** Image flags (VDI_IMAGE_FLAGS_*). */
138 uint32_t fFlags;
139 /** Image comment. (UTF-8) */
140 char szComment[VDI_IMAGE_COMMENT_SIZE];
141 /** Offset of Blocks array from the beginning of image file.
142 * Should be sector-aligned for HDD access optimization. */
143 uint32_t offBlocks;
144 /** Offset of image data from the beginning of image file.
145 * Should be sector-aligned for HDD access optimization. */
146 uint32_t offData;
147 /** Legacy image geometry (previous code stored PCHS there). */
148 VDIDISKGEOMETRY LegacyGeometry;
149 /** Was BIOS HDD translation mode, now unused. */
150 uint32_t u32Dummy;
151 /** Size of disk (in bytes). */
152 uint64_t cbDisk;
153 /** Block size. (For instance VDI_IMAGE_BLOCK_SIZE.) Should be a power of 2! */
154 uint32_t cbBlock;
155 /** Size of additional service information of every data block.
156 * Prepended before block data. May be 0.
157 * Should be a power of 2 and sector-aligned for optimization reasons. */
158 uint32_t cbBlockExtra;
159 /** Number of blocks. */
160 uint32_t cBlocks;
161 /** Number of allocated blocks. */
162 uint32_t cBlocksAllocated;
163 /** UUID of image. */
164 RTUUID uuidCreate;
165 /** UUID of image's last modification. */
166 RTUUID uuidModify;
167 /** Only for secondary images - UUID of previous image. */
168 RTUUID uuidLinkage;
169 /** Only for secondary images - UUID of previous image's last modification. */
170 RTUUID uuidParentModify;
171} VDIHEADER1, *PVDIHEADER1;
172#pragma pack()
173
174/**
175 * Header to be stored in image file, VDI_IMAGE_VERSION_MAJOR = 1,
176 * VDI_IMAGE_VERSION_MINOR = 1, the slightly changed variant necessary as the
177 * old released code doesn't support changing the minor version at all.
178 */
179#pragma pack(1)
180typedef struct VDIHEADER1PLUS
181{
182 /** Size of this structure in bytes. */
183 uint32_t cbHeader;
184 /** The image type (VDI_IMAGE_TYPE_*). */
185 uint32_t u32Type;
186 /** Image flags (VDI_IMAGE_FLAGS_*). */
187 uint32_t fFlags;
188 /** Image comment. (UTF-8) */
189 char szComment[VDI_IMAGE_COMMENT_SIZE];
190 /** Offset of blocks array from the beginning of image file.
191 * Should be sector-aligned for HDD access optimization. */
192 uint32_t offBlocks;
193 /** Offset of image data from the beginning of image file.
194 * Should be sector-aligned for HDD access optimization. */
195 uint32_t offData;
196 /** Legacy image geometry (previous code stored PCHS there). */
197 VDIDISKGEOMETRY LegacyGeometry;
198 /** Was BIOS HDD translation mode, now unused. */
199 uint32_t u32Dummy;
200 /** Size of disk (in bytes). */
201 uint64_t cbDisk;
202 /** Block size. (For instance VDI_IMAGE_BLOCK_SIZE.) Should be a power of 2! */
203 uint32_t cbBlock;
204 /** Size of additional service information of every data block.
205 * Prepended before block data. May be 0.
206 * Should be a power of 2 and sector-aligned for optimization reasons. */
207 uint32_t cbBlockExtra;
208 /** Number of blocks. */
209 uint32_t cBlocks;
210 /** Number of allocated blocks. */
211 uint32_t cBlocksAllocated;
212 /** UUID of image. */
213 RTUUID uuidCreate;
214 /** UUID of image's last modification. */
215 RTUUID uuidModify;
216 /** Only for secondary images - UUID of previous image. */
217 RTUUID uuidLinkage;
218 /** Only for secondary images - UUID of previous image's last modification. */
219 RTUUID uuidParentModify;
220 /** LCHS image geometry (new field in VDI1.2 version. */
221 VDIDISKGEOMETRY LCHSGeometry;
222} VDIHEADER1PLUS, *PVDIHEADER1PLUS;
223#pragma pack()
224
225/**
226 * Header structure for all versions.
227 */
228typedef struct VDIHEADER
229{
230 unsigned uVersion;
231 union
232 {
233 VDIHEADER0 v0;
234 VDIHEADER1 v1;
235 VDIHEADER1PLUS v1plus;
236 } u;
237} VDIHEADER, *PVDIHEADER;
238
239/**
240 * File alignment boundary for both the block array and data area. Should be
241 * at least the size of a physical sector on disk for performance reasons.
242 * With the growing market share of disks with 4K sectors this needs to be
243 * bumped, and maybe again later. */
244#define VDI_DATA_ALIGN _4K
245
246/** Block 'pointer'. */
247typedef uint32_t VDIIMAGEBLOCKPOINTER;
248/** Pointer to a block 'pointer'. */
249typedef VDIIMAGEBLOCKPOINTER *PVDIIMAGEBLOCKPOINTER;
250
251/**
252 * Block marked as free is not allocated in image file, read from this
253 * block may returns any random data.
254 */
255#define VDI_IMAGE_BLOCK_FREE ((VDIIMAGEBLOCKPOINTER)~0)
256
257/**
258 * Block marked as zero is not allocated in image file, read from this
259 * block returns zeroes.
260 */
261#define VDI_IMAGE_BLOCK_ZERO ((VDIIMAGEBLOCKPOINTER)~1)
262
263/**
264 * Block 'pointer' >= VDI_IMAGE_BLOCK_UNALLOCATED indicates block is not
265 * allocated in image file.
266 */
267#define VDI_IMAGE_BLOCK_UNALLOCATED (VDI_IMAGE_BLOCK_ZERO)
268#define IS_VDI_IMAGE_BLOCK_ALLOCATED(bp) (bp < VDI_IMAGE_BLOCK_UNALLOCATED)
269
270#define GET_MAJOR_HEADER_VERSION(ph) (VDI_GET_VERSION_MAJOR((ph)->uVersion))
271#define GET_MINOR_HEADER_VERSION(ph) (VDI_GET_VERSION_MINOR((ph)->uVersion))
272
273#ifdef VBOX_VDICORE_VD
274/** @name VDI image types
275 * @{ */
276typedef enum VDIIMAGETYPE
277{
278 /** Normal dynamically growing base image file. */
279 VDI_IMAGE_TYPE_NORMAL = 1,
280 /** Preallocated base image file of a fixed size. */
281 VDI_IMAGE_TYPE_FIXED,
282 /** Dynamically growing image file for undo/commit changes support. */
283 VDI_IMAGE_TYPE_UNDO,
284 /** Dynamically growing image file for differencing support. */
285 VDI_IMAGE_TYPE_DIFF,
286
287 /** First valid image type value. */
288 VDI_IMAGE_TYPE_FIRST = VDI_IMAGE_TYPE_NORMAL,
289 /** Last valid image type value. */
290 VDI_IMAGE_TYPE_LAST = VDI_IMAGE_TYPE_DIFF
291} VDIIMAGETYPE;
292/** Pointer to VDI image type. */
293typedef VDIIMAGETYPE *PVDIIMAGETYPE;
294/** @} */
295#endif /* VBOX_VDICORE_VD */
296
297/*******************************************************************************
298* Internal Functions for header access *
299*******************************************************************************/
300DECLINLINE(VDIIMAGETYPE) getImageType(PVDIHEADER ph)
301{
302 switch (GET_MAJOR_HEADER_VERSION(ph))
303 {
304 case 0: return (VDIIMAGETYPE)ph->u.v0.u32Type;
305 case 1: return (VDIIMAGETYPE)ph->u.v1.u32Type;
306 }
307 AssertFailed();
308 return (VDIIMAGETYPE)0;
309}
310
311#ifdef VBOX_VDICORE_VD
312DECLINLINE(unsigned) getImageFlags(PVDIHEADER ph)
313{
314 switch (GET_MAJOR_HEADER_VERSION(ph))
315 {
316 case 0:
317 /* VDI image flag conversion to VD image flags. */
318 return ph->u.v0.fFlags << 8;
319 case 1:
320 /* VDI image flag conversion to VD image flags. */
321 return ph->u.v1.fFlags << 8;
322 }
323 AssertFailed();
324 return 0;
325}
326#else /* !VBOX_VDICORE_VD */
327DECLINLINE(unsigned) getImageFlags(PVDIHEADER ph)
328{
329 switch (GET_MAJOR_HEADER_VERSION(ph))
330 {
331 case 0: return ph->u.v0.fFlags;
332 case 1: return ph->u.v1.fFlags;
333 }
334 AssertFailed();
335 return 0;
336}
337#endif /* !VBOX_VDICORE_VD */
338
339DECLINLINE(char *) getImageComment(PVDIHEADER ph)
340{
341 switch (GET_MAJOR_HEADER_VERSION(ph))
342 {
343 case 0: return &ph->u.v0.szComment[0];
344 case 1: return &ph->u.v1.szComment[0];
345 }
346 AssertFailed();
347 return NULL;
348}
349
350DECLINLINE(unsigned) getImageBlocksOffset(PVDIHEADER ph)
351{
352 switch (GET_MAJOR_HEADER_VERSION(ph))
353 {
354 case 0: return (sizeof(VDIPREHEADER) + sizeof(VDIHEADER0));
355 case 1: return ph->u.v1.offBlocks;
356 }
357 AssertFailed();
358 return 0;
359}
360
361DECLINLINE(uint32_t) getImageDataOffset(PVDIHEADER ph)
362{
363 switch (GET_MAJOR_HEADER_VERSION(ph))
364 {
365 case 0: return sizeof(VDIPREHEADER) + sizeof(VDIHEADER0) + \
366 (ph->u.v0.cBlocks * sizeof(VDIIMAGEBLOCKPOINTER));
367 case 1: return ph->u.v1.offData;
368 }
369 AssertFailed();
370 return 0;
371}
372
373DECLINLINE(void) setImageDataOffset(PVDIHEADER ph, uint32_t offData)
374{
375 switch (GET_MAJOR_HEADER_VERSION(ph))
376 {
377 case 0: return;
378 case 1: ph->u.v1.offData = offData; return;
379 }
380 AssertFailed();
381}
382
383DECLINLINE(PVDIDISKGEOMETRY) getImageLCHSGeometry(PVDIHEADER ph)
384{
385 switch (GET_MAJOR_HEADER_VERSION(ph))
386 {
387 case 0: return NULL;
388 case 1:
389 switch (GET_MINOR_HEADER_VERSION(ph))
390 {
391 case 1:
392 if (ph->u.v1.cbHeader < sizeof(ph->u.v1plus))
393 return NULL;
394 else
395 return &ph->u.v1plus.LCHSGeometry;
396 }
397 }
398 AssertFailed();
399 return NULL;
400}
401
402DECLINLINE(uint64_t) getImageDiskSize(PVDIHEADER ph)
403{
404 switch (GET_MAJOR_HEADER_VERSION(ph))
405 {
406 case 0: return ph->u.v0.cbDisk;
407 case 1: return ph->u.v1.cbDisk;
408 }
409 AssertFailed();
410 return 0;
411}
412
413DECLINLINE(void) setImageDiskSize(PVDIHEADER ph, uint64_t cbDisk)
414{
415 switch (GET_MAJOR_HEADER_VERSION(ph))
416 {
417 case 0: ph->u.v0.cbDisk = cbDisk; return;
418 case 1: ph->u.v1.cbDisk = cbDisk; return;
419 }
420 AssertFailed();
421}
422
423DECLINLINE(unsigned) getImageBlockSize(PVDIHEADER ph)
424{
425 switch (GET_MAJOR_HEADER_VERSION(ph))
426 {
427 case 0: return ph->u.v0.cbBlock;
428 case 1: return ph->u.v1.cbBlock;
429 }
430 AssertFailed();
431 return 0;
432}
433
434DECLINLINE(unsigned) getImageExtraBlockSize(PVDIHEADER ph)
435{
436 switch (GET_MAJOR_HEADER_VERSION(ph))
437 {
438 case 0: return 0;
439 case 1: return ph->u.v1.cbBlockExtra;
440 }
441 AssertFailed();
442 return 0;
443}
444
445DECLINLINE(unsigned) getImageBlocks(PVDIHEADER ph)
446{
447 switch (GET_MAJOR_HEADER_VERSION(ph))
448 {
449 case 0: return ph->u.v0.cBlocks;
450 case 1: return ph->u.v1.cBlocks;
451 }
452 AssertFailed();
453 return 0;
454}
455
456DECLINLINE(void) setImageBlocks(PVDIHEADER ph, unsigned cBlocks)
457{
458 switch (GET_MAJOR_HEADER_VERSION(ph))
459 {
460 case 0: ph->u.v0.cBlocks = cBlocks; return;
461 case 1: ph->u.v1.cBlocks = cBlocks; return;
462 }
463 AssertFailed();
464}
465
466
467DECLINLINE(unsigned) getImageBlocksAllocated(PVDIHEADER ph)
468{
469 switch (GET_MAJOR_HEADER_VERSION(ph))
470 {
471 case 0: return ph->u.v0.cBlocksAllocated;
472 case 1: return ph->u.v1.cBlocksAllocated;
473 }
474 AssertFailed();
475 return 0;
476}
477
478DECLINLINE(void) setImageBlocksAllocated(PVDIHEADER ph, unsigned cBlocks)
479{
480 switch (GET_MAJOR_HEADER_VERSION(ph))
481 {
482 case 0: ph->u.v0.cBlocksAllocated = cBlocks; return;
483 case 1: ph->u.v1.cBlocksAllocated = cBlocks; return;
484 }
485 AssertFailed();
486}
487
488DECLINLINE(PRTUUID) getImageCreationUUID(PVDIHEADER ph)
489{
490 switch (GET_MAJOR_HEADER_VERSION(ph))
491 {
492 case 0: return &ph->u.v0.uuidCreate;
493 case 1: return &ph->u.v1.uuidCreate;
494 }
495 AssertFailed();
496 return NULL;
497}
498
499DECLINLINE(PRTUUID) getImageModificationUUID(PVDIHEADER ph)
500{
501 switch (GET_MAJOR_HEADER_VERSION(ph))
502 {
503 case 0: return &ph->u.v0.uuidModify;
504 case 1: return &ph->u.v1.uuidModify;
505 }
506 AssertFailed();
507 return NULL;
508}
509
510DECLINLINE(PRTUUID) getImageParentUUID(PVDIHEADER ph)
511{
512 switch (GET_MAJOR_HEADER_VERSION(ph))
513 {
514 case 0: return &ph->u.v0.uuidLinkage;
515 case 1: return &ph->u.v1.uuidLinkage;
516 }
517 AssertFailed();
518 return NULL;
519}
520
521DECLINLINE(PRTUUID) getImageParentModificationUUID(PVDIHEADER ph)
522{
523 switch (GET_MAJOR_HEADER_VERSION(ph))
524 {
525 case 1: return &ph->u.v1.uuidParentModify;
526 }
527 AssertFailed();
528 return NULL;
529}
530
531#ifndef VBOX_VDICORE_VD
532/**
533 * Default image block size, may be changed by setBlockSize/getBlockSize.
534 *
535 * Note: for speed reasons block size should be a power of 2 !
536 */
537#define VDI_IMAGE_DEFAULT_BLOCK_SIZE _1M
538#endif /* !VBOX_VDICORE_VD */
539
540#ifndef VBOX_VDICORE_VD
541/**
542 * fModified bit flags.
543 */
544#define VDI_IMAGE_MODIFIED_FLAG RT_BIT(0)
545#define VDI_IMAGE_MODIFIED_FIRST RT_BIT(1)
546#define VDI_IMAGE_MODIFIED_DISABLE_UUID_UPDATE RT_BIT(2)
547#endif /* !VBOX_VDICORE_VD */
548
549/**
550 * Image structure
551 */
552typedef struct VDIIMAGEDESC
553{
554#ifndef VBOX_VDICORE_VD
555 /** Link to parent image descriptor, if any. */
556 struct VDIIMAGEDESC *pPrev;
557 /** Link to child image descriptor, if any. */
558 struct VDIIMAGEDESC *pNext;
559#endif /* !VBOX_VDICORE_VD */
560 /** Opaque storage handle. */
561 PVDIOSTORAGE pStorage;
562#ifndef VBOX_VDICORE_VD
563 /** True if the image is operating in readonly mode. */
564 bool fReadOnly;
565 /** Image open flags, VDI_OPEN_FLAGS_*. */
566 unsigned fOpen;
567#else /* VBOX_VDICORE_VD */
568 /** Image open flags, VD_OPEN_FLAGS_*. */
569 unsigned uOpenFlags;
570#endif /* VBOX_VDICORE_VD */
571 /** Image pre-header. */
572 VDIPREHEADER PreHeader;
573 /** Image header. */
574 VDIHEADER Header;
575 /** Pointer to a block array. */
576 PVDIIMAGEBLOCKPOINTER paBlocks;
577#ifndef VBOX_VDICORE_VD
578 /** fFlags copy from image header, for speed optimization. */
579 unsigned fFlags;
580#else /* VBOX_VDICORE_VD */
581 /** fFlags copy from image header, for speed optimization. */
582 unsigned uImageFlags;
583#endif /* VBOX_VDICORE_VD */
584 /** Start offset of block array in image file, here for speed optimization. */
585 unsigned offStartBlocks;
586 /** Start offset of data in image file, here for speed optimization. */
587 unsigned offStartData;
588 /** Block mask for getting the offset into a block from a byte hdd offset. */
589 unsigned uBlockMask;
590 /** Block shift value for converting byte hdd offset into paBlock index. */
591 unsigned uShiftOffset2Index;
592#ifndef VBOX_VDICORE_VD
593 /** Block shift value for converting block index into offset in image. */
594 unsigned uShiftIndex2Offset;
595#endif /* !VBOX_VDICORE_VD */
596 /** Offset of data from the beginning of block. */
597 unsigned offStartBlockData;
598#ifndef VBOX_VDICORE_VD
599 /** Image is modified flags (VDI_IMAGE_MODIFIED*). */
600 unsigned fModified;
601 /** Container filename. (UTF-8)
602 * @todo Make this variable length to save a bunch of bytes. (low prio) */
603 char szFilename[RTPATH_MAX];
604#else /* VBOX_VDICORE_VD */
605 /** Total size of image block (including the extra data). */
606 unsigned cbTotalBlockData;
607 /** Container filename. (UTF-8) */
608 const char *pszFilename;
609 /** Physical geometry of this image (never actually stored). */
610 VDGEOMETRY PCHSGeometry;
611 /** Pointer to the per-disk VD interface list. */
612 PVDINTERFACE pVDIfsDisk;
613 /** Pointer to the per-image VD interface list. */
614 PVDINTERFACE pVDIfsImage;
615 /** Error interface. */
616 PVDINTERFACE pInterfaceError;
617 /** Error interface callback table. */
618 PVDINTERFACEERROR pInterfaceErrorCallbacks;
619 /** I/O interface. */
620 PVDINTERFACE pInterfaceIO;
621 /** I/O interface callbacks. */
622 PVDINTERFACEIOINT pInterfaceIOCallbacks;
623#endif /* VBOX_VDICORE_VD */
624} VDIIMAGEDESC, *PVDIIMAGEDESC;
625
626#ifndef VBOX_VDICORE_VD
627/**
628 * Default work buffer size, may be changed by setBufferSize() method.
629 *
630 * For best speed performance it must be equal to image block size.
631 */
632#define VDIDISK_DEFAULT_BUFFER_SIZE (VDI_IMAGE_DEFAULT_BLOCK_SIZE)
633#endif /* !VBOX_VDICORE_VD */
634
635/** VDIDISK Signature. */
636#define VDIDISK_SIGNATURE (0xbedafeda)
637
638/**
639 * VBox HDD Container main structure, private part.
640 */
641struct VDIDISK
642{
643 /** Structure signature (VDIDISK_SIGNATURE). */
644 uint32_t u32Signature;
645
646 /** Number of opened images. */
647 unsigned cImages;
648
649 /** Base image. */
650 PVDIIMAGEDESC pBase;
651
652 /** Last opened image in the chain.
653 * The same as pBase if only one image is used or the last opened diff image. */
654 PVDIIMAGEDESC pLast;
655
656 /** Default block size for newly created images. */
657 unsigned cbBlock;
658
659 /** Working buffer size, allocated only while committing data,
660 * copying block from primary image to secondary and saving previously
661 * zero block. Buffer deallocated after operation complete.
662 * @remark For best performance buffer size must be equal to image's
663 * block size, however it may be decreased for memory saving.
664 */
665 unsigned cbBuf;
666
667 /** Flag whether zero writes should be handled normally or optimized
668 * away if possible. */
669 bool fHonorZeroWrites;
670
671#ifndef VBOX_VDICORE_VD
672 /** The media interface. */
673 PDMIMEDIA IMedia;
674 /** Pointer to the driver instance. */
675 PPDMDRVINS pDrvIns;
676#endif /* !VBOX_VDICORE_VD */
677};
678
679
680/*******************************************************************************
681* Internal Functions *
682*******************************************************************************/
683RT_C_DECLS_BEGIN
684
685#ifndef VBOX_VDICORE_VD
686VBOXDDU_DECL(void) vdiInitVDIDisk(PVDIDISK pDisk);
687VBOXDDU_DECL(void) VDIFlushImage(PVDIIMAGEDESC pImage);
688VBOXDDU_DECL(int) vdiChangeImageMode(PVDIIMAGEDESC pImage, bool fReadOnly);
689#endif /* !VBOX_VDICORE_VD */
690
691RT_C_DECLS_END
692
693#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette