dvm.cpp revision 54d2d2606d7c83a456819cd038a73e0f9a600ca4
/* $Id$ */
/** @file
* IPRT Disk Volume Management API (DVM) - generic code.
*/
/*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal volume manager structure.
*/
typedef struct RTDVMINTERNAL
{
/** The DVM magic (RTDVM_MAGIC). */
/** The disk descriptor. */
/** Pointer to the backend operations table after a successful probe. */
/** The format specific volume manager data. */
/** Flags passed on manager creation. */
/** Reference counter. */
/** List of recognised volumes (RTDVMVOLUMEINTERNAL). */
/** Pointer to an internal volume manager. */
typedef RTDVMINTERNAL *PRTDVMINTERNAL;
/**
* The internal volume structure.
*/
typedef struct RTDVMVOLUMEINTERNAL
{
/** The DVM volume magic (RTDVMVOLUME_MAGIC). */
/** Node for the volume list. */
/** Pointer to the owning volume manager. */
/** Format specific volume data. */
/** Set block status.callback */
/** Opaque user data. */
void *pvUser;
/** Reference counter. */
/** Pointer to an internal volume. */
typedef RTDVMVOLUMEINTERNAL *PRTDVMVOLUMEINTERNAL;
/*******************************************************************************
* Global variables *
*******************************************************************************/
extern RTDVMFMTOPS g_rtDvmFmtMbr;
extern RTDVMFMTOPS g_rtDvmFmtGpt;
extern RTDVMFMTOPS g_rtDvmFmtBsdLbl;
/**
* Supported volume formats.
*/
static PCRTDVMFMTOPS g_aDvmFmts[] =
{
};
/**
* Descriptions of the volume types.
*
* This is indexed by RTDVMVOLTYPE.
*/
static const char * g_apcszDvmVolTypes[] =
{
"Invalid",
"Unknown",
"NTFS",
"FAT16",
"FAT32",
"Linux swap",
"Linux native",
"Linux LVM",
"Linux SoftRaid",
"FreeBSD",
"NetBSD",
"OpenBSD",
"Mac OS X HFS or HFS+",
"Solaris"
};
/**
* Creates a new volume.
*
* @returns IPRT status code.
* @param pThis The DVM map instance.
* @param hVolFmt The format specific volume handle.
* @param phVol Where to store the generic volume handle on success.
*/
{
int rc = VINF_SUCCESS;
if (pVol)
{
}
else
rc = VERR_NO_MEMORY;
return rc;
}
/**
* Destroys a volume handle.
*
* @param pThis The volume to destroy.
*/
{
/* Close the volume. */
/* Release the reference of the volume manager. */
}
{
int rc = VINF_SUCCESS;
("Invalid flags given %#x\n", fFlags),
if (pThis)
{
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
return cRefs;
}
/**
* Destroys a volume manager handle.
*
* @param pThis The volume manager to destroy.
*/
{
{
/* Let the backend do it's own cleanup first. */
}
}
{
return 0;
if (cRefs == 0)
return cRefs;
}
{
int rc = VINF_SUCCESS;
for (unsigned i = 0; i < RT_ELEMENTS(g_aDvmFmts); i++)
{
if ( RT_SUCCESS(rc)
{
}
else if (RT_FAILURE(rc))
break;
}
if (RT_SUCCESS(rc))
{
{
/* Open the format. */
if (RT_SUCCESS(rc))
{
/* Construct volume list. */
if (cVols)
{
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
if (RT_SUCCESS(rc))
{
cVols--;
while ( cVols > 0
&& RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
else
cVols--;
}
}
}
if (RT_FAILURE(rc))
{
/* Remove all entries. */
{
}
}
}
}
}
else
}
return rc;
}
{
int rc = VERR_NOT_SUPPORTED;
for (unsigned i = 0; i < RT_ELEMENTS(g_aDvmFmts); i++)
{
{
if (RT_SUCCESS(rc))
break;
}
}
return rc;
}
{
}
{
}
{
}
{
int rc = VERR_DVM_MAP_EMPTY;
if (pVol)
{
rc = VINF_SUCCESS;
}
return rc;
}
{
int rc = VERR_DVM_MAP_NO_VOLUME;
if (pVolNext)
{
rc = VINF_SUCCESS;
}
return rc;
}
bool *pfAllocated)
{
int rc = VINF_SUCCESS;
/* Check whether the range is inuse by the volume manager metadata first. */
if (RT_FAILURE(rc))
return rc;
if (!*pfAllocated)
{
bool fAllocated = false;
while ( cb > 0
&& !fAllocated)
{
bool fVolFound = false;
/*
* Search through all volumes. It is not possible to
* get all start sectors and sizes of all volumes here
* because volumes can be scattered around the disk for certain formats.
* Linux LVM is one example, extents of logical volumes don't need to be
* contigous on the medium.
*/
{
&cbIntersect);
if (fIntersect)
{
fVolFound = true;
if (pVol->pfnQueryBlockStatus)
{
bool fVolAllocated = true;
if (RT_FAILURE(rc))
break;
else if (fVolAllocated)
{
fAllocated = true;
break;
}
}
fAllocated = true;
/* else, flag is set, continue. */
cb -= cbIntersect;
off += cbIntersect;
break;
}
}
if (!fVolFound)
{
fAllocated = true;
}
}
}
return rc;
}
{
if (cRefs == 1)
return cRefs;
}
{
if (pThis == NIL_RTDVMVOLUME)
return 0;
if (cRefs == 0)
{
/* Release the volume manager. */
}
return cRefs;
}
void *pvUser)
{
}
{
AssertPtrReturn(pThis, 0);
}
{
}
{
}
{
}
{
}
{
}
{
return g_apcszDvmVolTypes[enmVolType];
}