os/kernelhwsrv/kernel/eka/drivers/medmmc/mmcptn.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // \e32\drivers\medmmc\mmcptn.cpp
    15 // 
    16 //
    17 
    18 #include "sdcard.h"
    19 #include "OstTraceDefinitions.h"
    20 #ifdef OST_TRACE_COMPILER_IN_USE
    21 #include "locmedia_ost.h"
    22 #ifdef __VC32__
    23 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
    24 #endif
    25 #include "mmcptnTraces.h"
    26 #endif
    27 
    28 const TInt KDiskSectorShift = 9;
    29 
    30 LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry)
    31 	{
    32 	OstTraceFunctionEntry0( _SETPARTITIONTYPE_ENTRY );
    33 	if(aCard.IsHighCapacity())
    34 		{
    35 		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
    36 		}
    37 	else if(aPartitionEntry.iNumSectors < 32680)
    38 		{
    39 		aPartitionEntry.iPartitionType = KPartitionTypeFAT12;
    40 		}
    41 	else if(aPartitionEntry.iNumSectors < 65536)
    42 		{
    43 		aPartitionEntry.iPartitionType = KPartitionTypeFAT16small;
    44 		}
    45 	else if (aPartitionEntry.iNumSectors < 1048576)
    46 		{
    47 		aPartitionEntry.iPartitionType = KPartitionTypeFAT16;
    48  		}
    49 	else
    50 		{
    51 		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
    52 		}
    53 	OstTraceFunctionExit0( _SETPARTITIONTYPE_EXIT );
    54 	}
    55 
    56 /**
    57 Get the write block size to allow the FAT file system to calculate a suitable cluster size
    58 */
    59 GLDEF_C TInt BlockSize(const TMMCard* aCardP)
    60 	{
    61 	OstTraceFunctionEntry0( _BLOCKSIZE_ENTRY );
    62 	if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard())
    63 		return KMMCardHighCapBlockSize;
    64 
    65 	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
    66 
    67 	TInt blockSize = 
    68 		extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ? 
    69 		512 << (extCSD.AccessSize()-1) :
    70 			KMMCardHighCapBlockSize;			// default write block size = 512
    71 
    72 	OstTraceFunctionExit0( _BLOCKSIZE_EXIT );
    73 	return blockSize;
    74 	}
    75 
    76 /**
    77 Get Erase block size to allow FAT file system to align first usable cluster correctly
    78 */
    79 GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP)
    80 	{
    81 	OstTraceFunctionEntry0( _ERASEBLOCKSIZE_ENTRY );
    82 	if (aCardP == NULL)
    83 	    {
    84 		OstTraceFunctionExit0( _ERASEBLOCKSIZE_EXIT );
    85 		return 0;
    86 	    }
    87 	
    88 	const TUint K8KBShift = 13;
    89 	if (((const TSDCard *) aCardP)->IsSDCard())
    90 		{
    91 		//Allocation Unit is returned as EraseBlockSize for SD card
    92 		//as calculation for MMC card is not valid for SD card.
    93 		TUint8 auSize = ((const TSDCard *) aCardP)->GetAUSize();
    94 		//eraseBlkSize is 2^(auSize + K8KBShift)
    95 		TInt eraseBlkSize = 1 << (auSize + K8KBShift) ;
    96 		OstTraceFunctionExit0( DUP1__ERASEBLOCKSIZE_EXIT );
    97 		return eraseBlkSize;
    98 		}
    99 
   100 
   101 	TInt eraseBlockSize;
   102 
   103 	// Revision 1.0 of the "File Formats Specification for MultiMediaCards" dictates that 
   104 	// for High-Capacity MMC cards (i.e. FAT32 cards), 
   105 	// "There shall be a Master Boot Record with valid partition information. The partition(s)
   106 	// "and user data area(s) shall start from the beginning of an erasable unit (i.e. physical
   107 	// "block boundary).
   108 	// Version 1.0 of the "The MultiMediaCard FAT16 File System Specification" recommends having a 
   109 	// 16KB MBR and aligning the root directory entry (which is also 16KB long) and the first usable 
   110 	// sector to a 16KB boundary
   111 
   112 	const TUint K512KBShift = 19;
   113 	const TInt K16KBytes = 16384;
   114 	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
   115 
   116 	if (extCSD.ExtendedCSDRev() >= 3 && extCSD.HighCapacityEraseGroupSize() && extCSD.EraseGroupDef())
   117 		eraseBlockSize = extCSD.HighCapacityEraseGroupSize() << K512KBShift;
   118 	else if (aCardP->IsHighCapacity())
   119 		eraseBlockSize = aCardP->CSD().EraseGroupSize();
   120 	else
   121 		eraseBlockSize = K16KBytes;
   122 
   123 	OstTraceFunctionExit0( DUP2__ERASEBLOCKSIZE_EXIT );
   124 	return eraseBlockSize;
   125 	}
   126 
   127 /**
   128 	Calculates the default partition information for an MMC Card
   129 	@param aPartitionEntry The TMBRPartitionEntry to be filled in with the format parameters
   130 	@return Standard Symbian OS Error Code
   131  */
   132 GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP)
   133 	{
   134 	OstTraceFunctionEntry0( _GETMEDIADEFAULTPARTITIONINFO_ENTRY );
   135 	const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift);
   136 
   137 	aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift;
   138 	aPartitionEntry.iNumSectors  = KTotalSectors - aPartitionEntry.iFirstSector;
   139 	aPartitionEntry.iX86BootIndicator = 0x00;
   140 	SetPartitionType(*aCardP, aPartitionEntry);
   141 
   142 	aReservedSectors = 0;	// Let the filesystem decide on the appropriate value..
   143 
   144 	OstTraceFunctionExit0( _GETMEDIADEFAULTPARTITIONINFO_EXIT );
   145 	return(KErrNone);
   146 	}
   147 
   148 /**
   149 	Returns whether having a Master Boot Record is mandatory
   150 	
   151 	@return ETrue if MBR is mandatory for this card
   152  */
   153 GLDEF_C TBool MBRMandatory(const TMMCard* /*aCardP*/)
   154 	{
   155 	return EFalse;
   156 	}
   157 /**
   158 	Returns whether to create a Master Boot Record after a format
   159 	
   160 	@return ETrue if MBR should be created
   161  */
   162 GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP)
   163 	{
   164 	OstTraceFunctionEntry0( _CREATEMBRAFTERFORMAT_ENTRY );
   165 	if(aCardP == NULL)
   166 		{
   167 		OstTraceFunctionExit0( _CREATEMBRAFTERFORMAT_EXIT );
   168 		return EFalse;
   169 		}
   170 
   171 	// Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards
   172 	if (aCardP->IsHighCapacity())
   173 		{
   174 		OstTraceFunctionExit0( DUP1__CREATEMBRAFTERFORMAT_EXIT );
   175 		return ETrue;
   176 		}
   177 #ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC
   178 	if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680)
   179 		{
   180 		OstTraceFunctionExit0( DUP2__CREATEMBRAFTERFORMAT_EXIT );
   181 		return ETrue;
   182 		}
   183 #endif
   184 	
   185 	OstTraceFunctionExit0( DUP3__CREATEMBRAFTERFORMAT_EXIT );
   186 	return EFalse;
   187 	}
   188 
   189 GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/)
   190 /**
   191  * Returns the preferred format parameters for the primary partition.
   192  * @return Standard Symbian OS error code.
   193  */
   194 	{
   195 	return KErrNotSupported;
   196 	}
   197