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