956a0e3c076406b83d635174a201fd8761ee5133vboxsync/* $Id$ */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** @file
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * IPRT Disk Volume Management API (DVM) - GPT format backend.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2011-2012 Oracle Corporation
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * available from http://www.virtualbox.org. This file is free software;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * you can redistribute it and/or modify it under the terms of the GNU
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * General Public License (GPL) as published by the Free Software
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * The contents of this file may alternatively be used under the terms
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * of the Common Development and Distribution License Version 1.0
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * VirtualBox OSE distribution, in which case the provisions of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * CDDL are applicable instead of those of the GPL.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * You may elect to license modified versions of this file under the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * terms and conditions of either the GPL or the CDDL or both.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync/*******************************************************************************
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync* Header Files *
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync*******************************************************************************/
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/types.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/assert.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/mem.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/dvm.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/string.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/uuid.h>
09c172b68738f8266640d11618b8268acec423d2vboxsync#include <iprt/asm.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include "internal/dvm.h"
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync/*******************************************************************************
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync* Structures and Typedefs *
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync*******************************************************************************/
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** The GPT signature. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_SIGNATURE "EFI PART"
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * GPT on disk header.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack(1)
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct GptHdr
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Signature ("EFI PART"). */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync char abSignature[8];
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Revision. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t u32Revision;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Header size. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t cbHeader;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** CRC of header. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t u32Crc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} GptHdr;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to a GPT header. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct GptHdr *PGptHdr;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack()
956a0e3c076406b83d635174a201fd8761ee5133vboxsyncAssertCompileSize(GptHdr, 20);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Complete GPT table header for revision 1.0.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack(1)
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct GptHdrRev1
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Header. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync GptHdr Hdr;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Reserved. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t u32Reserved;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Current LBA. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaCurrent;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Backup LBA. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaBackup;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** First usable LBA for partitions. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaFirstPartition;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Last usable LBA for partitions. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaLastPartition;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Disk UUID. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTUUID DiskUuid;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** LBA of first partition entry. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaPartitionEntries;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Number of partition entries. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t cPartitionEntries;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Partition entry size. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t cbPartitionEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** CRC of partition entries. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t u32CrcPartitionEntries;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} GptHdrRev1;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to a revision 1.0 GPT header. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef GptHdrRev1 *PGptHdrRev1;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack()
956a0e3c076406b83d635174a201fd8761ee5133vboxsyncAssertCompileSize(GptHdrRev1, 92);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * GPT partition table entry.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack(1)
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct GptEntry
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Partition type UUID. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTUUID UuidType;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Partition UUID. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTUUID UuidPartition;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** First LBA. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaFirst;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Last LBA. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64LbaLast;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Attribute flags. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64Flags;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Partition name (UTF-16LE code units). */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTUTF16 aPartitionName[36];
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} GptEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to a GPT entry. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct GptEntry *PGptEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#pragma pack()
956a0e3c076406b83d635174a201fd8761ee5133vboxsyncAssertCompileSize(GptEntry, 128);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Partition flags - System partition. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_ENTRY_SYSTEM RT_BIT_64(0)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Partition flags - Partition is readonly. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_ENTRY_READONLY RT_BIT_64(60)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Partition flags - Partition is hidden. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_ENTRY_HIDDEN RT_BIT_64(62)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Partition flags - Don't automount this partition. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_ENTRY_NO_AUTOMOUNT RT_BIT_64(63)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * GPT volume manager data.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct RTDVMFMTINTERNAL
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Pointer to the underlying disk. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PCRTDVMDISK pDisk;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** GPT header. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync GptHdrRev1 HdrRev1;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** GPT array. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PGptEntry paGptEntries;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Number of occupied partition entries. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t cPartitions;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} RTDVMFMTINTERNAL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to the MBR volume manager. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef RTDVMFMTINTERNAL *PRTDVMFMTINTERNAL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * GPT volume data.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct RTDVMVOLUMEFMTINTERNAL
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Pointer to the volume manager. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pVolMgr;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Partition table entry index. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t idxEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Start offset of the volume. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t offStart;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Size of the volume. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t cbVolume;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Pointer to the GPT entry in the array. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PGptEntry pGptEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} RTDVMVOLUMEFMTINTERNAL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to an MBR volume. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef RTDVMVOLUMEFMTINTERNAL *PRTDVMVOLUMEFMTINTERNAL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * GPT partition type to DVM volume type mapping entry.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef struct RTDVMGPTPARTTYPE2VOLTYPE
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** Type UUID. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync const char *pcszUuid;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** DVM volume type. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTDVMVOLTYPE enmVolType;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync} RTDVMGPTPARTTYPE2VOLTYPE;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Pointer to a MBR FS Type to volume type mapping entry. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsynctypedef RTDVMGPTPARTTYPE2VOLTYPE *PRTDVMGPTPARTTYPE2VOLTYPE;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Converts a LBA number to the byte offset. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_LBA2BYTE(lba, disk) ((lba) * (disk)->cbSector)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** Converts a Byte offset to the LBA number. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#define RTDVM_GPT_BYTE2LBA(lba, disk) ((lba) / (disk)->cbSector)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync/*******************************************************************************
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync* Global Variables *
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync*******************************************************************************/
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Mapping of partition types to DVM volume types.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * From http://en.wikipedia.org/wiki/GUID_Partition_Table
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsyncstatic const RTDVMGPTPARTTYPE2VOLTYPE g_aPartType2DvmVolTypes[] =
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", RTDVMVOLTYPE_LINUX_SWAP},
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", RTDVMVOLTYPE_LINUX_NATIVE},
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"E6D6D379-F507-44C2-A23C-238F2A3DF928", RTDVMVOLTYPE_LINUX_LVM},
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"A19D880F-05FC-4D3B-A006-743F0F84911E", RTDVMVOLTYPE_LINUX_SOFTRAID},
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"83BD6B9D-7F41-11DC-BE0B-001560B84F0F", RTDVMVOLTYPE_FREEBSD}, /* Boot */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"516E7CB4-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Data */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"516E7CB5-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Swap */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"516E7CB6-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* UFS */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"516E7CB8-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* Vinum */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"516E7CBA-6ECF-11D6-8FF8-00022D09712B", RTDVMVOLTYPE_FREEBSD}, /* ZFS */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"49F48D32-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Swap */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"49F48D5A-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* FFS */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"49F48D82-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* LFS */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"49F48DAA-B10E-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Raid */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"2DB519C4-B10F-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Concatenated */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"2DB519EC-B10F-11DC-B99B-0019D1879648", RTDVMVOLTYPE_NETBSD}, /* Encrypted */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"48465300-0000-11AA-AA11-00306543ECAC", RTDVMVOLTYPE_MAC_OSX_HFS},
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A82CB45-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Boot */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A85CF4D-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Root */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A87C46F-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Swap */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A8B642B-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Backup */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A898CC3-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /usr */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A8EF2E9-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /var */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A90BA39-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* /home */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {"6A9283A5-1DD2-11B2-99A6-080020736631", RTDVMVOLTYPE_SOLARIS}, /* Alternate sector */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync};
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptProbe(PCRTDVMDISK pDisk, uint32_t *puScore)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VINF_SUCCESS;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync GptHdr Hdr;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *puScore = RTDVM_MATCH_SCORE_UNSUPPORTED;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync if (rtDvmDiskGetSectors(pDisk) >= 2)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* Read from the disk and check for the signature. */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(1, pDisk), &Hdr, sizeof(GptHdr));
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if ( RT_SUCCESS(rc)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync && !strncmp(&Hdr.abSignature[0], RTDVM_GPT_SIGNATURE, RT_ELEMENTS(Hdr.abSignature))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync && RT_LE2H_U32(Hdr.u32Revision) == 0x00010000
956a0e3c076406b83d635174a201fd8761ee5133vboxsync && RT_LE2H_U32(Hdr.cbHeader) == sizeof(GptHdrRev1))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *puScore = RTDVM_MATCH_SCORE_PERFECT;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptOpen(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VINF_SUCCESS;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis = (PRTDVMFMTINTERNAL)RTMemAllocZ(sizeof(RTDVMFMTINTERNAL));
0cbb2b0b9388d33ac395656e849e4c4c7ddeb347vboxsync if (pThis)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->pDisk = pDisk;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->cPartitions = 0;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* Read the complete GPT header and convert to host endianess. */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(1, pDisk), &pThis->HdrRev1, sizeof(pThis->HdrRev1));
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (RT_SUCCESS(rc))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.Hdr.u32Revision = RT_LE2H_U32(pThis->HdrRev1.Hdr.u32Revision);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.Hdr.cbHeader = RT_LE2H_U32(pThis->HdrRev1.Hdr.cbHeader);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.Hdr.u32Crc = RT_LE2H_U32(pThis->HdrRev1.Hdr.u32Crc);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u64LbaCurrent = RT_LE2H_U64(pThis->HdrRev1.u64LbaCurrent);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u64LbaBackup = RT_LE2H_U64(pThis->HdrRev1.u64LbaBackup);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u64LbaFirstPartition = RT_LE2H_U64(pThis->HdrRev1.u64LbaFirstPartition);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u64LbaLastPartition = RT_LE2H_U64(pThis->HdrRev1.u64LbaLastPartition);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** @todo: Disk UUID */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u64LbaPartitionEntries = RT_LE2H_U64(pThis->HdrRev1.u64LbaPartitionEntries);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.cPartitionEntries = RT_LE2H_U32(pThis->HdrRev1.cPartitionEntries);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.cbPartitionEntry = RT_LE2H_U32(pThis->HdrRev1.cbPartitionEntry);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->HdrRev1.u32CrcPartitionEntries = RT_LE2H_U32(pThis->HdrRev1.u32CrcPartitionEntries);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (pThis->HdrRev1.cbPartitionEntry == sizeof(GptEntry))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries = (PGptEntry)RTMemAllocZ(pThis->HdrRev1.cPartitionEntries * pThis->HdrRev1.cbPartitionEntry);
0cbb2b0b9388d33ac395656e849e4c4c7ddeb347vboxsync if (pThis->paGptEntries)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rc = rtDvmDiskRead(pDisk, RTDVM_GPT_LBA2BYTE(pThis->HdrRev1.u64LbaPartitionEntries, pDisk),
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries, pThis->HdrRev1.cPartitionEntries * pThis->HdrRev1.cbPartitionEntry);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (RT_SUCCESS(rc))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* Count the occupied entries. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync for (unsigned i = 0; i < pThis->HdrRev1.cPartitionEntries; i++)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (!RTUuidIsNull(&pThis->paGptEntries[i].UuidType))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* Convert to host endianess. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** @todo: Uuids */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries[i].u64LbaFirst = RT_LE2H_U64(pThis->paGptEntries[i].u64LbaFirst);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries[i].u64LbaLast = RT_LE2H_U64(pThis->paGptEntries[i].u64LbaLast);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries[i].u64Flags = RT_LE2H_U64(pThis->paGptEntries[i].u64Flags);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync for (unsigned cwc = 0; cwc < RT_ELEMENTS(pThis->paGptEntries[i].aPartitionName); cwc++)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries[i].aPartitionName[cwc] = RT_LE2H_U16(pThis->paGptEntries[i].aPartitionName[cwc]);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->cPartitions++;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (RT_FAILURE(rc))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTMemFree(pThis->paGptEntries);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = VERR_NO_MEMORY;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = VERR_NOT_SUPPORTED;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (RT_SUCCESS(rc))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *phVolMgrFmt = pThis;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTMemFree(pThis);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = VERR_NO_MEMORY;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptInitialize(PCRTDVMDISK pDisk, PRTDVMFMT phVolMgrFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pDisk); NOREF(phVolMgrFmt);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return VERR_NOT_IMPLEMENTED;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(void) rtDvmFmtGptClose(RTDVMFMT hVolMgrFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->pDisk = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync memset(&pThis->HdrRev1, 0, sizeof(pThis->HdrRev1));
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTMemFree(pThis->paGptEntries);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pThis->paGptEntries = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTMemFree(pThis);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptQueryRangeUse(RTDVMFMT hVolMgrFmt,
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync uint64_t off, uint64_t cbRange,
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync bool *pfUsed)
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync{
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync
6b8df80def0e731e860daade9dbd5b9432af4698vboxsync NOREF(cbRange);
6b8df80def0e731e860daade9dbd5b9432af4698vboxsync
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync if (off < 33*pThis->pDisk->cbSector)
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync *pfUsed = true;
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync else
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync *pfUsed = false;
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync return VINF_SUCCESS;
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync}
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(uint32_t) rtDvmFmtGptGetValidVolumes(RTDVMFMT hVolMgrFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return pThis->cPartitions;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(uint32_t) rtDvmFmtGptGetMaxVolumes(RTDVMFMT hVolMgrFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return pThis->HdrRev1.cPartitionEntries;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Creates a new volume.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @returns IPRT status code.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param pThis The MBR volume manager data.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param pGptEntry The GPT entry.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param idx The index in the partition array.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param phVolFmt Where to store the volume data on success.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic int rtDvmFmtMbrVolumeCreate(PRTDVMFMTINTERNAL pThis, PGptEntry pGptEntry,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint32_t idx, PRTDVMVOLUMEFMT phVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VINF_SUCCESS;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = (PRTDVMVOLUMEFMTINTERNAL)RTMemAllocZ(sizeof(RTDVMVOLUMEFMTINTERNAL));
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
0cbb2b0b9388d33ac395656e849e4c4c7ddeb347vboxsync if (pVol)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->pVolMgr = pThis;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->idxEntry = idx;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->pGptEntry = pGptEntry;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->offStart = RTDVM_GPT_LBA2BYTE(pGptEntry->u64LbaFirst, pThis->pDisk);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->cbVolume = RTDVM_GPT_LBA2BYTE(pGptEntry->u64LbaLast - pGptEntry->u64LbaFirst + 1, pThis->pDisk);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *phVolFmt = pVol;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = VERR_NO_MEMORY;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptQueryFirstVolume(RTDVMFMT hVolMgrFmt, PRTDVMVOLUMEFMT phVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VINF_SUCCESS;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (pThis->cPartitions != 0)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PGptEntry pGptEntry = &pThis->paGptEntries[0];
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* Search for the first non empty entry. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync for (unsigned i = 0; i < pThis->HdrRev1.cPartitionEntries; i++)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (!RTUuidIsNull(&pGptEntry->UuidType))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rc = rtDvmFmtMbrVolumeCreate(pThis, pGptEntry, i, phVolFmt);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pGptEntry++;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync else
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = VERR_DVM_MAP_EMPTY;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptQueryNextVolume(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VERR_DVM_MAP_NO_VOLUME;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMFMTINTERNAL pThis = hVolMgrFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PGptEntry pGptEntry = pVol->pGptEntry + 1;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync for (unsigned i = pVol->idxEntry + 1; i < pThis->HdrRev1.cPartitionEntries; i++)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (!RTUuidIsNull(&pGptEntry->UuidType))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rc = rtDvmFmtMbrVolumeCreate(pThis, pGptEntry, i, phVolFmtNext);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pGptEntry++;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(void) rtDvmFmtGptVolumeClose(RTDVMVOLUMEFMT hVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->pVolMgr = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->offStart = 0;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->cbVolume = 0;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync pVol->pGptEntry = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTMemFree(pVol);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(uint64_t) rtDvmFmtGptVolumeGetSize(RTDVMVOLUMEFMT hVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return pVol->cbVolume;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptVolumeQueryName(RTDVMVOLUMEFMT hVolFmt, char **ppszVolName)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync int rc = VINF_SUCCESS;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *ppszVolName = NULL;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync rc = RTUtf16ToUtf8Ex(&pVol->pGptEntry->aPartitionName[0], RT_ELEMENTS(pVol->pGptEntry->aPartitionName),
956a0e3c076406b83d635174a201fd8761ee5133vboxsync ppszVolName, 0, NULL);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return rc;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(RTDVMVOLTYPE) rtDvmFmtGptVolumeGetType(RTDVMVOLUMEFMT hVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTDVMVOLTYPE enmVolType = RTDVMVOLTYPE_UNKNOWN;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync for (unsigned i = 0; i < RT_ELEMENTS(g_aPartType2DvmVolTypes); i++)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (!RTUuidCompareStr(&pVol->pGptEntry->UuidType, g_aPartType2DvmVolTypes[i].pcszUuid))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync enmVolType = g_aPartType2DvmVolTypes[i].enmVolType;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return enmVolType;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(uint64_t) rtDvmFmtGptVolumeGetFlags(RTDVMVOLUMEFMT hVolFmt)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync NOREF(hVolFmt); /* No supported flags for now. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return 0;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsyncDECLCALLBACK(bool) rtDvmFmtGptVolumeIsRangeIntersecting(RTDVMVOLUMEFMT hVolFmt,
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync uint64_t offStart, size_t cbRange,
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync uint64_t *poffVol,
8a63f697e3c0c9afe0dc326c3db61fd4217fa895vboxsync uint64_t *pcbIntersect)
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync{
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync bool fIntersect = false;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync if (RTDVM_RANGE_IS_INTERSECTING(pVol->offStart, pVol->cbVolume, offStart))
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync {
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync fIntersect = true;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync *poffVol = offStart - pVol->offStart;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync *pcbIntersect = RT_MIN(cbRange, pVol->offStart + pVol->cbVolume - offStart);
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync }
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync return fIntersect;
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync}
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptVolumeRead(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync AssertReturn(off + cbRead <= pVol->cbVolume, VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync return rtDvmDiskRead(pVol->pVolMgr->pDisk, pVol->offStart + off, pvBuf, cbRead);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncstatic DECLCALLBACK(int) rtDvmFmtGptVolumeWrite(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync PRTDVMVOLUMEFMTINTERNAL pVol = hVolFmt;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync AssertReturn(off + cbWrite <= pVol->cbVolume, VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync return rtDvmDiskWrite(pVol->pVolMgr->pDisk, pVol->offStart + off, pvBuf, cbWrite);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync}
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsyncRTDVMFMTOPS g_rtDvmFmtGpt =
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pcszFmt */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync "GPT",
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnProbe */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptProbe,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnOpen */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptOpen,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnInitialize */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptInitialize,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnClose */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptClose,
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync /* pfnQueryRangeUse */
54d2d2606d7c83a456819cd038a73e0f9a600ca4vboxsync rtDvmFmtGptQueryRangeUse,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnGetValidVolumes */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptGetValidVolumes,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnGetMaxVolumes */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptGetMaxVolumes,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnQueryFirstVolume */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptQueryFirstVolume,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnQueryNextVolume */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptQueryNextVolume,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeClose */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeClose,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeGetSize */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeGetSize,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeQueryName */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeQueryName,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeGetType */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeGetType,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeGetFlags */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeGetFlags,
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync /* pfnVolumeIsRangeIntersecting */
2a0a20dee7f474c26cc8f6f9d7aa12c345c2b73bvboxsync rtDvmFmtGptVolumeIsRangeIntersecting,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeRead */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeRead,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /* pfnVolumeWrite */
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync rtDvmFmtGptVolumeWrite
956a0e3c076406b83d635174a201fd8761ee5133vboxsync};
956a0e3c076406b83d635174a201fd8761ee5133vboxsync