dvmbsdlabel.cpp revision e2878a43f6dd6800d12a8a09daa187d6eae9b9b9
/* $Id$ */
/** @file
* IPRT Disk Volume Management API (DVM) - BSD disklabel 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 *
*******************************************************************************/
/*
* Below are the on disk structures of a bsd disklabel as found in
* /usr/include/sys/disklabel.h from a FreeBSD system.
*
* Everything is stored in little endian on the disk.
*/
/** BSD disklabel magic. */
/** Maximum number of partitions in the label. */
#define RTDVM_BSDLBL_MAX_PARTITIONS 8
/**
* A BSD disk label partition.
*/
#pragma pack(1)
typedef struct BsdLabelPartition
{
/** Number of sectors in the partition. */
/** Start sector. */
/** Filesystem fragment size. */
/** Filesystem type. */
/** Filesystem fragments per block. */
/** Filesystem cylinders per group. */
#pragma pack()
/** Pointer to a BSD disklabel partition structure. */
typedef BsdLabelPartition *PBsdLabelPartition;
/**
* On disk BSD label structure.
*/
#pragma pack(1)
typedef struct BsdLabel
{
/** Magic identifying the BSD disk label. */
/** Drive type */
/** Subtype depending on the drive type above. */
/** Type name. */
/** Pack identifier. */
/** Number of bytes per sector. */
/** Number of sectors per track. */
/** Number of tracks per cylinder. */
/** Number of data cylinders pre unit. */
/** Number of data sectors per cylinder. */
/** Number of data sectors per unit (unit as in disk drive?). */
/** Number of spare sectors per track. */
/** Number of spare sectors per cylinder. */
/** Number of alternate cylinders per unit. */
/** Rotational speed of the disk drive in rotations per minute. */
/** Sector interleave. */
/** Sector 0 skew, per track. */
/** Sector 0 skew, per cylinder. */
/** Head switch time in us. */
/** Time of a track-to-track seek in us. */
/** Flags. */
/** Drive type sepcific information. */
/** Reserved. */
/** The magic number again. */
/** Checksum (xor of the whole structure). */
/** Number of partitions in the array. */
/** Boot area size in bytes. */
/** Maximum size of the filesystem super block. */
/** The partition array. */
} BsdLabel;
#pragma pack()
/** Pointer to a BSD disklabel structure. */
/**
* BSD disk label volume manager data.
*/
typedef struct RTDVMFMTINTERNAL
{
/** Pointer to the underlying disk. */
/** Number of used partitions. */
/** Saved BSD disklabel structure. */
/** 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. */
/** Converts a LBA number to the byte offset. */
/** Converts a Byte offset to the LBA number. */
/**
* Calculates the checksum of the entire bsd disklabel structure.
*
* @returns The checksum.
* @param pBsdLabel BSD disklabel to get teh checksum for.
*/
{
return uChkSum;
}
/**
* Converts a partition entry to the host endianness.
*
* @returns nothing.
* @param pPartition The partition to decode.
*/
{
}
/**
* Converts the on disk BSD label to the host endianness.
*
* @returns Whether the given label structure is a valid BSD disklabel.
* @param pBsdLabel Pointer to the BSD disklabel to decode.
*/
{
/* Check the magics now. */
return false;
/* Convert the partitions array. */
/* Check the checksum now. */
return false;
return true;
}
{
int rc = VINF_SUCCESS;
{
/* Read from the disk and check for the disk label structure. */
if ( RT_SUCCESS(rc)
}
return rc;
}
{
int rc = VINF_SUCCESS;
{
pThis->cPartitions = 0;
/* Read from the disk and check for the disk label structure. */
if ( RT_SUCCESS(rc)
{
/* Count number of used entries. */
pThis->cPartitions++;
*phVolMgrFmt = pThis;
}
else
{
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
{
return VERR_NOT_IMPLEMENTED;
}
{
pThis->cPartitions = 0;
}
{
return pThis->cPartitions;
}
{
}
/**
* Creates a new volume.
*
* @returns IPRT status code.
* @param pThis The MBR volume manager data.
* @param pbBsdLblEntry The raw MBR entry data.
* @param idx The index in the partition table.
* @param phVolFmt Where to store the volume data on success.
*/
static int rtDvmFmtBsdLblVolumeCreate(PRTDVMFMTINTERNAL pThis, PBsdLabelPartition pBsdPartitionEntry,
{
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. */
{
{
i, phVolFmt);
break;
}
}
}
else
return rc;
}
DECLCALLBACK(int) rtDvmFmtBsdLblQueryNextVolume(RTDVMFMT hVolMgrFmt, RTDVMVOLUMEFMT hVolFmt, PRTDVMVOLUMEFMT phVolFmtNext)
{
int rc = VERR_DVM_MAP_NO_VOLUME;
{
if (pBsdPartitionEntry->cSectors)
{
break;
}
}
return rc;
}
{
}
{
}
{
return VERR_NOT_SUPPORTED;
}
{
return RTDVMVOLTYPE_UNKNOWN;
}
{
return 0;
}
{
bool fIntersect = false;
{
fIntersect = true;
}
return fIntersect;
}
DECLCALLBACK(int) rtDvmFmtBsdLblVolumeRead(RTDVMVOLUMEFMT hVolFmt, uint64_t off, void *pvBuf, size_t cbRead)
{
}
DECLCALLBACK(int) rtDvmFmtBsdLblVolumeWrite(RTDVMVOLUMEFMT hVolFmt, uint64_t off, const void *pvBuf, size_t cbWrite)
{
}
{
/* pcszFmt */
"BsdLabel",
/* pfnProbe */
/* pfnOpen */
/* pfnInitialize */
/* pfnClose */
/* pfnGetValidVolumes */
/* pfnGetMaxVolumes */
/* pfnQueryFirstVolume */
/* pfnQueryNextVolume */
/* pfnVolumeClose */
/* pfnVolumeGetSize */
/* pfnVolumeQueryName */
/* pfnVolumeGetType */
/* pfnVolumeGetFlags */
/* pfnVolumeIsRangeIntersecting */
/* pfnVolumeRead */
/* pfnVolumeWrite */
};