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