author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 09 Jun 2010 11:10:19 +0300 | |
branch | RCL_3 |
changeset 36 | bbf8bed59bcb |
parent 14 | 5d2844f35677 |
permissions | -rw-r--r-- |
0 | 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" |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
19 |
#include "OstTraceDefinitions.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
20 |
#ifdef OST_TRACE_COMPILER_IN_USE |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
21 |
#include "locmedia_ost.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#ifdef __VC32__ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
23 |
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
#endif |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
25 |
#include "mmcptnTraces.h" |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
26 |
#endif |
0 | 27 |
|
28 |
const TInt KDiskSectorShift = 9; |
|
29 |
||
30 |
LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry) |
|
31 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
32 |
OstTraceFunctionEntry0( _SETPARTITIONTYPE_ENTRY ); |
0 | 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 |
} |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
53 |
OstTraceFunctionExit0( _SETPARTITIONTYPE_EXIT ); |
0 | 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 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
OstTraceFunctionEntry0( _BLOCKSIZE_ENTRY ); |
0 | 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 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
OstTraceFunctionExit0( _BLOCKSIZE_EXIT ); |
0 | 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 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
OstTraceFunctionEntry0( _ERASEBLOCKSIZE_ENTRY ); |
0 | 82 |
if (aCardP == NULL) |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
OstTraceFunctionExit0( _ERASEBLOCKSIZE_EXIT ); |
0 | 85 |
return 0; |
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
} |
0 | 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) ; |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
OstTraceFunctionExit0( DUP1__ERASEBLOCKSIZE_EXIT ); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
return eraseBlkSize; |
0 | 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 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
OstTraceFunctionExit0( DUP2__ERASEBLOCKSIZE_EXIT ); |
0 | 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 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
OstTraceFunctionEntry0( _GETMEDIADEFAULTPARTITIONINFO_ENTRY ); |
0 | 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 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
OstTraceFunctionExit0( _GETMEDIADEFAULTPARTITIONINFO_EXIT ); |
0 | 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 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
OstTraceFunctionEntry0( _CREATEMBRAFTERFORMAT_ENTRY ); |
0 | 165 |
if(aCardP == NULL) |
166 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
OstTraceFunctionExit0( _CREATEMBRAFTERFORMAT_EXIT ); |
0 | 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 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
OstTraceFunctionExit0( DUP1__CREATEMBRAFTERFORMAT_EXIT ); |
0 | 175 |
return ETrue; |
176 |
} |
|
177 |
#ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC |
|
178 |
if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680) |
|
179 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
OstTraceFunctionExit0( DUP2__CREATEMBRAFTERFORMAT_EXIT ); |
0 | 181 |
return ETrue; |
182 |
} |
|
183 |
#endif |
|
184 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
OstTraceFunctionExit0( DUP3__CREATEMBRAFTERFORMAT_EXIT ); |
0 | 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 |