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