VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/dvm/dvmgpt.cpp@ 40027

Last change on this file since 40027 was 40027, checked in by vboxsync, 13 years ago

Runtime/Dvm: Add callbacks to query the allocation status of blocks (for filesystem aware image compaction)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.8 KB
Line 
1/* $Id: dvmgpt.cpp 40027 2012-02-07 23:09:31Z vboxsync $ */
2/** @file
3 * IPRT Disk Volume Management API (DVM) - GPT format backend.
4 */
5
6/*
7 * Copyright (C) 2011 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/types.h>
32#include <iprt/assert.h>
33#include <iprt/mem.h>
34#include <iprt/dvm.h>
35#include <iprt/string.h>
36#include <iprt/uuid.h>
37#include "internal/dvm.h"
38
39
40/*******************************************************************************
41* Structures and Typedefs *
42*******************************************************************************/
43/** The GPT signature. */
44#define RTDVM_GPT_SIGNATURE "EFI PART"
45
46/**
47 * GPT on disk header.
48 */
49#pragma pack(1)
50typedef struct GptHdr
51{
52 /** Signature ("EFI PART"). */
53 char abSignature[8];
54 /** Revision. */
55 uint32_t u32Revision;
56 /** Header size. */
57 uint32_t cbHeader;
58 /** CRC of header. */
59 uint32_t u32Crc;
60} GptHdr;
61/** Pointer to a GPT header. */
62typedef struct GptHdr *PGptHdr;
63#pragma pack()
64AssertCompileSize(GptHdr, 20);
65
66/**
67 * Complete GPT table header for revision 1.0.
68 */
69#pragma pack(1)
70typedef struct GptHdrRev1
71{
72 /** Header. */
73 GptHdr Hdr;
74 /** Reserved. */
75 uint32_t u32Reserved;
76 /** Current LBA. */
77 uint64_t u64LbaCurrent;
78 /** Backup LBA. */
79 uint64_t u64LbaBackup;
80 /** First usable LBA for partitions. */
81 uint64_t u64LbaFirstPartition;
82 /** Last usable LBA for partitions. */
83 uint64_t u64LbaLastPartition;
84 /** Disk UUID. */
85 RTUUID DiskUuid;
86 /** LBA of first partition entry. */
87 uint64_t u64LbaPartitionEntries;
88 /** Number of partition entries. */
89 uint32_t cPartitionEntries;
90 /** Partition entry size. */
91 uint32_t cbPartitionEntry;
92 /** CRC of partition entries. */
93 uint32_t u32CrcPartitionEntries;
94} GptHdrRev1;
95/** Pointer to a revision 1.0 GPT header. */
96typedef GptHdrRev1 *PGptHdrRev1;
97#pragma pack()
98AssertCompileSize(GptHdrRev1, 92);
99
100/**
101 * GPT partition table entry.
102 */
103#pragma pack(1)
104typedef struct GptEntry
105{
106 /** Partition type UUID. */
107 RTUUID UuidType;
108 /** Partition UUID. */
109 RTUUID UuidPartition;
110 /** First LBA. */
111 uint64_t u64LbaFirst;
112 /** Last LBA. */
113 uint64_t u64LbaLast;
114 /** Attribute flags. */
115 uint64_t u64Flags;
116 /** Partition name (UTF-16LE code units). */
117 RTUTF16 aPartitionName[36];
118} GptEntry;
119/** Pointer to a GPT entry. */
120typedef struct GptEntry *PGptEntry;
121#pragma pack()
122AssertCompileSize(GptEntry, 128);
123
124/** Partition flags - System partition. */
125#define RTDVM_GPT_ENTRY_SYSTEM RT_BIT_64(0)
126/** Partition flags - Partition is readonly. */
127#define RTDVM_GPT_ENTRY_READONLY RT_BIT_64(60)
128/** Partition flags - Partition is hidden. */
129#define RTDVM_GPT_ENTRY_HIDDEN RT_BIT_64(62)
130/** Partition flags - Don't automount this partition. */
131#define RTDVM_GPT_ENTRY_NO_AUTOMOUNT RT_BIT_64(63)
132
133/**
134 * GPT volume manager data.
135 */
136typedef struct RTDVMFMTINTERNAL
137{
138 /** Pointer to the underlying disk. */
139 PCRTDVMDISK pDisk;
140 /** GPT header. */
141 GptHdrRev1 HdrRev1;
142 /** GPT array. */
143 PGptEntry paGptEntries;
144 /** Number of occupied partition entries. */
145 uint32_t cPartitions;
146} RTDVMFMTINTERNAL;
147/** Pointer to the MBR volume manager. */
148typedef RTDVMFMTINTERNAL *PRTDVMFMTINTERNAL;
149
150/**
151 * GPT volume data.
152 */
153typedef struct RTDVMVOLUMEFMTINTERNAL
154{
155 /** Pointer to the volume manager. */
156 PRTDVMFMTINTERNAL pVolMgr;
157 /** Partition table entry index. */
158 uint32_t idxEntry;
159 /** Start offset of the volume. */
160 uint64_t offStart;
161 /** Size of the volume. */
162 uint64_t cbVolume;
163 /** Pointer to the GPT entry in the array. */
164 PGptEntry pGptEntry;
165} RTDVMVOLUMEFMTINTERNAL;
166/** Pointer to an MBR volume. */
167typedef RTDVMVOLUMEFMTINTERNAL *PRTDVMVOLUMEFMTINTERNAL;
168
169/**
170 * GPT partition type to DVM volume type mapping entry.
171 */
172
173typedef struct RTDVMGPTPARTTYPE2VOLTYPE
174{
175 /** Type UUID. */
176 const char *pcszUuid;
177 /** DVM volume type. */
178 RTDVMVOLTYPE enmVolType;
179} RTDVMGPTPARTTYPE2VOLTYPE;
180/** Pointer to a MBR FS Type to volume type mapping entry. */
181typedef RTDVMGPTPARTTYPE2VOLTYPE *PRTDVMGPTPARTTYPE2VOLTYPE;
182
183/** Converts a LBA number to the byte offset. */
184#define RTDVM_GPT_LBA2BYTE(lba, disk) ((lba) * (disk)->cbSector)
185/** Converts a Byte offset to the LBA number. */
186#define RTDVM_GPT_BYTE2LBA(lba, disk) ((lba) / (disk)->cbSector)
187
188
189/*******************************************************************************
190* Global Variables *
191*******************************************************************************/
192/**
193 * Mapping of partition types to DVM volume types.
194 *
195 * From http://en.wikipedia.org/wiki/GUID_Partition_Table
196 */
197static const RTDVMGPTPARTTYPE2VOLTYPE g_aPartType2DvmVolTypes[] =
198{
199 {"0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", RTDVMVOLTYPE_LINUX_SWAP},
200 {"EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", RTDVMVOLTYPE_LINUX_NATIVE},
201 {"E6D6D379-F507-44C2-A23C-238F2A3DF928", RTDVMVOLTYPE_LINUX_LVM},
202 {"A19D880F-05FC-4D3B-A006-743F0F84911E", RTDVMVOLTYPE_LINUX_SOFTRAID},
203
204 {"83BD6B9D-7F41-11DC-BE0B-001560B84F0F", RTDVMVOLTYPE_FREEBSD}, /* Boot */
205 {"516E7CB4-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Data */
206 {"516E7CB5-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Swap */
207 {"516E7CB6-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* UFS */
208 {"516E7CB8-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Vinum */
209 {"516E7CBA-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* ZFS */
210
211 {"49F48D32-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Swap */
212 {"49F48D5A-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* FFS */
213 {"49F48D82-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* LFS */
214 {"49F48DAA-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Raid */
215 {"2DB519C4-B10F-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Concatenated */
216 {"2DB519EC-B10F-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Encrypted */
217
218 {"48465300-0000-11AA-AA11-00306543ECAC", RTDVMVOLTYPE_MAC_OSX_HFS},
219
220 {"6A82CB45-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Boot */
221 {"6A85CF4D-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Root */
222 {"6A87C46F-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Swap */
223 {"6A8B642B-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Backup */
224 {"6A898CC3-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /usr */
225 {"6A8EF2E9-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /var */
226 {"6A90BA39-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /home */
227 {"6A9283A5-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Alternate sector */
228};
229
230static DECLCALLBACK(int) rtDvmFmtGptProbe(PCRTDVMDISK pDisk, uint32_t *puScore)
231{
232 int rc = VINF_SUCCESS;
233 GptHdr Hdr;
234
235 *puScore = RTDVM_MATCH_SCORE_UNSUPPORTED;
236
237 if (rtDvmDiskGetSectors(pDisk) >= 2)
238 {
239 /* Read from the disk and check for the signature. */
240 rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(1, pDisk), &Hdr, sizeof(GptHdr));
241 if ( RT_SUCCESS(rc)
242 && !strncmp(&Hdr.abSignature[0], RTDVM_GPT_SIGNATURE, RT_ELEMENTS(Hdr.abSignature))
243 && RT_LE2H_U32(Hdr.u32Revision) == 0x00010000
244 && RT_LE2H_U32(Hdr.cbHeader) == sizeof(GptHdrRev1))
245 *puScore = RTDVM_MATCH_SCORE_PERFECT;
246 }
247
248 return rc;
249}
250
251static DECLCALLBACK(int) rtDvmFmtGptOpen(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt)
252{
253 int rc = VINF_SUCCESS;
254 PRTDVMFMTINTERNAL pThis = NULL;
255
256 pThis = (PRTDVMFMTINTERNAL)RTMemAllocZ(sizeof(RTDVMFMTINTERNAL));
257 if (VALID_PTR(pThis))
258 {
259 pThis->pDisk = pDisk;
260 pThis->cPartitions = 0;
261
262 /* Read the complete GPT header and convert to host endianess. */
263 rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(1, pDisk), &pThis->HdrRev1, sizeof(pThis->HdrRev1));
264 if (RT_SUCCESS(rc))
265 {
266 pThis->HdrRev1.Hdr.u32Revision = RT_LE2H_U32(pThis->HdrRev1.Hdr.u32Revision);
267 pThis->HdrRev1.Hdr.cbHeader = RT_LE2H_U32(pThis->HdrRev1.Hdr.cbHeader);
268 pThis->HdrRev1.Hdr.u32Crc = RT_LE2H_U32(pThis->HdrRev1.Hdr.u32Crc);
269 pThis->HdrRev1.u64LbaCurrent = RT_LE2H_U64(pThis->HdrRev1.u64LbaCurrent);
270 pThis->HdrRev1.u64LbaBackup = RT_LE2H_U64(pThis->HdrRev1.u64LbaBackup);
271 pThis->HdrRev1.u64LbaFirstPartition = RT_LE2H_U64(pThis->HdrRev1.u64LbaFirstPartition);
272 pThis->HdrRev1.u64LbaLastPartition = RT_LE2H_U64(pThis->HdrRev1.u64LbaLastPartition);
273 /** @todo: Disk UUID */
274 pThis->HdrRev1.u64LbaPartitionEntries = RT_LE2H_U64(pThis->HdrRev1.u64LbaPartitionEntries);
275 pThis->HdrRev1.cPartitionEntries = RT_LE2H_U32(pThis->HdrRev1.cPartitionEntries);
276 pThis->HdrRev1.cbPartitionEntry = RT_LE2H_U32(pThis->HdrRev1.cbPartitionEntry);
277 pThis->HdrRev1.u32CrcPartitionEntries = RT_LE2H_U32(pThis->HdrRev1.u32CrcPartitionEntries);
278
279 if (pThis->HdrRev1.cbPartitionEntry == sizeof(GptEntry))
280 {
281 pThis->paGptEntries = (PGptEntry)RTMemAllocZ(pThis->HdrRev1.cPartitionEntries * pThis->HdrRev1.cbPartitionEntry);
282 if (VALID_PTR(pThis->paGptEntries))
283 {
284 rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(pThis->HdrRev1.u64LbaPartitionEntries, pDisk),
285 pThis->paGptEntries, pThis->HdrRev1.cPartitionEntries * pThis->HdrRev1.cbPartitionEntry);
286 if (RT_SUCCESS(rc))
287 {
288 /* Count the occupied entries. */
289 for (unsigned i = 0; i < pThis->HdrRev1.cPartitionEntries; i++)
290 if (!RTUuidIsNull(&pThis->paGptEntries[i].UuidType))
291 {
292 /* Convert to host endianess. */
293 /** @todo: Uuids */
294 pThis->paGptEntries[i].u64LbaFirst = RT_LE2H_U64(pThis->paGptEntries[i].u64LbaFirst);
295 pThis->paGptEntries[i].u64LbaLast = RT_LE2H_U64(pThis->paGptEntries[i].u64LbaLast);
296 pThis->paGptEntries[i].u64Flags = RT_LE2H_U64(pThis->paGptEntries[i].u64Flags);
297 for (unsigned cwc = 0; cwc < RT_ELEMENTS(pThis->paGptEntries[i].aPartitionName); cwc++)
298 pThis->paGptEntries[i].aPartitionName[cwc] = RT_LE2H_U16(pThis->paGptEntries[i].aPartitionName[cwc]);
299
300 pThis->cPartitions++;
301 }
302 }
303
304 if (RT_FAILURE(rc))
305 RTMemFree(pThis->paGptEntries);
306 }
307 else
308 rc = VERR_NO_MEMORY;
309 }
310 else
311 rc = VERR_NOT_SUPPORTED;
312
313 if (RT_SUCCESS(rc))
314 *phVolMgrFmt = pThis;
315 else
316 RTMemFree(pThis);
317 }
318 }
319 else
320 rc = VERR_NO_MEMORY;
321
322 return rc;
323}
324
325static DECLCALLBACK(int) rtDvmFmtGptInitialize(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt)
326{
327 NOREF(pDisk); NOREF(phVolMgrFmt);
328 return VERR_NOT_IMPLEMENTED;
329}
330
331static DECLCALLBACK(void) rtDvmFmtGptClose(RTDVMFMT hVolMgrFmt)
332{
333 PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
334
335 pThis->pDisk = NULL;
336 memset(&pThis->HdrRev1, 0, sizeof(pThis->HdrRev1));
337 RTMemFree(pThis->paGptEntries);
338
339 pThis->paGptEntries = NULL;
340 RTMemFree(pThis);
341}
342
343static DECLCALLBACK(uint32_t) rtDvmFmtGptGetValidVolumes(RTDVMFMT hVolMgrFmt)
344{
345 PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
346
347 return pThis->cPartitions;
348}
349
350static DECLCALLBACK(uint32_t) rtDvmFmtGptGetMaxVolumes(RTDVMFMT hVolMgrFmt)
351{
352 PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
353
354 return pThis->HdrRev1.cPartitionEntries;
355}
356
357/**
358 * Creates a new volume.
359 *
360 * @returns IPRT status code.
361 * @param pThis The MBR volume manager data.
362 * @param pGptEntry The GPT entry.
363 * @param idx The index in the partition array.
364 * @param phVolFmt Where to store the volume data on success.
365 */
366static int rtDvmFmtMbrVolumeCreate(PRTDVMFMTINTERNAL pThis, PGptEntry pGptEntry,
367 uint32_t idx, PRTDVMVOLUMEFMT phVolFmt)
368{
369 int rc = VINF_SUCCESS;
370 PRTDVMVOLUMEFMTINTERNAL pVol = (PRTDVMVOLUMEFMTINTERNAL)RTMemAllocZ(sizeof(RTDVMVOLUMEFMTINTERNAL));
371
372 if (VALID_PTR(pVol))
373 {
374 pVol->pVolMgr = pThis;
375 pVol->idxEntry = idx;
376 pVol->pGptEntry = pGptEntry;
377 pVol->offStart = RTDVM_GPT_LBA2BYTE(pGptEntry->u64LbaFirst, pThis->pDisk);
378 pVol->cbVolume = RTDVM_GPT_LBA2BYTE(pGptEntry->u64LbaLast - pGptEntry->u64LbaFirst + 1, pThis->pDisk);
379
380 *phVolFmt = pVol;
381 }
382 else
383 rc = VERR_NO_MEMORY;
384
385 return rc;
386}
387
388static DECLCALLBACK(int) rtDvmFmtGptQueryFirstVolume(RTDVMFMT hVolMgrFmt, PRTDVMVOLUMEFMT phVolFmt)
389{
390 int rc = VINF_SUCCESS;
391 PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
392
393 if (pThis->cPartitions != 0)
394 {
395 PGptEntry pGptEntry = &pThis->paGptEntries[0];
396
397 /* Search for the first non empty entry. */
398 for (unsigned i = 0; i < pThis->HdrRev1.cPartitionEntries; i++)
399 {
400 if (!RTUuidIsNull(&pGptEntry->UuidType))
401 {
402 rc = rtDvmFmtMbrVolumeCreate(pThis, pGptEntry, i, phVolFmt);
403 break;
404 }
405 pGptEntry++;
406 }
407 }
408 else
409 rc = VERR_DVM_MAP_EMPTY;
410
411 return rc;
412}
413
414static DECLCALLBACK(int) rtDvmFmtGptQueryNextVolume(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext)
415{
416 int rc = VERR_DVM_MAP_NO_VOLUME;
417 PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
418 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
419 PGptEntry pGptEntry = pVol->pGptEntry + 1;
420
421 for (unsigned i = pVol->idxEntry + 1; i < pThis->HdrRev1.cPartitionEntries; i++)
422 {
423 if (!RTUuidIsNull(&pGptEntry->UuidType))
424 {
425 rc = rtDvmFmtMbrVolumeCreate(pThis, pGptEntry, i, phVolFmtNext);
426 break;
427 }
428 pGptEntry++;
429 }
430
431 return rc;
432}
433
434static DECLCALLBACK(void) rtDvmFmtGptVolumeClose(RTDVMVOLUMEFMT hVolFmt)
435{
436 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
437
438 pVol->pVolMgr = NULL;
439 pVol->offStart = 0;
440 pVol->cbVolume = 0;
441 pVol->pGptEntry = NULL;
442
443 RTMemFree(pVol);
444}
445
446static DECLCALLBACK(uint64_t) rtDvmFmtGptVolumeGetSize(RTDVMVOLUMEFMT hVolFmt)
447{
448 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
449
450 return pVol->cbVolume;
451}
452
453static DECLCALLBACK(int) rtDvmFmtGptVolumeQueryName(RTDVMVOLUMEFMT hVolFmt, char **ppszVolName)
454{
455 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
456 int rc = VINF_SUCCESS;
457
458 *ppszVolName = NULL;
459 rc = RTUtf16ToUtf8Ex(&pVol->pGptEntry->aPartitionName[0], RT_ELEMENTS(pVol->pGptEntry->aPartitionName),
460 ppszVolName, 0, NULL);
461
462 return rc;
463}
464
465static DECLCALLBACK(RTDVMVOLTYPE) rtDvmFmtGptVolumeGetType(RTDVMVOLUMEFMT hVolFmt)
466{
467 RTDVMVOLTYPE enmVolType = RTDVMVOLTYPE_UNKNOWN;
468 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
469
470 for (unsigned i = 0; i < RT_ELEMENTS(g_aPartType2DvmVolTypes); i++)
471 if (!RTUuidCompareStr(&pVol->pGptEntry->UuidType, g_aPartType2DvmVolTypes[i].pcszUuid))
472 {
473 enmVolType = g_aPartType2DvmVolTypes[i].enmVolType;
474 break;
475 }
476
477 return enmVolType;
478}
479
480static DECLCALLBACK(uint64_t) rtDvmFmtGptVolumeGetFlags(RTDVMVOLUMEFMT hVolFmt)
481{
482 NOREF(hVolFmt); /* No supported flags for now. */
483 return 0;
484}
485
486DECLCALLBACK(bool) rtDvmFmtGptVolumeIsRangeIntersecting(RTDVMVOLUMEFMT hVolFmt,
487 uint64_t offStart, size_t cbRange,
488 uint64_t *poffVol,
489 size_t *pcbIntersect)
490{
491 bool fIntersect = false;
492 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
493
494 if (RTDVM_RANGE_IS_INTERSECTING(pVol->offStart, pVol->cbVolume, offStart))
495 {
496 fIntersect = true;
497 *poffVol = offStart - pVol->offStart;
498 *pcbIntersect = RT_MIN(cbRange, pVol->offStart + pVol->cbVolume - offStart);
499 }
500
501 return fIntersect;
502}
503
504static DECLCALLBACK(int) rtDvmFmtGptVolumeRead(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead)
505{
506 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
507 AssertReturn(off + cbRead <= pVol->cbVolume, VERR_INVALID_PARAMETER);
508
509 return rtDvmDiskRead(pVol->pVolMgr->pDisk, pVol->offStart + off, pvBuf, cbRead);
510}
511
512static DECLCALLBACK(int) rtDvmFmtGptVolumeWrite(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite)
513{
514 PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
515 AssertReturn(off + cbWrite <= pVol->cbVolume, VERR_INVALID_PARAMETER);
516
517 return rtDvmDiskWrite(pVol->pVolMgr->pDisk, pVol->offStart + off, pvBuf, cbWrite);
518}
519
520RTDVMFMTOPS g_rtDvmFmtGpt =
521{
522 /* pcszFmt */
523 "GPT",
524 /* pfnProbe */
525 rtDvmFmtGptProbe,
526 /* pfnOpen */
527 rtDvmFmtGptOpen,
528 /* pfnInitialize */
529 rtDvmFmtGptInitialize,
530 /* pfnClose */
531 rtDvmFmtGptClose,
532 /* pfnGetValidVolumes */
533 rtDvmFmtGptGetValidVolumes,
534 /* pfnGetMaxVolumes */
535 rtDvmFmtGptGetMaxVolumes,
536 /* pfnQueryFirstVolume */
537 rtDvmFmtGptQueryFirstVolume,
538 /* pfnQueryNextVolume */
539 rtDvmFmtGptQueryNextVolume,
540 /* pfnVolumeClose */
541 rtDvmFmtGptVolumeClose,
542 /* pfnVolumeGetSize */
543 rtDvmFmtGptVolumeGetSize,
544 /* pfnVolumeQueryName */
545 rtDvmFmtGptVolumeQueryName,
546 /* pfnVolumeGetType */
547 rtDvmFmtGptVolumeGetType,
548 /* pfnVolumeGetFlags */
549 rtDvmFmtGptVolumeGetFlags,
550 /* pfnVolumeIsRangeIntersecting */
551 rtDvmFmtGptVolumeIsRangeIntersecting,
552 /* pfnVolumeRead */
553 rtDvmFmtGptVolumeRead,
554 /* pfnVolumeWrite */
555 rtDvmFmtGptVolumeWrite
556};
557
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