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