kernel/eka/drivers/medmmc/mmcptn.cpp
changeset 0 a41df078684a
child 39 5d2844f35677
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 
       
    20 const TInt KDiskSectorShift = 9;
       
    21 
       
    22 LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry)
       
    23 	{
       
    24 	if(aCard.IsHighCapacity())
       
    25 		{
       
    26 		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
       
    27 		}
       
    28 	else if(aPartitionEntry.iNumSectors < 32680)
       
    29 		{
       
    30 		aPartitionEntry.iPartitionType = KPartitionTypeFAT12;
       
    31 		}
       
    32 	else if(aPartitionEntry.iNumSectors < 65536)
       
    33 		{
       
    34 		aPartitionEntry.iPartitionType = KPartitionTypeFAT16small;
       
    35 		}
       
    36 	else if (aPartitionEntry.iNumSectors < 1048576)
       
    37 		{
       
    38 		aPartitionEntry.iPartitionType = KPartitionTypeFAT16;
       
    39  		}
       
    40 	else
       
    41 		{
       
    42 		aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
       
    43 		}
       
    44 	}
       
    45 
       
    46 /**
       
    47 Get the write block size to allow the FAT file system to calculate a suitable cluster size
       
    48 */
       
    49 GLDEF_C TInt BlockSize(const TMMCard* aCardP)
       
    50 	{
       
    51 	if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard())
       
    52 		return KMMCardHighCapBlockSize;
       
    53 
       
    54 	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
       
    55 
       
    56 	TInt blockSize = 
       
    57 		extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ? 
       
    58 		512 << (extCSD.AccessSize()-1) :
       
    59 			KMMCardHighCapBlockSize;			// default write block size = 512
       
    60 
       
    61 	return blockSize;
       
    62 	}
       
    63 
       
    64 /**
       
    65 Get Erase block size to allow FAT file system to align first usable cluster correctly
       
    66 */
       
    67 GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP)
       
    68 	{
       
    69 	if (aCardP == NULL)
       
    70 		return 0;
       
    71 
       
    72 	
       
    73 	const TUint K8KBShift = 13;
       
    74 	if (((const TSDCard *) aCardP)->IsSDCard())
       
    75 		{
       
    76 		//Allocation Unit is returned as EraseBlockSize for SD card
       
    77 		//as calculation for MMC card is not valid for SD card.
       
    78 		TUint8 auSize = ((const TSDCard *) aCardP)->GetAUSize();
       
    79 		//eraseBlkSize is 2^(auSize + K8KBShift)
       
    80 		TInt eraseBlkSize = 1 << (auSize + K8KBShift) ;
       
    81 		return (eraseBlkSize);
       
    82 		}
       
    83 
       
    84 
       
    85 	TInt eraseBlockSize;
       
    86 
       
    87 	// Revision 1.0 of the "File Formats Specification for MultiMediaCards" dictates that 
       
    88 	// for High-Capacity MMC cards (i.e. FAT32 cards), 
       
    89 	// "There shall be a Master Boot Record with valid partition information. The partition(s)
       
    90 	// "and user data area(s) shall start from the beginning of an erasable unit (i.e. physical
       
    91 	// "block boundary).
       
    92 	// Version 1.0 of the "The MultiMediaCard FAT16 File System Specification" recommends having a 
       
    93 	// 16KB MBR and aligning the root directory entry (which is also 16KB long) and the first usable 
       
    94 	// sector to a 16KB boundary
       
    95 
       
    96 	const TUint K512KBShift = 19;
       
    97 	const TInt K16KBytes = 16384;
       
    98 	const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
       
    99 
       
   100 	if (extCSD.ExtendedCSDRev() >= 3 && extCSD.HighCapacityEraseGroupSize() && extCSD.EraseGroupDef())
       
   101 		eraseBlockSize = extCSD.HighCapacityEraseGroupSize() << K512KBShift;
       
   102 	else if (aCardP->IsHighCapacity())
       
   103 		eraseBlockSize = aCardP->CSD().EraseGroupSize();
       
   104 	else
       
   105 		eraseBlockSize = K16KBytes;
       
   106 
       
   107 	return eraseBlockSize;
       
   108 	}
       
   109 
       
   110 /**
       
   111 	Calculates the default partition information for an MMC Card
       
   112 	@param aPartitionEntry The TMBRPartitionEntry to be filled in with the format parameters
       
   113 	@return Standard Symbian OS Error Code
       
   114  */
       
   115 GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP)
       
   116 	{
       
   117 	const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift);
       
   118 
       
   119 	aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift;
       
   120 	aPartitionEntry.iNumSectors  = KTotalSectors - aPartitionEntry.iFirstSector;
       
   121 	aPartitionEntry.iX86BootIndicator = 0x00;
       
   122 	SetPartitionType(*aCardP, aPartitionEntry);
       
   123 
       
   124 	aReservedSectors = 0;	// Let the filesystem decide on the appropriate value..
       
   125 
       
   126 	return(KErrNone);
       
   127 	}
       
   128 
       
   129 /**
       
   130 	Returns whether having a Master Boot Record is mandatory
       
   131 	
       
   132 	@return ETrue if MBR is mandatory for this card
       
   133  */
       
   134 GLDEF_C TBool MBRMandatory(const TMMCard* /*aCardP*/)
       
   135 	{
       
   136 	return EFalse;
       
   137 	}
       
   138 /**
       
   139 	Returns whether to create a Master Boot Record after a format
       
   140 	
       
   141 	@return ETrue if MBR should be created
       
   142  */
       
   143 GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP)
       
   144 	{
       
   145 	if(aCardP == NULL)
       
   146 		{
       
   147 		return EFalse;
       
   148 		}
       
   149 
       
   150 	// Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards
       
   151 	if (aCardP->IsHighCapacity())
       
   152 		{
       
   153 		return ETrue;
       
   154 		}
       
   155 #ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC
       
   156 	if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680)
       
   157 		{
       
   158 		return ETrue;
       
   159 		}
       
   160 #endif
       
   161 	
       
   162 	return EFalse;
       
   163 	}
       
   164 
       
   165 GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/)
       
   166 /**
       
   167  * Returns the preferred format parameters for the primary partition.
       
   168  * @return Standard Symbian OS error code.
       
   169  */
       
   170 	{
       
   171 	return KErrNotSupported;
       
   172 	}
       
   173