mtpfws/mtpfw/src/cmtpstoragemgr.cpp
branchRCL_3
changeset 12 8b094906a049
parent 0 d0791faffa3f
child 24 523717cdb0ad
equal deleted inserted replaced
11:4843bb5893b6 12:8b094906a049
   346     }
   346     }
   347 
   347 
   348 EXPORT_C TUint32 CMTPStorageMgr::DefaultStorageId() const
   348 EXPORT_C TUint32 CMTPStorageMgr::DefaultStorageId() const
   349     {
   349     {
   350     __FLOG(_L8("DefaultStorageId - Entry"));
   350     __FLOG(_L8("DefaultStorageId - Entry"));
       
   351     
       
   352     TUint32 ret = iDefaultStorageId;
       
   353     TBool check = EFalse;
       
   354 	TInt driveNo = DriveNumber(ret);
       
   355 	const TUint KMinFreeSpace(1024 * 512);  
       
   356 	if( (KErrNotFound == driveNo) || ( !IsReadWriteStorage(ret) ) )
       
   357 		{
       
   358 		check = ETrue;
       
   359 		}
       
   360 	else
       
   361 		{
       
   362 		TVolumeInfo volumeInfo;
       
   363 		if(iSingletons.Fs().Volume(volumeInfo, driveNo) != KErrNone)
       
   364 			{
       
   365 			check = ETrue;
       
   366 			}
       
   367 		else if (volumeInfo.iFree < KMinFreeSpace)
       
   368 			{
       
   369 			check = ETrue;
       
   370 			}
       
   371 		}
       
   372     	
       
   373     if(check)
       
   374     	{ 
       
   375 		const TUint KCount(iMapDriveToStorage.Count());
       
   376 		for (TInt i = 0; i < KCount; i++)
       
   377 			{
       
   378 			if (iMapDriveToStorage[i] == KErrNotFound)
       
   379 				{
       
   380 				continue;
       
   381 				}
       
   382 			TVolumeInfo volume;
       
   383 			if( !IsReadWriteStorage(iMapDriveToStorage[i]) 
       
   384 					|| (iSingletons.Fs().Volume(volume, i) != KErrNone) )
       
   385 				{
       
   386 				continue;
       
   387 				}
       
   388 			
       
   389 			if (volume.iFree > KMinFreeSpace )
       
   390 				{
       
   391 				ret = iMapDriveToStorage[i];
       
   392 				break;
       
   393 				}
       
   394 			}
       
   395     	}
       
   396     
   351     __FLOG(_L8("DefaultStorageId - Exit"));
   397     __FLOG(_L8("DefaultStorageId - Exit"));
   352     return iDefaultStorageId;
   398     return ret;
   353     }
   399     }
   354 
   400 
   355 EXPORT_C TInt CMTPStorageMgr::DriveNumber(TUint32 aStorageId) const
   401 EXPORT_C TInt CMTPStorageMgr::DriveNumber(TUint32 aStorageId) const
   356     {
   402     {
   357     __FLOG(_L8("DriveNumber - Entry"));
   403     __FLOG(_L8("DriveNumber - Entry"));
   807 TInt CMTPStorageMgr::StorageOrder(const TUint32* aKey, const CMTPStorageMetaData& aStorage)
   853 TInt CMTPStorageMgr::StorageOrder(const TUint32* aKey, const CMTPStorageMetaData& aStorage)
   808     {
   854     {
   809     return (*aKey - aStorage.Uint(CMTPStorageMetaData::EStorageId));
   855     return (*aKey - aStorage.Uint(CMTPStorageMetaData::EStorageId));
   810     }
   856     }
   811 
   857 
       
   858 EXPORT_C TBool CMTPStorageMgr::IsReadWriteStorage(TUint32 aStorageId) const
       
   859 	{
       
   860 	const TInt KCDrive = 2;
       
   861 	TInt driveNo(DriveNumber(aStorageId));
       
   862 	if(KErrNotFound == driveNo)
       
   863 		return ETrue;
       
   864 	
       
   865 	if(KCDrive == driveNo)
       
   866 		return EFalse;
       
   867 	
       
   868 	TDriveInfo driveInfo;
       
   869 	if(iSingletons.Fs().Drive(driveInfo, driveNo) != KErrNone)
       
   870 		return EFalse;
       
   871 	
       
   872 	TBool ret = ETrue;
       
   873 	switch(driveInfo.iType)
       
   874 		{
       
   875 		case EMediaCdRom:
       
   876 		case EMediaRom:
       
   877 			ret = EFalse;
       
   878 			break;
       
   879 		
       
   880 		//comment the blank cases.
       
   881 		//case EMediaNotPresent:
       
   882 		//case EMediaUnknown:	
       
   883 		//case EMediaRam:
       
   884 		//case EMediaNANDFlash:
       
   885 		//case EMediaHardDisk:
       
   886 		//case EMediaFlash:					
       
   887 		//case EMediaRemote:
       
   888 		//case EMediaFloppy:
       
   889 		default:
       
   890 			break;
       
   891 		}
       
   892 	
       
   893 	if(ret)
       
   894 		{
       
   895 		TVolumeInfo volumeInfo;
       
   896 		if(iSingletons.Fs().Volume(volumeInfo, driveNo) == KErrNone)
       
   897 			{
       
   898 			if( volumeInfo.iDrive.iMediaAtt & (KMediaAttWriteProtected | KMediaAttLocked) )
       
   899 				{
       
   900 				ret = EFalse;
       
   901 				}
       
   902 			}
       
   903 		}
       
   904 	    	
       
   905 	return ret;
       
   906 	}