dvmmbr.cpp revision 956a0e3c076406b83d635174a201fd8761ee5133
/* $Id$ */
/** @file
* IPRT Disk Volume Management API (DVM) - MBR format backend.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* MBR volume manager data.
*/
typedef struct RTDVMFMTINTERNAL
{
/** Pointer to the underlying disk. */
/** Number of initialized partitions. */
/** The raw MBR data. */
/** Pointer to the MBR volume manager. */
typedef RTDVMFMTINTERNAL *PRTDVMFMTINTERNAL;
/**
* MBR volume data.
*/
typedef struct RTDVMVOLUMEFMTINTERNAL
{
/** Pointer to the volume manager. */
/** Partition table entry index. */
/** Start offset of the volume. */
/** Size of the volume. */
/** Pointer to the raw partition table entry. */
/** Pointer to an MBR volume. */
/**
* MBR FS type to DVM volume type mapping entry.
*/
typedef struct RTDVMMBRFS2VOLTYPE
{
/** MBR FS Id. */
/** DVM volume type. */
/** Pointer to a MBR FS Type to volume type mapping entry. */
typedef RTDVMMBRFS2VOLTYPE *PRTDVMMBRFS2VOLTYPE;
/**
* Mapping of FS types to DVM volume types.
*
*/
static const RTDVMMBRFS2VOLTYPE g_aFs2DvmVolTypes[] =
{
{0x06, RTDVMVOLTYPE_FAT16},
{0x0b, RTDVMVOLTYPE_FAT32},
{0x0c, RTDVMVOLTYPE_FAT32},
{0x82, RTDVMVOLTYPE_LINUX_SWAP},
{0x83, RTDVMVOLTYPE_LINUX_NATIVE},
{0x8e, RTDVMVOLTYPE_LINUX_LVM},
{0xa5, RTDVMVOLTYPE_FREEBSD},
{0xa9, RTDVMVOLTYPE_NETBSD},
{0xa6, RTDVMVOLTYPE_OPENBSD},
{0xaf, RTDVMVOLTYPE_MAC_OSX_HFS},
{0xbf, RTDVMVOLTYPE_SOLARIS},
{0xfd, RTDVMVOLTYPE_LINUX_SOFTRAID}
};
{
int rc = VINF_SUCCESS;
{
/* Read from the disk and check for the 0x55aa signature at the end. */
if ( RT_SUCCESS(rc)
}
return rc;
}
{
int rc = VINF_SUCCESS;
{
pThis->cPartitions = 0;
/* Read the MBR and count the valid partition entries. */
if (RT_SUCCESS(rc))
{
for (unsigned i = 0; i < 4; i++)
{
/* The entry is unused if the type contains 0x00. */
pThis->cPartitions++;
pbMbrEntry += 16;
}
*phVolMgrFmt = pThis;
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
int rc = VINF_SUCCESS;
{
/* Setup a new MBR and write it to the disk. */
if (RT_SUCCESS(rc))
{
pThis->cPartitions = 0;
*phVolMgrFmt = pThis;
}
else
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
pThis->cPartitions = 0;
}
{
return pThis->cPartitions;
}
{
return 4; /** @todo: Add support for EBR? */
}
/**
* Creates a new volume.
*
* @returns IPRT status code.
* @param pThis The MBR volume manager data.
* @param pbMbrEntry The raw MBR entry data.
* @param idx The index in the partition table.
* @param phVolFmt Where to store the volume data on success.
*/
{
int rc = VINF_SUCCESS;
PRTDVMVOLUMEFMTINTERNAL pVol = (PRTDVMVOLUMEFMTINTERNAL)RTMemAllocZ(sizeof(RTDVMVOLUMEFMTINTERNAL));
{
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
int rc = VINF_SUCCESS;
if (pThis->cPartitions != 0)
{
/* Search for the first non empty entry. */
for (unsigned i = 0; i < 4; i++)
{
{
break;
}
pbMbrEntry += 16;
}
}
else
return rc;
}
DECLCALLBACK(int) dvmFmtMbrQueryNextVolume(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext)
{
int rc = VERR_DVM_MAP_NO_VOLUME;
{
{
break;
}
pbMbrEntry += 16;
}
return rc;
}
{
}
{
}
{
return VERR_NOT_SUPPORTED;
}
{
for (unsigned i = 0; i < RT_ELEMENTS(g_aFs2DvmVolTypes); i++)
{
break;
}
return enmVolType;
}
{
return fFlags;
}
DECLCALLBACK(int) dvmFmtMbrVolumeRead(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead)
{
}
DECLCALLBACK(int) dvmFmtMbrVolumeWrite(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite)
{
}
{
/* pcszFmt */
"MBR",
/* pfnProbe */
/* pfnOpen */
/* pfnInitialize */
/* pfnClose */
/* pfnGetValidVolumes */
/* pfnGetMaxVolumes */
/* pfnQueryFirstVolume */
/* pfnQueryNextVolume */
/* pfnVolumeClose */
/* pfnVolumeGetSize */
/* pfnVolumeQueryName */
/* pfnVolumeGetType */
/* pfnVolumeGetFlags */
/* pfnVolumeRead */
/* pfnVolumeWrite */
};