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 |
// CMassStorageMountCB implementation.
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalTechnology
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include <f32fsys.h>
|
|
24 |
#include <f32file.h>
|
|
25 |
#include "cmassstoragemountcb.h"
|
|
26 |
#include "cmassstoragefilesystem.h"
|
|
27 |
#include "drivemanager.h"
|
|
28 |
#include "massstoragedebug.h"
|
|
29 |
#include "massstorageutil.h"
|
|
30 |
|
|
31 |
CMassStorageMountCB::CMassStorageMountCB(const RArray<TInt>& aDriveMapping)
|
|
32 |
: iDriveMapping(aDriveMapping)
|
|
33 |
{
|
|
34 |
}
|
|
35 |
|
|
36 |
CMassStorageMountCB* CMassStorageMountCB::NewL(const RArray<TInt>& aDriveMapping)
|
|
37 |
{
|
|
38 |
return new (ELeave) CMassStorageMountCB(aDriveMapping);
|
|
39 |
}
|
|
40 |
|
|
41 |
/**
|
|
42 |
Checks that the drive number is supported.
|
|
43 |
|
|
44 |
@leave KErrNotReady The drive number is not supported.
|
|
45 |
*/
|
|
46 |
TInt CMassStorageMountCB::CheckDriveNumberL()
|
|
47 |
{
|
|
48 |
__FNLOG("CMassStorageMountCB::CheckDriveNumberL");
|
|
49 |
TInt driveNumber;
|
|
50 |
driveNumber = Drive().DriveNumber();
|
|
51 |
if (!IsValidLocalDriveMapping(driveNumber))
|
|
52 |
{
|
|
53 |
__PRINT1(_L("CMassStorageMountCB::CheckDriveNumberL: Drive number %d not supported"), driveNumber);
|
|
54 |
User::Leave(KErrNotReady);
|
|
55 |
}
|
|
56 |
__PRINT1(_L("CMassStorageMountCB::CheckDriveNumberL: Drive number = %d"), driveNumber);
|
|
57 |
return driveNumber;
|
|
58 |
}
|
|
59 |
|
|
60 |
/**
|
|
61 |
Registers the drive with the Mass Storage drive manager.
|
|
62 |
|
|
63 |
@leave KErrNotSupported The drive is not compatible with Mass Storage.
|
|
64 |
*/
|
|
65 |
void CMassStorageMountCB::MountL(TBool /*aForceMount*/)
|
|
66 |
{
|
|
67 |
__FNLOG("CMassStorageMountCB::MountL");
|
|
68 |
|
|
69 |
CheckDriveNumberL();
|
|
70 |
CMassStorageFileSystem& msFsys = *reinterpret_cast<CMassStorageFileSystem*>(Drive().GetFSys());
|
|
71 |
|
|
72 |
TInt lun = DriveNumberToLun(Drive().DriveNumber());
|
|
73 |
|
|
74 |
if(lun < 0)
|
|
75 |
{
|
|
76 |
// This is not a supported Mass Storage drive
|
|
77 |
User::Leave(KErrNotSupported);
|
|
78 |
}
|
|
79 |
|
|
80 |
TBusLocalDrive& localDrive = msFsys.iLocalDriveForMediaFlag[lun];
|
|
81 |
|
|
82 |
TInt err = CreateLocalDrive(localDrive);
|
|
83 |
User::LeaveIfError(err);
|
|
84 |
|
|
85 |
CProxyDrive* proxyDrive = LocalDrive();
|
|
86 |
|
|
87 |
TLocalDriveCapsV2Buf caps;
|
|
88 |
err = localDrive.Caps(caps);
|
|
89 |
//Make sure file system is FAT and removable
|
|
90 |
if (err == KErrNone)
|
|
91 |
{
|
|
92 |
err = KErrNotSupported;
|
|
93 |
if ((caps().iDriveAtt & KDriveAttRemovable) == KDriveAttRemovable)
|
|
94 |
{
|
|
95 |
if (caps().iType != EMediaNotPresent)
|
|
96 |
{
|
|
97 |
err = KErrNone;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
if (err != KErrNone && err != KErrNotReady)
|
|
103 |
{
|
|
104 |
__PRINT1(_L("CMassStorageMountCB::MountL: Drive is not compatible with Mass Storage, err=%d"), err);
|
|
105 |
User::Leave(err);
|
|
106 |
}
|
|
107 |
|
|
108 |
__PRINT(_L("CMassStorageMountCB::MountL: Registering drive"));
|
|
109 |
|
|
110 |
// Set media changed to true so that Win2K doesn't used cached drive data
|
|
111 |
(*msFsys.iMediaChanged)[lun] = ETrue;
|
|
112 |
|
|
113 |
msFsys.Controller().DriveManager().RegisterDrive(*proxyDrive, (*msFsys.iMediaChanged)[lun], lun);
|
|
114 |
|
|
115 |
SetVolumeName(_L("MassStorage").AllocL());
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
Returns the LUN that corresponds to the specified drive number.
|
|
120 |
|
|
121 |
@param aDriveNumber The drive number.
|
|
122 |
*/
|
|
123 |
TInt CMassStorageMountCB::DriveNumberToLun(TInt aDriveNumber)
|
|
124 |
{
|
|
125 |
__FNLOG("CMassStorageMountCB::DriveNumberToLun");
|
|
126 |
TInt lun = -1;
|
|
127 |
for (TInt i = 0; i < iDriveMapping.Count(); i++)
|
|
128 |
{
|
|
129 |
if (iDriveMapping[i] == aDriveNumber)
|
|
130 |
{
|
|
131 |
lun = i;
|
|
132 |
break;
|
|
133 |
}
|
|
134 |
}
|
|
135 |
__PRINT2(_L("CMassStorageMountCB::DriveNumberToLun: Drive %d maps to LUN %d"), aDriveNumber, lun);
|
|
136 |
return lun;
|
|
137 |
}
|
|
138 |
|
|
139 |
/**
|
|
140 |
Deregisters the drive from the Drive Manager.
|
|
141 |
*/
|
|
142 |
void CMassStorageMountCB::Dismounted()
|
|
143 |
{
|
|
144 |
__FNLOG("CMassStorageMountCB::Dismounted");
|
|
145 |
TInt driveNumber = -1;
|
|
146 |
TRAPD(err, driveNumber = CheckDriveNumberL());
|
|
147 |
if (err != KErrNone)
|
|
148 |
{
|
|
149 |
return;
|
|
150 |
}
|
|
151 |
__PRINT(_L("CMassStorageMountCB::Dismounted: Deregistering drive"));
|
|
152 |
CMassStorageFileSystem& msFsys = *reinterpret_cast<CMassStorageFileSystem*>(Drive().GetFSys());
|
|
153 |
msFsys.Controller().DriveManager().DeregisterDrive(DriveNumberToLun(driveNumber));
|
|
154 |
|
|
155 |
DismountedLocalDrive();
|
|
156 |
}
|
|
157 |
|
|
158 |
/**
|
|
159 |
Unlocks the drive with the specified password, optionally storing the password for later use.
|
|
160 |
|
|
161 |
@param aPassword The password to use for unlocking the drive.
|
|
162 |
@param aStore True if the password is to be stored.
|
|
163 |
*/
|
|
164 |
TInt CMassStorageMountCB::Unlock(TMediaPassword& aPassword, TBool aStore)
|
|
165 |
{
|
|
166 |
__FNLOG("CMassStorageMountCB::Unlock");
|
|
167 |
TInt driveNumber = -1;
|
|
168 |
TRAPD(err, driveNumber = CheckDriveNumberL());
|
|
169 |
if (err != KErrNone)
|
|
170 |
{
|
|
171 |
return err;
|
|
172 |
}
|
|
173 |
TBusLocalDrive& localDrive=GetLocalDrive(driveNumber);
|
|
174 |
if(localDrive.Status() == KErrLocked)
|
|
175 |
{
|
|
176 |
localDrive.Status() = KErrNotReady;
|
|
177 |
}
|
|
178 |
TInt r = localDrive.Unlock(aPassword, aStore);
|
|
179 |
if(r == KErrNone && aStore)
|
|
180 |
{
|
|
181 |
WritePasswordData();
|
|
182 |
}
|
|
183 |
return(r);
|
|
184 |
}
|
|
185 |
|
|
186 |
/**
|
|
187 |
Stores the password for the drive to the password file.
|
|
188 |
*/
|
|
189 |
void CMassStorageMountCB::WritePasswordData()
|
|
190 |
{
|
|
191 |
__FNLOG("CMassStorageMountCB::WritePasswordData");
|
|
192 |
TBusLocalDrive& local=GetLocalDrive(Drive().DriveNumber());
|
|
193 |
TInt length = local.PasswordStoreLengthInBytes();
|
|
194 |
if(length==0)
|
|
195 |
{
|
|
196 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
|
|
197 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
198 |
WriteToDisk(mediaPWrdFile,_L8(""));
|
|
199 |
return;
|
|
200 |
}
|
|
201 |
HBufC8* hDes=HBufC8::New(length);
|
|
202 |
if(hDes==NULL)
|
|
203 |
{
|
|
204 |
return;
|
|
205 |
}
|
|
206 |
TPtr8 pDes=hDes->Des();
|
|
207 |
TInt r=local.ReadPasswordData(pDes);
|
|
208 |
if(r==KErrNone)
|
|
209 |
{
|
|
210 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile);
|
|
211 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar();
|
|
212 |
WriteToDisk(mediaPWrdFile,pDes);
|
|
213 |
}
|
|
214 |
delete hDes;
|
|
215 |
}
|
|
216 |
|
|
217 |
/**
|
|
218 |
Make sure that the file system is fat.
|
|
219 |
*/
|
|
220 |
TBool CMassStorageMountCB::ValidateBootSector()
|
|
221 |
{
|
|
222 |
__FNLOG("CMassStorageMountCB::ValidateBootSector");
|
|
223 |
|
|
224 |
TFatBootSector bootSector;
|
|
225 |
TInt r=ReadBootSector(bootSector);
|
|
226 |
__PRINT1(_L("CMassStorageMountCB::MountL - ReadBootSector returned %d"),r);
|
|
227 |
if (r != KErrNone)
|
|
228 |
{
|
|
229 |
return EFalse;
|
|
230 |
}
|
|
231 |
|
|
232 |
__PRINT(_L("\nBootSector info"));
|
|
233 |
__PRINT8BIT1(_L("FAT type = %S"),bootSector.FileSysType());
|
|
234 |
__PRINT8BIT1(_L("Vendor ID = %S"),bootSector.VendorId());
|
|
235 |
__PRINT1(_L("BytesPerSector %d"),bootSector.BytesPerSector());
|
|
236 |
__PRINT1(_L("SectorsPerCluster %d"),bootSector.SectorsPerCluster());
|
|
237 |
__PRINT1(_L("ReservedSectors %d"),bootSector.ReservedSectors());
|
|
238 |
__PRINT1(_L("NumberOfFats %d"),bootSector.NumberOfFats());
|
|
239 |
__PRINT1(_L("RootDirEntries %d"),bootSector.RootDirEntries());
|
|
240 |
__PRINT1(_L("Total Sectors = %d"),bootSector.TotalSectors());
|
|
241 |
__PRINT1(_L("MediaDescriptor = 0x%x"),bootSector.MediaDescriptor());
|
|
242 |
__PRINT1(_L("FatSectors %d"),bootSector.FatSectors());
|
|
243 |
__PRINT1(_L("SectorsPerTrack %d"),bootSector.SectorsPerTrack());
|
|
244 |
__PRINT1(_L("NumberOfHeads %d"),bootSector.NumberOfHeads());
|
|
245 |
__PRINT1(_L("HugeSectors %d"),bootSector.HugeSectors());
|
|
246 |
__PRINT1(_L("Fat32 Sectors %d"),bootSector.FatSectors32());
|
|
247 |
__PRINT1(_L("Fat32 Flags %d"),bootSector.FATFlags());
|
|
248 |
__PRINT1(_L("Fat32 Version Number %d"),bootSector.VersionNumber());
|
|
249 |
__PRINT1(_L("Root Cluster Number %d"),bootSector.RootClusterNum());
|
|
250 |
__PRINT1(_L("FSInfo Sector Number %d"),bootSector.FSInfoSectorNum());
|
|
251 |
__PRINT1(_L("Backup Boot Rec Sector Number %d"),bootSector.BkBootRecSector());
|
|
252 |
__PRINT1(_L("PhysicalDriveNumber %d"),bootSector.PhysicalDriveNumber());
|
|
253 |
__PRINT1(_L("ExtendedBootSignature %d"),bootSector.ExtendedBootSignature());
|
|
254 |
__PRINT1(_L("UniqueID %d"),bootSector.UniqueID());
|
|
255 |
__PRINT8BIT1(_L("VolumeLabel %S"),bootSector.VolumeLabel());
|
|
256 |
__PRINT8BIT1(_L("FileSysType %S\n"),bootSector.FileSysType());
|
|
257 |
|
|
258 |
iUniqueID=bootSector.UniqueID();
|
|
259 |
iIs16BitFat=bootSector.Is16BitFat();
|
|
260 |
|
|
261 |
iIs32BitFat=bootSector.Is32BitFat();
|
|
262 |
switch (DetermineFatType(bootSector))
|
|
263 |
{
|
|
264 |
case 12:
|
|
265 |
iIs16BitFat = EFalse;
|
|
266 |
iIs32BitFat = EFalse;
|
|
267 |
break;
|
|
268 |
case 16:
|
|
269 |
iIs16BitFat = ETrue;
|
|
270 |
iIs32BitFat = EFalse;
|
|
271 |
break;
|
|
272 |
case 32:
|
|
273 |
iIs16BitFat = EFalse;
|
|
274 |
iIs32BitFat = ETrue;
|
|
275 |
break;
|
|
276 |
default:
|
|
277 |
return EFalse;
|
|
278 |
}
|
|
279 |
|
|
280 |
TInt sectorsPerCluster=bootSector.SectorsPerCluster();
|
|
281 |
if (!IsPowerOfTwo(sectorsPerCluster))
|
|
282 |
return EFalse;
|
|
283 |
|
|
284 |
TInt sectorSizeLog2=Log2(bootSector.BytesPerSector());
|
|
285 |
if (sectorSizeLog2<0 || !IsPowerOfTwo(bootSector.BytesPerSector()))
|
|
286 |
return EFalse;
|
|
287 |
|
|
288 |
TInt firstFatSector=bootSector.ReservedSectors();
|
|
289 |
if (firstFatSector<1)
|
|
290 |
return EFalse;
|
|
291 |
|
|
292 |
TInt fatSizeInBytes;
|
|
293 |
if(iIs32BitFat)
|
|
294 |
{
|
|
295 |
fatSizeInBytes=bootSector.FatSectors32()*bootSector.BytesPerSector();
|
|
296 |
if (fatSizeInBytes<bootSector.BytesPerSector())
|
|
297 |
return EFalse;
|
|
298 |
}
|
|
299 |
else
|
|
300 |
{
|
|
301 |
fatSizeInBytes=bootSector.FatSectors()*bootSector.BytesPerSector();
|
|
302 |
if (fatSizeInBytes<bootSector.BytesPerSector())
|
|
303 |
return EFalse;
|
|
304 |
|
|
305 |
TInt rootDirectorySector=firstFatSector+bootSector.FatSectors()*bootSector.NumberOfFats();
|
|
306 |
if (rootDirectorySector<3)
|
|
307 |
return EFalse;
|
|
308 |
|
|
309 |
TInt rootDirSizeInBytes=bootSector.RootDirEntries()*KSizeOfFatDirEntry;
|
|
310 |
TInt numOfRootDirSectors=(rootDirSizeInBytes+(1<<sectorSizeLog2)-1)>>sectorSizeLog2;
|
|
311 |
TInt rootDirEnd=(rootDirectorySector+numOfRootDirSectors)<<sectorSizeLog2;
|
|
312 |
if (rootDirEnd<(4<<sectorSizeLog2))
|
|
313 |
return EFalse;
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
TInt totalSectors=bootSector.TotalSectors();
|
|
318 |
if (totalSectors==0)
|
|
319 |
totalSectors=bootSector.HugeSectors();
|
|
320 |
if (totalSectors<5)
|
|
321 |
return EFalse;
|
|
322 |
|
|
323 |
TInt numberOfFats=bootSector.NumberOfFats();
|
|
324 |
if (numberOfFats<1)
|
|
325 |
return EFalse;
|
|
326 |
|
|
327 |
return ETrue;
|
|
328 |
}
|
|
329 |
|
|
330 |
/**
|
|
331 |
Read non aligned boot data from media into TFatBootSector structure
|
|
332 |
|
|
333 |
@param aBootSector refrence to TFatBootSector populate
|
|
334 |
@return Media read error code
|
|
335 |
*/
|
|
336 |
TInt CMassStorageMountCB::ReadBootSector(TFatBootSector& aBootSector)
|
|
337 |
{
|
|
338 |
__FNLOG("CMassStorageMountCB::ReadBootSector");
|
|
339 |
TInt pos=0;
|
|
340 |
TUint8 data[KSizeOfFatBootSector];
|
|
341 |
TPtr8 buf(&data[0],KSizeOfFatBootSector);
|
|
342 |
TInt r=LocalDrive()->Read(0,KSizeOfFatBootSector,buf);
|
|
343 |
if (r!=KErrNone)
|
|
344 |
{
|
|
345 |
__PRINT1(_L("LocalDrive::Read() failed - %d"),r);
|
|
346 |
return(r);
|
|
347 |
}
|
|
348 |
// 0 TUint8 iJumpInstruction[3]
|
|
349 |
Mem::Copy(&aBootSector.iJumpInstruction,&data[pos],3);
|
|
350 |
pos+=3;
|
|
351 |
// 3 TUint8 iVendorId[KVendorIdSize]
|
|
352 |
Mem::Copy(&aBootSector.iVendorId,&data[pos],KVendorIdSize);
|
|
353 |
pos+=KVendorIdSize;
|
|
354 |
// 11 TUint16 iBytesPerSector
|
|
355 |
Mem::Copy(&aBootSector.iBytesPerSector,&data[pos],2);
|
|
356 |
pos+=2;
|
|
357 |
// 13 TUint8 sectorsPerCluster
|
|
358 |
Mem::Copy(&aBootSector.iSectorsPerCluster,&data[pos],1);
|
|
359 |
pos+=1;
|
|
360 |
// 14 TUint16 iReservedSectors
|
|
361 |
Mem::Copy(&aBootSector.iReservedSectors,&data[pos],2);
|
|
362 |
pos+=2;
|
|
363 |
// 16 TUint8 numberOfFats
|
|
364 |
Mem::Copy(&aBootSector.iNumberOfFats,&data[pos],1);
|
|
365 |
pos+=1;
|
|
366 |
// 17 TUint16 iRootDirEntries
|
|
367 |
Mem::Copy(&aBootSector.iRootDirEntries,&data[pos],2);
|
|
368 |
pos+=2;
|
|
369 |
// 19 TUint16 totalSectors
|
|
370 |
Mem::Copy(&aBootSector.iTotalSectors,&data[pos],2);
|
|
371 |
pos+=2;
|
|
372 |
// 21 TUint8 iMediaDescriptor
|
|
373 |
Mem::Copy(&aBootSector.iMediaDescriptor,&data[pos],1);
|
|
374 |
pos+=1;
|
|
375 |
// 22 TUint16 iFatSectors
|
|
376 |
Mem::Copy(&aBootSector.iFatSectors,&data[pos],2);
|
|
377 |
pos+=2;
|
|
378 |
// 24 TUint16 iSectorsPerTrack
|
|
379 |
Mem::Copy(&aBootSector.iSectorsPerTrack,&data[pos],2);
|
|
380 |
pos+=2;
|
|
381 |
// 26 TUint16 iNumberOfHeads
|
|
382 |
Mem::Copy(&aBootSector.iNumberOfHeads,&data[pos],2);
|
|
383 |
pos+=2;
|
|
384 |
// 28 TUint32 iHiddenSectors
|
|
385 |
Mem::Copy(&aBootSector.iHiddenSectors,&data[pos],4);
|
|
386 |
pos+=4;
|
|
387 |
// 32 TUint32 iHugeSectors
|
|
388 |
Mem::Copy(&aBootSector.iHugeSectors,&data[pos],4);
|
|
389 |
pos+=4;
|
|
390 |
|
|
391 |
if(aBootSector.iRootDirEntries == 0) //indicates we have FAT32 volume
|
|
392 |
{
|
|
393 |
__PRINT(_L("\nFile system thinks Fat32"));
|
|
394 |
|
|
395 |
//36 TUint32 iFatSectors32
|
|
396 |
Mem::Copy(&aBootSector.iFatSectors32, &data[pos],4);
|
|
397 |
pos+=4;
|
|
398 |
//40 TUint16 iFATFlags
|
|
399 |
Mem::Copy(&aBootSector.iFATFlags, &data[pos],2);
|
|
400 |
pos+=2;
|
|
401 |
//42 TUint16 iVersionNumber
|
|
402 |
Mem::Copy(&aBootSector.iVersionNumber, &data[pos],2);
|
|
403 |
pos+=2;
|
|
404 |
//44 TUint32 iRootClusterNum
|
|
405 |
Mem::Copy(&aBootSector.iRootClusterNum, &data[pos],4);
|
|
406 |
pos+=4;
|
|
407 |
//48 TUint16 iFSInfoSectorNum
|
|
408 |
Mem::Copy(&aBootSector.iFSInfoSectorNum, &data[pos],2);
|
|
409 |
pos+=2;
|
|
410 |
//50 TUint16 iBkBootRecSector
|
|
411 |
Mem::Copy(&aBootSector.iBkBootRecSector, &data[pos],2);
|
|
412 |
pos+=(2+12);//extra 12 for the reserved bytes
|
|
413 |
}
|
|
414 |
|
|
415 |
// 36|64 TUint8 iPhysicalDriveNumber
|
|
416 |
Mem::Copy(&aBootSector.iPhysicalDriveNumber,&data[pos],1);
|
|
417 |
pos+=1;
|
|
418 |
// 37|65 TUint8 iReserved
|
|
419 |
Mem::Copy(&aBootSector.iReserved,&data[pos],1);
|
|
420 |
pos+=1;
|
|
421 |
// 38|66 TUint8 iExtendedBootSignature
|
|
422 |
Mem::Copy(&aBootSector.iExtendedBootSignature,&data[pos],1);
|
|
423 |
pos+=1;
|
|
424 |
// 39|67 TUint32 iUniqueID
|
|
425 |
Mem::Copy(&aBootSector.iUniqueID,&data[pos],4);
|
|
426 |
pos+=4;
|
|
427 |
// 43|71 TUint8 iVolumeLabel[KVolumeLabelSize]
|
|
428 |
Mem::Copy(&aBootSector.iVolumeLabel,&data[pos],KVolumeLabelSize);
|
|
429 |
pos+=KVolumeLabelSize;
|
|
430 |
// 54|82 TUint8 iFileSysType[KFileSysTypeSize]
|
|
431 |
Mem::Copy(&aBootSector.iFileSysType,&data[pos],KFileSysTypeSize);
|
|
432 |
// 62|90
|
|
433 |
|
|
434 |
return(KErrNone);
|
|
435 |
}
|
|
436 |
|
|
437 |
/**
|
|
438 |
Work out if we have a FAT12|16|32 volume.
|
|
439 |
Returns 12, 16 or 32 as appropriate.
|
|
440 |
Returns 0 if can't be calculated (invalid values)
|
|
441 |
*/
|
|
442 |
TInt CMassStorageMountCB::DetermineFatType(TFatBootSector& aBootSector)
|
|
443 |
{
|
|
444 |
TUint32 ressectors = aBootSector.ReservedSectors();
|
|
445 |
|
|
446 |
if (aBootSector.SectorsPerCluster() < 1)
|
|
447 |
return 0;
|
|
448 |
|
|
449 |
if (aBootSector.RootDirEntries() != 0)
|
|
450 |
{
|
|
451 |
TUint32 rootdirbytes;
|
|
452 |
rootdirbytes = aBootSector.RootDirEntries() * 32 + aBootSector.BytesPerSector() - 1;
|
|
453 |
ressectors += rootdirbytes / aBootSector.BytesPerSector();
|
|
454 |
}
|
|
455 |
|
|
456 |
if (aBootSector.FatSectors() != 0)
|
|
457 |
ressectors += aBootSector.NumberOfFats() * aBootSector.FatSectors();
|
|
458 |
else
|
|
459 |
ressectors += aBootSector.NumberOfFats() * aBootSector.FatSectors32();
|
|
460 |
|
|
461 |
TUint32 totalsectors;
|
|
462 |
if (aBootSector.TotalSectors() != 0)
|
|
463 |
totalsectors = aBootSector.TotalSectors();
|
|
464 |
else
|
|
465 |
totalsectors = aBootSector.HugeSectors();
|
|
466 |
|
|
467 |
if (ressectors < 1 || totalsectors < 1)
|
|
468 |
return 0;
|
|
469 |
|
|
470 |
TUint32 datasec;
|
|
471 |
datasec = totalsectors - ressectors;
|
|
472 |
|
|
473 |
TUint32 countofclusters;
|
|
474 |
countofclusters = datasec / aBootSector.SectorsPerCluster();
|
|
475 |
|
|
476 |
__PRINT1(_L("CFatMountCB: Count of clusters = %d\n"), countofclusters);
|
|
477 |
|
|
478 |
if (countofclusters < 4085)
|
|
479 |
{
|
|
480 |
return 12;
|
|
481 |
}
|
|
482 |
else if (countofclusters < 65525)
|
|
483 |
{
|
|
484 |
return 16;
|
|
485 |
}
|
|
486 |
else
|
|
487 |
{
|
|
488 |
return 32;
|
|
489 |
}
|
|
490 |
}
|
|
491 |
|
|
492 |
TInt CMassStorageMountCB::ReMount()
|
|
493 |
{
|
|
494 |
return KErrNotReady;
|
|
495 |
}
|
|
496 |
|
|
497 |
void CMassStorageMountCB::VolumeL(TVolumeInfo& /*aVolume*/) const
|
|
498 |
{
|
|
499 |
User::Leave(KErrNotReady);
|
|
500 |
}
|
|
501 |
|
|
502 |
void CMassStorageMountCB::SetVolumeL(TDes& /*aName*/)
|
|
503 |
{
|
|
504 |
User::Leave(KErrNotReady);
|
|
505 |
}
|
|
506 |
|
|
507 |
void CMassStorageMountCB::MkDirL(const TDesC& /*aName*/)
|
|
508 |
{
|
|
509 |
User::Leave(KErrNotReady);
|
|
510 |
}
|
|
511 |
|
|
512 |
void CMassStorageMountCB::RmDirL(const TDesC& /*aName*/)
|
|
513 |
{
|
|
514 |
User::Leave(KErrNotReady);
|
|
515 |
}
|
|
516 |
|
|
517 |
void CMassStorageMountCB::DeleteL(const TDesC& /*aName*/)
|
|
518 |
{
|
|
519 |
User::Leave(KErrNotReady);
|
|
520 |
}
|
|
521 |
|
|
522 |
void CMassStorageMountCB::RenameL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
|
|
523 |
{
|
|
524 |
User::Leave(KErrNotReady);
|
|
525 |
}
|
|
526 |
|
|
527 |
void CMassStorageMountCB::ReplaceL(const TDesC& /*anOldName*/,const TDesC& /*anNewName*/)
|
|
528 |
{
|
|
529 |
User::Leave(KErrNotReady);
|
|
530 |
}
|
|
531 |
|
|
532 |
void CMassStorageMountCB::EntryL(const TDesC& /*aName*/,TEntry& /*anEntry*/) const
|
|
533 |
{
|
|
534 |
User::Leave(KErrNotReady);
|
|
535 |
}
|
|
536 |
|
|
537 |
void CMassStorageMountCB::SetEntryL(const TDesC& /*aName*/,const TTime& /*aTime*/,TUint /*aSetAttMask*/,TUint /*aClearAttMask*/)
|
|
538 |
{
|
|
539 |
User::Leave(KErrNotReady);
|
|
540 |
}
|
|
541 |
|
|
542 |
void CMassStorageMountCB::FileOpenL(const TDesC& /*aName*/,TUint /*aMode*/,TFileOpen /*anOpen*/,CFileCB* /*aFile*/)
|
|
543 |
{
|
|
544 |
User::Leave(KErrNotReady);
|
|
545 |
}
|
|
546 |
|
|
547 |
void CMassStorageMountCB::DirOpenL(const TDesC& /*aName*/,CDirCB* /*aDir*/)
|
|
548 |
{
|
|
549 |
User::Leave(KErrNotReady);
|
|
550 |
}
|
|
551 |
|
|
552 |
|
|
553 |
void CMassStorageMountCB::RawReadL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aTrg*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/) const
|
|
554 |
{
|
|
555 |
User::Leave(KErrNotReady);
|
|
556 |
}
|
|
557 |
|
|
558 |
void CMassStorageMountCB::RawWriteL(TInt64 /*aPos*/,TInt /*aLength*/,const TAny* /*aSrc*/,TInt /*anOffset*/,const RMessagePtr2& /*aMessage*/)
|
|
559 |
{
|
|
560 |
User::Leave(KErrNotReady);
|
|
561 |
}
|
|
562 |
|
|
563 |
|
|
564 |
void CMassStorageMountCB::GetShortNameL(const TDesC& /*aLongName*/,TDes& /*aShortName*/)
|
|
565 |
{
|
|
566 |
User::Leave(KErrNotReady);
|
|
567 |
}
|
|
568 |
|
|
569 |
void CMassStorageMountCB::GetLongNameL(const TDesC& /*aShorName*/,TDes& /*aLongName*/)
|
|
570 |
{
|
|
571 |
User::Leave(KErrNotReady);
|
|
572 |
}
|
|
573 |
|
|
574 |
#if defined(_DEBUG)
|
|
575 |
TInt CMassStorageMountCB::ControlIO(const RMessagePtr2& aMessage,TInt aCommand,TAny* aParam1,TAny* aParam2)
|
|
576 |
//
|
|
577 |
// Debug function
|
|
578 |
//
|
|
579 |
{
|
|
580 |
if(aCommand>=(KMaxTInt/2))
|
|
581 |
return LocalDrive()->ControlIO(aMessage,aCommand-(KMaxTInt/2),aParam1,aParam2);
|
|
582 |
else
|
|
583 |
return KErrNotSupported;
|
|
584 |
}
|
|
585 |
#else
|
|
586 |
TInt CMassStorageMountCB::ControlIO(const RMessagePtr2& /*aMessage*/,TInt /*aCommand*/,TAny* /*aParam1*/,TAny* /*aParam2*/)
|
|
587 |
{return(KErrNotSupported);}
|
|
588 |
#endif
|
|
589 |
|
|
590 |
void CMassStorageMountCB::ReadSectionL(const TDesC& /*aName*/,TInt /*aPos*/,TAny* /*aTrg*/,TInt /*aLength*/,const RMessagePtr2& /*aMessage*/)
|
|
591 |
{
|
|
592 |
User::Leave(KErrNotReady);
|
|
593 |
}
|
|
594 |
|