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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // \e32\drivers\medmmc\mmcptn.cpp
19 #include "OstTraceDefinitions.h"
20 #ifdef OST_TRACE_COMPILER_IN_USE
21 #include "locmedia_ost.h"
23 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
25 #include "mmcptnTraces.h"
28 const TInt KDiskSectorShift = 9;
30 LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry)
32 OstTraceFunctionEntry0( _SETPARTITIONTYPE_ENTRY );
33 if(aCard.IsHighCapacity())
35 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
37 else if(aPartitionEntry.iNumSectors < 32680)
39 aPartitionEntry.iPartitionType = KPartitionTypeFAT12;
41 else if(aPartitionEntry.iNumSectors < 65536)
43 aPartitionEntry.iPartitionType = KPartitionTypeFAT16small;
45 else if (aPartitionEntry.iNumSectors < 1048576)
47 aPartitionEntry.iPartitionType = KPartitionTypeFAT16;
51 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32;
53 OstTraceFunctionExit0( _SETPARTITIONTYPE_EXIT );
57 Get the write block size to allow the FAT file system to calculate a suitable cluster size
59 GLDEF_C TInt BlockSize(const TMMCard* aCardP)
61 OstTraceFunctionEntry0( _BLOCKSIZE_ENTRY );
62 if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard())
63 return KMMCardHighCapBlockSize;
65 const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
68 extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ?
69 512 << (extCSD.AccessSize()-1) :
70 KMMCardHighCapBlockSize; // default write block size = 512
72 OstTraceFunctionExit0( _BLOCKSIZE_EXIT );
77 Get Erase block size to allow FAT file system to align first usable cluster correctly
79 GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP)
81 OstTraceFunctionEntry0( _ERASEBLOCKSIZE_ENTRY );
84 OstTraceFunctionExit0( _ERASEBLOCKSIZE_EXIT );
88 const TUint K8KBShift = 13;
89 if (((const TSDCard *) aCardP)->IsSDCard())
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 );
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
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
112 const TUint K512KBShift = 19;
113 const TInt K16KBytes = 16384;
114 const TExtendedCSD& extCSD = aCardP->ExtendedCSD();
116 if (extCSD.ExtendedCSDRev() >= 3 && extCSD.HighCapacityEraseGroupSize() && extCSD.EraseGroupDef())
117 eraseBlockSize = extCSD.HighCapacityEraseGroupSize() << K512KBShift;
118 else if (aCardP->IsHighCapacity())
119 eraseBlockSize = aCardP->CSD().EraseGroupSize();
121 eraseBlockSize = K16KBytes;
123 OstTraceFunctionExit0( DUP2__ERASEBLOCKSIZE_EXIT );
124 return eraseBlockSize;
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
132 GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP)
134 OstTraceFunctionEntry0( _GETMEDIADEFAULTPARTITIONINFO_ENTRY );
135 const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift);
137 aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift;
138 aPartitionEntry.iNumSectors = KTotalSectors - aPartitionEntry.iFirstSector;
139 aPartitionEntry.iX86BootIndicator = 0x00;
140 SetPartitionType(*aCardP, aPartitionEntry);
142 aReservedSectors = 0; // Let the filesystem decide on the appropriate value..
144 OstTraceFunctionExit0( _GETMEDIADEFAULTPARTITIONINFO_EXIT );
149 Returns whether having a Master Boot Record is mandatory
151 @return ETrue if MBR is mandatory for this card
153 GLDEF_C TBool MBRMandatory(const TMMCard* /*aCardP*/)
158 Returns whether to create a Master Boot Record after a format
160 @return ETrue if MBR should be created
162 GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP)
164 OstTraceFunctionEntry0( _CREATEMBRAFTERFORMAT_ENTRY );
167 OstTraceFunctionExit0( _CREATEMBRAFTERFORMAT_EXIT );
171 // Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards
172 if (aCardP->IsHighCapacity())
174 OstTraceFunctionExit0( DUP1__CREATEMBRAFTERFORMAT_EXIT );
177 #ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC
178 if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680)
180 OstTraceFunctionExit0( DUP2__CREATEMBRAFTERFORMAT_EXIT );
185 OstTraceFunctionExit0( DUP3__CREATEMBRAFTERFORMAT_EXIT );
189 GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/)
191 * Returns the preferred format parameters for the primary partition.
192 * @return Standard Symbian OS error code.
195 return KErrNotSupported;