14 // \e32\drivers\medmmc\mmcptn.cpp |
14 // \e32\drivers\medmmc\mmcptn.cpp |
15 // |
15 // |
16 // |
16 // |
17 |
17 |
18 #include "sdcard.h" |
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 |
19 |
27 |
20 const TInt KDiskSectorShift = 9; |
28 const TInt KDiskSectorShift = 9; |
21 |
29 |
22 LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry) |
30 LOCAL_C void SetPartitionType(const TMMCard& aCard, TMBRPartitionEntry& aPartitionEntry) |
23 { |
31 { |
|
32 OstTraceFunctionEntry0( _SETPARTITIONTYPE_ENTRY ); |
24 if(aCard.IsHighCapacity()) |
33 if(aCard.IsHighCapacity()) |
25 { |
34 { |
26 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32; |
35 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32; |
27 } |
36 } |
28 else if(aPartitionEntry.iNumSectors < 32680) |
37 else if(aPartitionEntry.iNumSectors < 32680) |
39 } |
48 } |
40 else |
49 else |
41 { |
50 { |
42 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32; |
51 aPartitionEntry.iPartitionType = KPartitionTypeWin95FAT32; |
43 } |
52 } |
|
53 OstTraceFunctionExit0( _SETPARTITIONTYPE_EXIT ); |
44 } |
54 } |
45 |
55 |
46 /** |
56 /** |
47 Get the write block size to allow the FAT file system to calculate a suitable cluster size |
57 Get the write block size to allow the FAT file system to calculate a suitable cluster size |
48 */ |
58 */ |
49 GLDEF_C TInt BlockSize(const TMMCard* aCardP) |
59 GLDEF_C TInt BlockSize(const TMMCard* aCardP) |
50 { |
60 { |
|
61 OstTraceFunctionEntry0( _BLOCKSIZE_ENTRY ); |
51 if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard()) |
62 if ((aCardP == NULL) || ((const TSDCard *) aCardP)->IsSDCard()) |
52 return KMMCardHighCapBlockSize; |
63 return KMMCardHighCapBlockSize; |
53 |
64 |
54 const TExtendedCSD& extCSD = aCardP->ExtendedCSD(); |
65 const TExtendedCSD& extCSD = aCardP->ExtendedCSD(); |
55 |
66 |
56 TInt blockSize = |
67 TInt blockSize = |
57 extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ? |
68 extCSD.ExtendedCSDRev() >= 3 && extCSD.AccessSize() < 9 ? |
58 512 << (extCSD.AccessSize()-1) : |
69 512 << (extCSD.AccessSize()-1) : |
59 KMMCardHighCapBlockSize; // default write block size = 512 |
70 KMMCardHighCapBlockSize; // default write block size = 512 |
60 |
71 |
|
72 OstTraceFunctionExit0( _BLOCKSIZE_EXIT ); |
61 return blockSize; |
73 return blockSize; |
62 } |
74 } |
63 |
75 |
64 /** |
76 /** |
65 Get Erase block size to allow FAT file system to align first usable cluster correctly |
77 Get Erase block size to allow FAT file system to align first usable cluster correctly |
66 */ |
78 */ |
67 GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP) |
79 GLDEF_C TInt EraseBlockSize(const TMMCard* aCardP) |
68 { |
80 { |
|
81 OstTraceFunctionEntry0( _ERASEBLOCKSIZE_ENTRY ); |
69 if (aCardP == NULL) |
82 if (aCardP == NULL) |
|
83 { |
|
84 OstTraceFunctionExit0( _ERASEBLOCKSIZE_EXIT ); |
70 return 0; |
85 return 0; |
71 |
86 } |
72 |
87 |
73 const TUint K8KBShift = 13; |
88 const TUint K8KBShift = 13; |
74 if (((const TSDCard *) aCardP)->IsSDCard()) |
89 if (((const TSDCard *) aCardP)->IsSDCard()) |
75 { |
90 { |
76 //Allocation Unit is returned as EraseBlockSize for SD card |
91 //Allocation Unit is returned as EraseBlockSize for SD card |
77 //as calculation for MMC card is not valid for SD card. |
92 //as calculation for MMC card is not valid for SD card. |
78 TUint8 auSize = ((const TSDCard *) aCardP)->GetAUSize(); |
93 TUint8 auSize = ((const TSDCard *) aCardP)->GetAUSize(); |
79 //eraseBlkSize is 2^(auSize + K8KBShift) |
94 //eraseBlkSize is 2^(auSize + K8KBShift) |
80 TInt eraseBlkSize = 1 << (auSize + K8KBShift) ; |
95 TInt eraseBlkSize = 1 << (auSize + K8KBShift) ; |
81 return (eraseBlkSize); |
96 OstTraceFunctionExit0( DUP1__ERASEBLOCKSIZE_EXIT ); |
|
97 return eraseBlkSize; |
82 } |
98 } |
83 |
99 |
84 |
100 |
85 TInt eraseBlockSize; |
101 TInt eraseBlockSize; |
86 |
102 |
102 else if (aCardP->IsHighCapacity()) |
118 else if (aCardP->IsHighCapacity()) |
103 eraseBlockSize = aCardP->CSD().EraseGroupSize(); |
119 eraseBlockSize = aCardP->CSD().EraseGroupSize(); |
104 else |
120 else |
105 eraseBlockSize = K16KBytes; |
121 eraseBlockSize = K16KBytes; |
106 |
122 |
|
123 OstTraceFunctionExit0( DUP2__ERASEBLOCKSIZE_EXIT ); |
107 return eraseBlockSize; |
124 return eraseBlockSize; |
108 } |
125 } |
109 |
126 |
110 /** |
127 /** |
111 Calculates the default partition information for an MMC Card |
128 Calculates the default partition information for an MMC Card |
112 @param aPartitionEntry The TMBRPartitionEntry to be filled in with the format parameters |
129 @param aPartitionEntry The TMBRPartitionEntry to be filled in with the format parameters |
113 @return Standard Symbian OS Error Code |
130 @return Standard Symbian OS Error Code |
114 */ |
131 */ |
115 GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP) |
132 GLDEF_C TInt GetMediaDefaultPartitionInfo(TMBRPartitionEntry& aPartitionEntry, TUint16& aReservedSectors, const TMMCard* aCardP) |
116 { |
133 { |
|
134 OstTraceFunctionEntry0( _GETMEDIADEFAULTPARTITIONINFO_ENTRY ); |
117 const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift); |
135 const TUint32 KTotalSectors = I64LOW(aCardP->DeviceSize64() >> KDiskSectorShift); |
118 |
136 |
119 aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift; |
137 aPartitionEntry.iFirstSector = EraseBlockSize(aCardP) >> KDiskSectorShift; |
120 aPartitionEntry.iNumSectors = KTotalSectors - aPartitionEntry.iFirstSector; |
138 aPartitionEntry.iNumSectors = KTotalSectors - aPartitionEntry.iFirstSector; |
121 aPartitionEntry.iX86BootIndicator = 0x00; |
139 aPartitionEntry.iX86BootIndicator = 0x00; |
122 SetPartitionType(*aCardP, aPartitionEntry); |
140 SetPartitionType(*aCardP, aPartitionEntry); |
123 |
141 |
124 aReservedSectors = 0; // Let the filesystem decide on the appropriate value.. |
142 aReservedSectors = 0; // Let the filesystem decide on the appropriate value.. |
125 |
143 |
|
144 OstTraceFunctionExit0( _GETMEDIADEFAULTPARTITIONINFO_EXIT ); |
126 return(KErrNone); |
145 return(KErrNone); |
127 } |
146 } |
128 |
147 |
129 /** |
148 /** |
130 Returns whether having a Master Boot Record is mandatory |
149 Returns whether having a Master Boot Record is mandatory |
140 |
159 |
141 @return ETrue if MBR should be created |
160 @return ETrue if MBR should be created |
142 */ |
161 */ |
143 GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP) |
162 GLDEF_C TBool CreateMBRAfterFormat(const TMMCard* aCardP) |
144 { |
163 { |
|
164 OstTraceFunctionEntry0( _CREATEMBRAFTERFORMAT_ENTRY ); |
145 if(aCardP == NULL) |
165 if(aCardP == NULL) |
146 { |
166 { |
|
167 OstTraceFunctionExit0( _CREATEMBRAFTERFORMAT_EXIT ); |
147 return EFalse; |
168 return EFalse; |
148 } |
169 } |
149 |
170 |
150 // Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards |
171 // Create an MBR on high capacity (FAT32) cards and optionally on low-capacity FAT16/FAT32 MMC cards |
151 if (aCardP->IsHighCapacity()) |
172 if (aCardP->IsHighCapacity()) |
152 { |
173 { |
|
174 OstTraceFunctionExit0( DUP1__CREATEMBRAFTERFORMAT_EXIT ); |
153 return ETrue; |
175 return ETrue; |
154 } |
176 } |
155 #ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC |
177 #ifdef SYMBIAN_CREATE_MBR_ON_LOW_CAPACITY_MMC |
156 if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680) |
178 if ((I64LOW(aCardP->DeviceSize64()) >> KDiskSectorShift) >= 32680) |
157 { |
179 { |
|
180 OstTraceFunctionExit0( DUP2__CREATEMBRAFTERFORMAT_EXIT ); |
158 return ETrue; |
181 return ETrue; |
159 } |
182 } |
160 #endif |
183 #endif |
161 |
184 |
|
185 OstTraceFunctionExit0( DUP3__CREATEMBRAFTERFORMAT_EXIT ); |
162 return EFalse; |
186 return EFalse; |
163 } |
187 } |
164 |
188 |
165 GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/) |
189 GLDEF_C TInt GetCardFormatInfo(const TMMCard* /*aCardP*/, TLDFormatInfo& /*aFormatInfo*/) |
166 /** |
190 /** |