os/kernelhwsrv/kernel/eka/drivers/medmmc/mmcptn.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/medmmc/mmcptn.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,197 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// \e32\drivers\medmmc\mmcptn.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "sdcard.h"
    1.22 +#include "OstTraceDefinitions.h"
    1.23 +#ifdef OST_TRACE_COMPILER_IN_USE
    1.24 +#include "locmedia_ost.h"
    1.25 +#ifdef __VC32__
    1.26 +#pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
    1.27 +#endif
    1.28 +#include "mmcptnTraces.h"
    1.29 +#endif
    1.30 +
    1.31 +const TInt KDiskSectorShift = 9;
    1.32 +
    1.33 +LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry)
    1.34 +	{
    1.35 +	OstTraceFunctionEntry0( _SETPARTITIONTYPE_ENTRY );
    1.36 +	if(aCard.IsHighCapacity())
    1.37 +		{
    1.38 +		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
    1.39 +		}
    1.40 +	else if(aPartitionEntry.iNumSectors < 32680)
    1.41 +		{
    1.42 +		aPartitionEntry.iPartitionType = KPartitionTypeFAT12;
    1.43 +		}
    1.44 +	else if(aPartitionEntry.iNumSectors < 65536)
    1.45 +		{
    1.46 +		aPartitionEntry.iPartitionType = KPartitionTypeFAT16small;
    1.47 +		}
    1.48 +	else if (aPartitionEntry.iNumSectors < 1048576)
    1.49 +		{
    1.50 +		aPartitionEntry.iPartitionType = KPartitionTypeFAT16;
    1.51 + 		}
    1.52 +	else
    1.53 +		{
    1.54 +		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
    1.55 +		}
    1.56 +	OstTraceFunctionExit0( _SETPARTITIONTYPE_EXIT );
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +Get the write block size to allow the FAT file system to calculate a suitable cluster size
    1.61 +*/
    1.62 +GLDEF_C TInt BlockSize(const TMMCard* aCardP)
    1.63 +	{
    1.64 +	OstTraceFunctionEntry0( _BLOCKSIZE_ENTRY );
    1.65 +	if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard())
    1.66 +		return KMMCardHighCapBlockSize;
    1.67 +
    1.68 +	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
    1.69 +
    1.70 +	TInt blockSize = 
    1.71 +		extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ? 
    1.72 +		512 << (extCSD.AccessSize()-1) :
    1.73 +			KMMCardHighCapBlockSize;			// default write block size = 512
    1.74 +
    1.75 +	OstTraceFunctionExit0( _BLOCKSIZE_EXIT );
    1.76 +	return blockSize;
    1.77 +	}
    1.78 +
    1.79 +/**
    1.80 +Get Erase block size to allow FAT file system to align first usable cluster correctly
    1.81 +*/
    1.82 +GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP)
    1.83 +	{
    1.84 +	OstTraceFunctionEntry0( _ERASEBLOCKSIZE_ENTRY );
    1.85 +	if (aCardP == NULL)
    1.86 +	    {
    1.87 +		OstTraceFunctionExit0( _ERASEBLOCKSIZE_EXIT );
    1.88 +		return 0;
    1.89 +	    }
    1.90 +	
    1.91 +	const TUint K8KBShift = 13;
    1.92 +	if (((const TSDCard *) aCardP)->IsSDCard())
    1.93 +		{
    1.94 +		//Allocation Unit is returned as EraseBlockSize for SD card
    1.95 +		//as calculation for MMC card is not valid for SD card.
    1.96 +		TUint8 auSize = ((const TSDCard *) aCardP)->GetAUSize();
    1.97 +		//eraseBlkSize is 2^(auSize + K8KBShift)
    1.98 +		TInt eraseBlkSize = 1 << (auSize + K8KBShift) ;
    1.99 +		OstTraceFunctionExit0( DUP1__ERASEBLOCKSIZE_EXIT );
   1.100 +		return eraseBlkSize;
   1.101 +		}
   1.102 +
   1.103 +
   1.104 +	TInt eraseBlockSize;
   1.105 +
   1.106 +	// Revision 1.0 of the "File Formats Specification for MultiMediaCards" dictates that 
   1.107 +	// for High-Capacity MMC cards (i.e. FAT32 cards), 
   1.108 +	// "There shall be a Master Boot Record with valid partition information. The partition(s)
   1.109 +	// "and user data area(s) shall start from the beginning of an erasable unit (i.e. physical
   1.110 +	// "block boundary).
   1.111 +	// Version 1.0 of the "The MultiMediaCard FAT16 File System Specification" recommends having a 
   1.112 +	// 16KB MBR and aligning the root directory entry (which is also 16KB long) and the first usable 
   1.113 +	// sector to a 16KB boundary
   1.114 +
   1.115 +	const TUint K512KBShift = 19;
   1.116 +	const TInt K16KBytes = 16384;
   1.117 +	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
   1.118 +
   1.119 +	if (extCSD.ExtendedCSDRev() >= 3 && extCSD.HighCapacityEraseGroupSize() && extCSD.EraseGroupDef())
   1.120 +		eraseBlockSize = extCSD.HighCapacityEraseGroupSize() << K512KBShift;
   1.121 +	else if (aCardP->IsHighCapacity())
   1.122 +		eraseBlockSize = aCardP->CSD().EraseGroupSize();
   1.123 +	else
   1.124 +		eraseBlockSize = K16KBytes;
   1.125 +
   1.126 +	OstTraceFunctionExit0( DUP2__ERASEBLOCKSIZE_EXIT );
   1.127 +	return eraseBlockSize;
   1.128 +	}
   1.129 +
   1.130 +/**
   1.131 +	Calculates the default partition information for an MMC Card
   1.132 +	@param aPartitionEntry The TMBRPartitionEntry to be filled in with the format parameters
   1.133 +	@return Standard Symbian OS Error Code
   1.134 + */
   1.135 +GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP)
   1.136 +	{
   1.137 +	OstTraceFunctionEntry0( _GETMEDIADEFAULTPARTITIONINFO_ENTRY );
   1.138 +	const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift);
   1.139 +
   1.140 +	aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift;
   1.141 +	aPartitionEntry.iNumSectors  = KTotalSectors - aPartitionEntry.iFirstSector;
   1.142 +	aPartitionEntry.iX86BootIndicator = 0x00;
   1.143 +	SetPartitionType(*aCardP, aPartitionEntry);
   1.144 +
   1.145 +	aReservedSectors = 0;	// Let the filesystem decide on the appropriate value..
   1.146 +
   1.147 +	OstTraceFunctionExit0( _GETMEDIADEFAULTPARTITIONINFO_EXIT );
   1.148 +	return(KErrNone);
   1.149 +	}
   1.150 +
   1.151 +/**
   1.152 +	Returns whether having a Master Boot Record is mandatory
   1.153 +	
   1.154 +	@return ETrue if MBR is mandatory for this card
   1.155 + */
   1.156 +GLDEF_C TBool MBRMandatory(const TMMCard* /*aCardP*/)
   1.157 +	{
   1.158 +	return EFalse;
   1.159 +	}
   1.160 +/**
   1.161 +	Returns whether to create a Master Boot Record after a format
   1.162 +	
   1.163 +	@return ETrue if MBR should be created
   1.164 + */
   1.165 +GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP)
   1.166 +	{
   1.167 +	OstTraceFunctionEntry0( _CREATEMBRAFTERFORMAT_ENTRY );
   1.168 +	if(aCardP == NULL)
   1.169 +		{
   1.170 +		OstTraceFunctionExit0( _CREATEMBRAFTERFORMAT_EXIT );
   1.171 +		return EFalse;
   1.172 +		}
   1.173 +
   1.174 +	// Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards
   1.175 +	if (aCardP->IsHighCapacity())
   1.176 +		{
   1.177 +		OstTraceFunctionExit0( DUP1__CREATEMBRAFTERFORMAT_EXIT );
   1.178 +		return ETrue;
   1.179 +		}
   1.180 +#ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC
   1.181 +	if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680)
   1.182 +		{
   1.183 +		OstTraceFunctionExit0( DUP2__CREATEMBRAFTERFORMAT_EXIT );
   1.184 +		return ETrue;
   1.185 +		}
   1.186 +#endif
   1.187 +	
   1.188 +	OstTraceFunctionExit0( DUP3__CREATEMBRAFTERFORMAT_EXIT );
   1.189 +	return EFalse;
   1.190 +	}
   1.191 +
   1.192 +GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/)
   1.193 +/**
   1.194 + * Returns the preferred format parameters for the primary partition.
   1.195 + * @return Standard Symbian OS error code.
   1.196 + */
   1.197 +	{
   1.198 +	return KErrNotSupported;
   1.199 +	}
   1.200 +